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

Prepare 2.0.0 release #99

Merged
merged 19 commits into from
Nov 19, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- develop
- '*.x'
pull_request:
schedule:
Expand Down
37 changes: 7 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,27 @@ on:
push:
branches:
- master
- develop
- '*.x'
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
linux_tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04

strategy:
fail-fast: true
matrix:
php: [7.3, 7.4, '8.0', 8.1, 8.2, 8.3]
laravel: [8, 9, 10, 11]
exclude:
- php: 7.3
laravel: 9
- php: 7.3
laravel: 10
- php: 7.3
laravel: 11
- php: 7.4
laravel: 9
- php: 7.4
laravel: 10
- php: 7.4
laravel: 11
- php: '8.0'
laravel: 10
- php: '8.0'
php: [8.1, 8.2, 8.3]
laravel: [10, 11]
include:
- php: 8.4
laravel: 11
exclude:
- php: 8.1
laravel: 11
- php: 8.2
laravel: 8
- php: 8.3
laravel: 8
- php: 8.3
laravel: 9

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

Expand All @@ -66,10 +48,5 @@ jobs:
- name: Install PHP dependencies
run: composer update --prefer-stable --no-interaction --no-progress --with="illuminate/support:^${{ matrix.laravel }}"

- name: Execute tests
run: vendor/bin/pest tests/Php73Test.php
if: matrix.php == 7.3

- name: Execute tests
run: vendor/bin/pest
if: matrix.php > 7.3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
composer.lock
/phpunit.xml
.phpunit.result.cache
.phpunit.cache
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
}
],
"require": {
"php": "^7.3|^8.0"
"php": "^8.1"
},
"require-dev": {
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
"nesbot/carbon": "^2.61|^3.0",
"pestphp/pest": "^1.21.3",
"phpstan/phpstan": "^1.8.2",
"symfony/var-dumper": "^5.4.11|^6.2.0|^7.0.0"
"illuminate/support": "^10.0|^11.0",
"nesbot/carbon": "^2.67|^3.0",
"pestphp/pest": "^2.36",
"phpstan/phpstan": "^2.0",
"symfony/var-dumper": "^6.2.0|^7.0.0"
},
"autoload": {
"psr-4": {
Expand All @@ -39,8 +39,7 @@
},
"extra": {
"branch-alias": {
"dev-develop": "2.x-dev",
"dev-master": "1.x-dev"
"dev-master": "2.x-dev"
}
},
"config": {
Expand Down
9 changes: 5 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ parameters:
level: max
paths:
- src
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
reportUnmatchedIgnoredErrors: true
excludePaths:
- 'src/Support/ReflectionClosure'
- 'src/Serializers/Native'
- 'src/Support/ReflectionClosure.php'
- 'src/Serializers/Native.php'
34 changes: 7 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="vendor/autoload.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<testsuites>
<testsuite name="php73">
<file phpVersion="7.3.0" phpVersionOperator="==">./tests/Php73Test.php</file>
</testsuite>
<testsuite name="php74">
<file phpVersion="7.4.0" phpVersionOperator=">=">./tests/SerializerTest.php</file>
<file phpVersion="7.4.0" phpVersionOperator=">=">./tests/SignedSerializerTest.php</file>
<file phpVersion="7.4.0" phpVersionOperator=">=">./tests/SignedSerializerTest.php</file>
<file phpVersion="7.4.0" phpVersionOperator=">=">./tests/ReflectionClosure1Test.php</file>
<file phpVersion="7.4.0" phpVersionOperator=">=">./tests/ReflectionClosure2Test.php</file>
<file phpVersion="7.4.0" phpVersionOperator=">=">./tests/ReflectionClosure3Test.php</file>
<file phpVersion="7.4.0" phpVersionOperator=">=">./tests/ReflectionClosure4Test.php</file>
<file phpVersion="7.4.0" phpVersionOperator=">=">./tests/ReflectionClosure5Test.php</file>
</testsuite>
<testsuite name="php80">
<file phpVersion="8.0.0-dev" phpVersionOperator=">=">./tests/ReflectionClosurePhp80Test.php</file>
<file phpVersion="8.0.0-dev" phpVersionOperator=">=">./tests/SerializerPhp80Test.php</file>
</testsuite>
<testsuite name="php81">
<file phpVersion="8.1.0-dev" phpVersionOperator=">=">./tests/ReflectionClosurePhp81Test.php</file>
<file phpVersion="8.1.0-dev" phpVersionOperator=">=">./tests/SerializerPhp81Test.php</file>
<testsuite name="Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
17 changes: 2 additions & 15 deletions src/SerializableClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Laravel\SerializableClosure\Exceptions\InvalidSignatureException;
use Laravel\SerializableClosure\Exceptions\PhpVersionNotSupportedException;
use Laravel\SerializableClosure\Serializers\Signed;
use Laravel\SerializableClosure\Signers\Hmac;

Expand All @@ -25,10 +24,6 @@ class SerializableClosure
*/
public function __construct(Closure $closure)
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}

$this->serializable = Serializers\Signed::$signer
? new Serializers\Signed($closure)
: new Serializers\Native($closure);
Expand All @@ -41,10 +36,6 @@ public function __construct(Closure $closure)
*/
public function __invoke()
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}

return call_user_func_array($this->serializable, func_get_args());
}

Expand All @@ -55,10 +46,6 @@ public function __invoke()
*/
public function getClosure()
{
if (\PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}

return $this->serializable->getClosure();
}

Expand Down Expand Up @@ -111,7 +98,7 @@ public static function resolveUseVariablesUsing($resolver)
/**
* Get the serializable representation of the closure.
*
* @return array
* @return array{serializable: \Laravel\SerializableClosure\Serializers\Signed|\Laravel\SerializableClosure\Contracts\Serializable}
*/
public function __serialize()
{
Expand All @@ -123,7 +110,7 @@ public function __serialize()
/**
* Restore the closure after serialization.
*
* @param array $data
* @param array{serializable: \Laravel\SerializableClosure\Serializers\Signed|\Laravel\SerializableClosure\Contracts\Serializable} $data
* @return void
*
* @throws \Laravel\SerializableClosure\Exceptions\InvalidSignatureException
Expand Down
14 changes: 3 additions & 11 deletions src/Serializers/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static function wrapClosures(&$data, $storage)

$property->setAccessible(true);

if (PHP_VERSION >= 7.4 && ! $property->isInitialized($instance)) {
if (! $property->isInitialized($instance)) {
continue;
}

Expand Down Expand Up @@ -374,11 +374,7 @@ protected function mapPointers(&$data)

$property->setAccessible(true);

if (PHP_VERSION >= 7.4 && ! $property->isInitialized($data)) {
continue;
}

if (PHP_VERSION >= 8.1 && $property->isReadOnly()) {
if (! $property->isInitialized($data) || $property->isReadOnly()) {
continue;
}

Expand Down Expand Up @@ -500,11 +496,7 @@ protected function mapByReference(&$data)

$property->setAccessible(true);

if (PHP_VERSION >= 7.4 && ! $property->isInitialized($instance)) {
continue;
}

if (PHP_VERSION >= 8.1 && $property->isReadOnly() && $property->class !== $reflection->name) {
if (! $property->isInitialized($instance) || ($property->isReadOnly() && $property->class !== $reflection->name)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Serializers/Signed.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __serialize()
/**
* Restore the closure after serialization.
*
* @param array $signature
* @param array{serializable: string, hash: string} $signature
* @return void
*
* @throws \Laravel\SerializableClosure\Exceptions\InvalidSignatureException
Expand Down
2 changes: 1 addition & 1 deletion src/Signers/Hmac.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function sign($serialized)
/**
* Verify the given signature.
*
* @param array $signature
* @param array{serializable: string, hash: string} $signature
* @return bool
*/
public function verify($signature)
Expand Down
2 changes: 2 additions & 0 deletions src/Support/ClosureStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class ClosureStream
{
/**
* The stream protocol.
*
* @var string
*/
const STREAM_PROTO = 'laravel-serializable-closure';

Expand Down
58 changes: 22 additions & 36 deletions src/Support/ReflectionClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,27 +680,25 @@ public function getCode()
$this->isBindingRequired = $isUsingThisObject;
$this->isScopeRequired = $isUsingScope;

if (PHP_VERSION_ID >= 80100) {
$attributesCode = array_map(function ($attribute) {
$arguments = $attribute->getArguments();
$attributesCode = array_map(function ($attribute) {
$arguments = $attribute->getArguments();

$name = $attribute->getName();
$arguments = implode(', ', array_map(function ($argument, $key) {
$argument = sprintf("'%s'", str_replace("'", "\\'", $argument));
$name = $attribute->getName();
$arguments = implode(', ', array_map(function ($argument, $key) {
$argument = sprintf("'%s'", str_replace("'", "\\'", $argument));

if (is_string($key)) {
$argument = sprintf('%s: %s', $key, $argument);
}
if (is_string($key)) {
$argument = sprintf('%s: %s', $key, $argument);
}

return $argument;
}, $arguments, array_keys($arguments)));
return $argument;
}, $arguments, array_keys($arguments)));

return "#[$name($arguments)]";
}, $this->getAttributes());
return "#[$name($arguments)]";
}, $this->getAttributes());

if (! empty($attributesCode)) {
$code = implode("\n", array_merge($attributesCode, [$code]));
}
if (! empty($attributesCode)) {
$code = implode("\n", array_merge($attributesCode, [$code]));
}

$this->code = $code;
Expand All @@ -715,25 +713,7 @@ public function getCode()
*/
protected static function getBuiltinTypes()
{
// PHP 8.1
if (PHP_VERSION_ID >= 80100) {
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void', 'object', 'mixed', 'false', 'null', 'never'];
}

// PHP 8
if (\PHP_MAJOR_VERSION === 8) {
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void', 'object', 'mixed', 'false', 'null'];
}

// PHP 7
switch (\PHP_MINOR_VERSION) {
case 0:
return ['array', 'callable', 'string', 'int', 'bool', 'float'];
case 1:
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void'];
default:
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void', 'object'];
}
return ['array', 'callable', 'string', 'int', 'bool', 'float', 'iterable', 'void', 'object', 'mixed', 'false', 'null', 'never'];
}

/**
Expand Down Expand Up @@ -1169,8 +1149,14 @@ protected function getClosureNamespaceName()
{
$ns = $this->getNamespaceName();

$name = $this->getName();

// First class callables...
if ($this->getName() !== '{closure}' && empty($ns) && ! is_null($this->getClosureScopeClass())) {
if ($name !== '{closure}'
&& ! str_contains($name, '{closure:/')
&& ! str_contains($name, '{closure:\\')
&& empty($ns)
&& ! is_null($this->getClosureScopeClass())) {
$ns = $this->getClosureScopeClass()->getNamespaceName();
}

Expand Down
Loading