Skip to content

Commit

Permalink
PHP 8.1 while maintaining PHP 7.2 & 7.3 compatibility (#61)
Browse files Browse the repository at this point in the history
* PHP 8.1 while maintaining PHP 7.2 & 7.3 compatibility

* remove duplicated code

* cakephp/migrations >= 3.7.0
  • Loading branch information
swiffer authored Dec 15, 2022
1 parent 8acc6ba commit 58f0c65
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions config/Migrations/20171018185609_CreateAuditLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CreateAuditLogs extends AbstractMigration
{
public $autoId = false;

public function up()
public function up(): void
{
$this->table('audit_logs')
->addColumn('id', 'integer', [
Expand Down Expand Up @@ -95,7 +95,7 @@ public function up()
->create();
}

public function down()
public function down(): void
{
$this->dropTable('audit_logs');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Event/BaseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract public function getEventType();
*
* @return array
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this->basicSerialize() + [
'original' => $this->original,
Expand Down
27 changes: 24 additions & 3 deletions src/Event/SerializableEventTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait SerializableEventTrait
*/
public function serialize()
{
return serialize(get_object_vars($this));
return $this->__serialize();
}

/**
Expand All @@ -24,6 +24,27 @@ public function serialize()
* @return void
*/
public function unserialize($data)
{
$this->__unserialize($data);
}

/**
* Returns the string representation of this object.
*
* @return string
*/
public function __serialize()
{
return serialize(get_object_vars($this));
}

/**
* Takes the string representation of this object so it can be reconstructed.
*
* @param string $data serialized string
* @return void
*/
public function __unserialize($data)
{
$vars = unserialize($data);
foreach ($vars as $var => $value) {
Expand All @@ -34,9 +55,9 @@ public function unserialize($data)
/**
* Returns an array with the basic variables that should be json serialized.
*
* @return void
* @return array
*/
protected function basicSerialize()
protected function basicSerialize(): mixed
{
return [
'type' => $this->getEventType(),
Expand Down

0 comments on commit 58f0c65

Please sign in to comment.