Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 magic method support #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
build:
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
filter:
paths: ["src/*"]
tools:
php_sim: true
php_pdepend: true
php_analyzer: true
php_cpd: true
php_mess_detector:
enabled: true
config:
ruleset: ./phpmd.xml
php_code_sniffer:
enabled: true
config:
ruleset: ./phpcs.xml
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": "^7.3 || ^8.0",
"psr/cache": "^1.0.1",
"ray/di": "^2.12.0",
"ray/di": "dev-php8.1-serializalble as 2.13.0",
"symfony/cache": "^5.3.4",
"doctrine/annotations": "^1.13",
"psr/simple-cache": "^1.0"
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<exclude name="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix"/>
</rule>
<!-- Additional Rules -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
Expand Down
22 changes: 1 addition & 21 deletions src/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,15 @@
use Symfony\Component\Cache\Adapter\FilesystemAdapter as OriginAdapter;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;

use function call_user_func_array;
use function func_get_args;
use function serialize;
use function unserialize;

class FilesystemAdapter extends OriginAdapter implements Serializable
{
/** @var array<int, mixed> */
private $args;
use SerializableTrait;

public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, ?MarshallerInterface $marshaller = null)
{
$this->args = func_get_args();
parent::__construct($namespace, $defaultLifetime, $directory, $marshaller);
}

/**
* @inheritDoc
*/
public function serialize()
{
return serialize($this->args);
}

/**
* @inheritDoc
*/
public function unserialize($data)
{
call_user_func_array([$this, '__construct'], unserialize($data)); // @phpstan-ignore-line
}
}
22 changes: 1 addition & 21 deletions src/PhpFileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,15 @@
use Serializable;
use Symfony\Component\Cache\Adapter\PhpFilesAdapter as OriginAdapter;

use function call_user_func_array;
use function func_get_args;
use function serialize;
use function unserialize;

class PhpFileAdapter extends OriginAdapter implements Serializable
{
/** @var array<int, mixed> */
private $args;
use SerializableTrait;

public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, bool $appendOnly = false)
{
$this->args = func_get_args();
parent::__construct($namespace, $defaultLifetime, $directory, $appendOnly);
}

/**
* @inheritDoc
*/
public function serialize()
{
return serialize($this->args);
}

/**
* @inheritDoc
*/
public function unserialize($data)
{
call_user_func_array([$this, '__construct'], unserialize($data)); // @phpstan-ignore-line
}
}
51 changes: 51 additions & 0 deletions src/SerializableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Ray\PsrCacheModule;

use function call_user_func_array;
use function serialize;
use function unserialize;

trait SerializableTrait
{
/** @var array<int, mixed> */
private $args;

/**
* @inheritDoc
*/
public function serialize()
{
return serialize($this->__serialize());
}

/**
* @psalm-param string $serializedData
*
* @inheritDoc
*/
public function unserialize($serializedData)
{
/** @var array<mixed> $array */
$array = unserialize($serializedData);
$this->__unserialize($array);
}

/**
* @return array<mixed>
*/
public function __serialize(): array
{
return $this->args;
}

/**
* @param array<mixed> $data
*/
public function __unserialize(array $data): void
{
call_user_func_array([$this, '__construct'], $data); // @phpstan-ignore-line
}
}