diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml
index b021d48..545cd86 100644
--- a/.github/workflows/coding-standards.yml
+++ b/.github/workflows/coding-standards.yml
@@ -12,6 +12,7 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
- uses: "doctrine/.github/.github/workflows/coding-standards.yml@1.2.0"
+ uses: "doctrine/.github/.github/workflows/coding-standards.yml@1.4.1"
with:
composer-root-version: "1.4"
+ php-version: "8.1"
diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index 7569e38..9317474 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -12,7 +12,7 @@ on:
jobs:
phpunit:
name: "PHPUnit"
- uses: "doctrine/.github/.github/workflows/continuous-integration.yml@1.2.0"
+ uses: "doctrine/.github/.github/workflows/continuous-integration.yml@1.4.1"
with:
- php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0"]'
+ php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0", "8.1"]'
composer-root-version: "1.4"
diff --git a/.github/workflows/phpbench.yml b/.github/workflows/phpbench.yml
index 9d131e7..d1abf24 100644
--- a/.github/workflows/phpbench.yml
+++ b/.github/workflows/phpbench.yml
@@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
php-version:
- - "7.4"
+ - "8.1"
steps:
- name: "Checkout"
diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml
index c97995f..e7e127f 100644
--- a/.github/workflows/release-on-milestone-closed.yml
+++ b/.github/workflows/release-on-milestone-closed.yml
@@ -8,9 +8,8 @@ on:
jobs:
release:
name: "Git tag, release & create merge-up PR"
- uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@1.2.0"
+ uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@1.4.1"
secrets:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
ORGANIZATION_ADMIN_TOKEN: ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
index 018dffd..dd70c4e 100644
--- a/.github/workflows/static-analysis.yml
+++ b/.github/workflows/static-analysis.yml
@@ -12,7 +12,7 @@ on:
jobs:
static-analysis:
name: "Static Analysis"
- uses: "doctrine/.github/.github/workflows/static-analysis.yml@1.2.0"
+ uses: "doctrine/.github/.github/workflows/static-analysis.yml@1.4.1"
with:
composer-root-version: "1.4"
- php-version: "7.4"
+ php-version: "8.1"
diff --git a/composer.json b/composer.json
index b46bd52..4fba95c 100644
--- a/composer.json
+++ b/composer.json
@@ -21,12 +21,12 @@
"require-dev": {
"ext-phar": "*",
"ext-pdo": "*",
- "doctrine/coding-standard": "^8.0",
- "phpbench/phpbench": "^0.13 || 1.0.0-alpha2",
- "phpstan/phpstan": "^0.12",
- "phpstan/phpstan-phpunit": "^0.12",
- "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
- "vimeo/psalm": "^4.11"
+ "doctrine/coding-standard": "^9",
+ "phpbench/phpbench": "^0.16 || ^1",
+ "phpstan/phpstan": "^1.4",
+ "phpstan/phpstan-phpunit": "^1",
+ "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
+ "vimeo/psalm": "^4.22"
},
"autoload": {
"psr-4": {
@@ -39,5 +39,10 @@
"DoctrineTest\\InstantiatorTest\\": "tests",
"DoctrineTest\\InstantiatorTestAsset\\": "tests"
}
+ },
+ "config": {
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": true
+ }
}
}
diff --git a/phpbench.json b/phpbench.json
index fce5dd6..e5daa77 100644
--- a/phpbench.json
+++ b/phpbench.json
@@ -1,4 +1,4 @@
{
- "bootstrap": "vendor/autoload.php",
- "path": "tests/DoctrineTest/InstantiatorPerformance"
+ "runner.bootstrap": "vendor/autoload.php",
+ "runner.path": "tests/DoctrineTest/InstantiatorPerformance"
}
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 4e08b16..67dfcda 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -9,6 +9,8 @@
+
+
src
tests
@@ -27,7 +29,9 @@
- */src/*
+ src/*
+ tests/DoctrineTest/InstantiatorTestAsset/SerializableArrayObjectAsset.php
+ tests/DoctrineTest/InstantiatorTestAsset/SimpleSerializableAsset.php
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index 60bec6b..c9cb6fb 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -4,12 +4,18 @@ includes:
parameters:
level: max
+ phpVersion: 80103
paths:
- src
- tests
ignoreErrors:
+ # PHPStan is unable to infer the return type of unserialize() in this case.
+ -
+ message: '#Method Doctrine\\Instantiator\\Instantiator\:\:buildFactory\(\) should return callable\(\): T of object but returns Closure\(\): mixed\.#'
+ path: 'src/Doctrine/Instantiator/Instantiator.php'
+
# dynamic properties confuse static analysis
-
message: '#Access to an undefined property object::\$foo\.#'
- path: '*/tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php'
+ path: 'tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php'
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 8944ab7..7d9de6d 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,15 +1,21 @@
-
+
+
+
+
./tests/DoctrineTest/InstantiatorTest
diff --git a/psalm.xml b/psalm.xml
index 7c0333d..e6270c1 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,6 +1,7 @@
$reflectionClass
+ *
+ * @template T of object
*/
public static function fromAbstractClass(ReflectionClass $reflectionClass): self
{
diff --git a/src/Doctrine/Instantiator/Exception/UnexpectedValueException.php b/src/Doctrine/Instantiator/Exception/UnexpectedValueException.php
index 19842bb..4e55ac5 100644
--- a/src/Doctrine/Instantiator/Exception/UnexpectedValueException.php
+++ b/src/Doctrine/Instantiator/Exception/UnexpectedValueException.php
@@ -14,8 +14,9 @@
class UnexpectedValueException extends BaseUnexpectedValueException implements ExceptionInterface
{
/**
- * @template T of object
* @phpstan-param ReflectionClass $reflectionClass
+ *
+ * @template T of object
*/
public static function fromSerializationTriggeredException(
ReflectionClass $reflectionClass,
@@ -32,8 +33,9 @@ public static function fromSerializationTriggeredException(
}
/**
- * @template T of object
* @phpstan-param ReflectionClass $reflectionClass
+ *
+ * @template T of object
*/
public static function fromUncleanUnSerialization(
ReflectionClass $reflectionClass,
diff --git a/src/Doctrine/Instantiator/Instantiator.php b/src/Doctrine/Instantiator/Instantiator.php
index 330d331..d5f591e 100644
--- a/src/Doctrine/Instantiator/Instantiator.php
+++ b/src/Doctrine/Instantiator/Instantiator.php
@@ -45,15 +45,14 @@ final class Instantiator implements InstantiatorInterface
/**
* @param string $className
+ * @phpstan-param class-string $className
*
* @return object
+ * @phpstan-return T
*
* @throws ExceptionInterface
*
* @template T of object
- * @phpstan-param class-string $className
- *
- * @phpstan-return T
*/
public function instantiate($className)
{
@@ -78,12 +77,12 @@ public function instantiate($className)
/**
* Builds the requested object and caches it in static properties for performance
*
- * @return object
- *
- * @template T of object
* @phpstan-param class-string $className
*
+ * @return object
* @phpstan-return T
+ *
+ * @template T of object
*/
private function buildAndCacheFromFactory(string $className)
{
@@ -101,14 +100,15 @@ private function buildAndCacheFromFactory(string $className)
* Builds a callable capable of instantiating the given $className without
* invoking its constructor.
*
+ * @phpstan-param class-string $className
+ *
+ * @phpstan-return callable(): T
+ *
* @throws InvalidArgumentException
* @throws UnexpectedValueException
* @throws ReflectionException
*
* @template T of object
- * @phpstan-param class-string $className
- *
- * @phpstan-return callable(): T
*/
private function buildFactory(string $className): callable
{
@@ -133,13 +133,14 @@ private function buildFactory(string $className): callable
}
/**
+ * @phpstan-param class-string $className
+ *
+ * @phpstan-return ReflectionClass
+ *
* @throws InvalidArgumentException
* @throws ReflectionException
*
* @template T of object
- * @phpstan-param class-string $className
- *
- * @phpstan-return ReflectionClass
*/
private function getReflectionClass(string $className): ReflectionClass
{
@@ -157,10 +158,11 @@ private function getReflectionClass(string $className): ReflectionClass
}
/**
+ * @phpstan-param ReflectionClass $reflectionClass
+ *
* @throws UnexpectedValueException
*
* @template T of object
- * @phpstan-param ReflectionClass $reflectionClass
*/
private function checkIfUnSerializationIsSupported(ReflectionClass $reflectionClass, string $serializedString): void
{
@@ -188,10 +190,11 @@ private function checkIfUnSerializationIsSupported(ReflectionClass $reflectionCl
}
/**
+ * @phpstan-param ReflectionClass $reflectionClass
+ *
* @throws UnexpectedValueException
*
* @template T of object
- * @phpstan-param ReflectionClass $reflectionClass
*/
private function attemptInstantiationViaUnSerialization(ReflectionClass $reflectionClass, string $serializedString): void
{
@@ -203,8 +206,9 @@ private function attemptInstantiationViaUnSerialization(ReflectionClass $reflect
}
/**
- * @template T of object
* @phpstan-param ReflectionClass $reflectionClass
+ *
+ * @template T of object
*/
private function isInstantiableViaReflection(ReflectionClass $reflectionClass): bool
{
@@ -214,8 +218,9 @@ private function isInstantiableViaReflection(ReflectionClass $reflectionClass):
/**
* Verifies whether the given class is to be considered internal
*
- * @template T of object
* @phpstan-param ReflectionClass $reflectionClass
+ *
+ * @template T of object
*/
private function hasInternalAncestors(ReflectionClass $reflectionClass): bool
{
@@ -235,8 +240,9 @@ private function hasInternalAncestors(ReflectionClass $reflectionClass): bool
*
* Classes implementing `__clone` cannot be safely cloned, as that may cause side-effects.
*
- * @template T of object
* @phpstan-param ReflectionClass $reflectionClass
+ *
+ * @template T of object
*/
private function isSafeToClone(ReflectionClass $reflectionClass): bool
{
diff --git a/src/Doctrine/Instantiator/InstantiatorInterface.php b/src/Doctrine/Instantiator/InstantiatorInterface.php
index 39a4581..10508b5 100644
--- a/src/Doctrine/Instantiator/InstantiatorInterface.php
+++ b/src/Doctrine/Instantiator/InstantiatorInterface.php
@@ -11,15 +11,14 @@ interface InstantiatorInterface
{
/**
* @param string $className
+ * @phpstan-param class-string $className
*
* @return object
+ * @phpstan-return T
*
* @throws ExceptionInterface
*
* @template T of object
- * @phpstan-param class-string $className
- *
- * @phpstan-return T
*/
public function instantiate($className);
}
diff --git a/tests/DoctrineTest/InstantiatorPerformance/InstantiatorPerformanceEvent.php b/tests/DoctrineTest/InstantiatorPerformance/InstantiatorPerformanceBench.php
similarity index 98%
rename from tests/DoctrineTest/InstantiatorPerformance/InstantiatorPerformanceEvent.php
rename to tests/DoctrineTest/InstantiatorPerformance/InstantiatorPerformanceBench.php
index b036c46..a5f3e50 100644
--- a/tests/DoctrineTest/InstantiatorPerformance/InstantiatorPerformanceEvent.php
+++ b/tests/DoctrineTest/InstantiatorPerformance/InstantiatorPerformanceBench.php
@@ -15,7 +15,7 @@
*
* @BeforeMethods({"init"})
*/
-class InstantiatorPerformanceEvent
+class InstantiatorPerformanceBench
{
/** @var Instantiator */
private $instantiator;
diff --git a/tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php b/tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php
index 20ca4d5..e28a5c0 100644
--- a/tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php
+++ b/tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php
@@ -47,8 +47,9 @@ protected function setUp(): void
}
/**
- * @dataProvider getInstantiableClasses
* @phpstan-param class-string $className
+ *
+ * @dataProvider getInstantiableClasses
*/
public function testCanInstantiate(string $className): void
{
@@ -56,8 +57,9 @@ public function testCanInstantiate(string $className): void
}
/**
- * @dataProvider getInstantiableClasses
* @phpstan-param class-string $className
+ *
+ * @dataProvider getInstantiableClasses
*/
public function testInstantiatesSeparateInstances(string $className): void
{
@@ -76,8 +78,9 @@ public function testExceptionOnUnSerializationException(): void
}
/**
- * @dataProvider getInvalidClassNames
* @phpstan-param class-string $invalidClassName
+ *
+ * @dataProvider getInvalidClassNames
*/
public function testInstantiationFromNonExistingClass(string $invalidClassName): void
{
@@ -110,7 +113,6 @@ public function testInstancesAreNotCloned(): void
* Provides a list of instantiable classes (existing)
*
* @return string[][]
- *
* @phpstan-return list
*/
public function getInstantiableClasses(): array
diff --git a/tests/DoctrineTest/InstantiatorTestAsset/SerializableArrayObjectAsset.php b/tests/DoctrineTest/InstantiatorTestAsset/SerializableArrayObjectAsset.php
index edc0fbe..993ee3f 100644
--- a/tests/DoctrineTest/InstantiatorTestAsset/SerializableArrayObjectAsset.php
+++ b/tests/DoctrineTest/InstantiatorTestAsset/SerializableArrayObjectAsset.php
@@ -26,20 +26,20 @@ public function __construct()
/**
* {@inheritDoc}
+ *
+ * Should not be called
+ *
+ * @throws BadMethodCallException
*/
- public function serialize()
+ public function unserialize($serialized): void
{
- return '';
+ throw new BadMethodCallException('Not supposed to be called!');
}
/**
- * {@inheritDoc}
- *
- * Should not be called
- *
- * @throws BadMethodCallException
+ * @param mixed[] $data
*/
- public function unserialize($serialized)
+ public function __unserialize($data): void
{
throw new BadMethodCallException('Not supposed to be called!');
}
diff --git a/tests/DoctrineTest/InstantiatorTestAsset/SimpleSerializableAsset.php b/tests/DoctrineTest/InstantiatorTestAsset/SimpleSerializableAsset.php
index b384336..77a5239 100644
--- a/tests/DoctrineTest/InstantiatorTestAsset/SimpleSerializableAsset.php
+++ b/tests/DoctrineTest/InstantiatorTestAsset/SimpleSerializableAsset.php
@@ -20,10 +20,7 @@ public function __construct()
throw new BadMethodCallException('Not supposed to be called!');
}
- /**
- * {@inheritDoc}
- */
- public function serialize()
+ public function serialize(): string
{
return '';
}
@@ -35,7 +32,23 @@ public function serialize()
*
* @throws BadMethodCallException
*/
- public function unserialize($serialized)
+ public function unserialize($serialized): void
+ {
+ throw new BadMethodCallException('Not supposed to be called!');
+ }
+
+ /**
+ * @return mixed[]
+ */
+ public function __serialize(): array
+ {
+ return [];
+ }
+
+ /**
+ * @param mixed[] $data
+ */
+ public function __unserialize($data): void
{
throw new BadMethodCallException('Not supposed to be called!');
}