-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Migrate codebase to PHP 8.1 #94
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,5 @@ jobs: | |
name: "PHPUnit" | ||
uses: "doctrine/.github/.github/workflows/[email protected]" | ||
with: | ||
php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]' | ||
php-versions: '["8.1", "8.2"]' | ||
composer-root-version: "1.4" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Instantiator\Exception; | ||
|
||
use Throwable; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Instantiator; | ||
|
||
use ArrayIterator; | ||
|
@@ -20,8 +22,6 @@ | |
use function strlen; | ||
use function unserialize; | ||
|
||
use const PHP_VERSION_ID; | ||
|
||
final class Instantiator implements InstantiatorInterface | ||
{ | ||
/** | ||
|
@@ -31,37 +31,33 @@ final class Instantiator implements InstantiatorInterface | |
* | ||
* @deprecated This constant will be private in 2.0 | ||
*/ | ||
public const SERIALIZATION_FORMAT_USE_UNSERIALIZER = 'C'; | ||
|
||
/** @deprecated This constant will be private in 2.0 */ | ||
public const SERIALIZATION_FORMAT_AVOID_UNSERIALIZER = 'O'; | ||
private const SERIALIZATION_FORMAT_USE_UNSERIALIZER = 'C'; | ||
private const SERIALIZATION_FORMAT_AVOID_UNSERIALIZER = 'O'; | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those constants are never used publicly and I believe they should not be part of the public interface. Do we need to flag them as deprecated on 1.x or is it enough to just switch them to private in 2.0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's flag them as deprecated out of consistency with doctrine/orm#10342? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in #96 |
||
|
||
/** | ||
* Used to instantiate specific classes, indexed by class name. | ||
* | ||
* @var callable[] | ||
*/ | ||
private static $cachedInstantiators = []; | ||
private static array $cachedInstantiators = []; | ||
|
||
/** | ||
* Array of objects that can directly be cloned, indexed by class name. | ||
* | ||
* @var object[] | ||
*/ | ||
private static $cachedCloneables = []; | ||
private static array $cachedCloneables = []; | ||
|
||
/** | ||
* @param string $className | ||
* @phpstan-param class-string<T> $className | ||
* | ||
* @return object | ||
* @phpstan-return T | ||
* | ||
* @throws ExceptionInterface | ||
* | ||
* @template T of object | ||
*/ | ||
public function instantiate($className) | ||
public function instantiate(string $className): object | ||
{ | ||
if (isset(self::$cachedCloneables[$className])) { | ||
/** @phpstan-var T */ | ||
|
@@ -84,12 +80,11 @@ public function instantiate($className) | |
* | ||
* @phpstan-param class-string<T> $className | ||
* | ||
* @return object | ||
* @phpstan-return T | ||
* | ||
* @template T of object | ||
*/ | ||
private function buildAndCacheFromFactory(string $className) | ||
private function buildAndCacheFromFactory(string $className): object | ||
{ | ||
$factory = self::$cachedInstantiators[$className] = $this->buildFactory($className); | ||
$instance = $factory(); | ||
|
@@ -127,14 +122,12 @@ private function buildFactory(string $className): callable | |
'%s:%d:"%s":0:{}', | ||
is_subclass_of($className, Serializable::class) ? self::SERIALIZATION_FORMAT_USE_UNSERIALIZER : self::SERIALIZATION_FORMAT_AVOID_UNSERIALIZER, | ||
strlen($className), | ||
$className | ||
$className, | ||
); | ||
|
||
$this->checkIfUnSerializationIsSupported($reflectionClass, $serializedString); | ||
|
||
return static function () use ($serializedString) { | ||
return unserialize($serializedString); | ||
}; | ||
return static fn () => unserialize($serializedString); | ||
} | ||
|
||
/** | ||
|
@@ -153,7 +146,7 @@ private function getReflectionClass(string $className): ReflectionClass | |
throw InvalidArgumentException::fromNonExistingClass($className); | ||
} | ||
|
||
if (PHP_VERSION_ID >= 80100 && enum_exists($className, false)) { | ||
if (enum_exists($className, false)) { | ||
throw InvalidArgumentException::fromEnum($className); | ||
} | ||
|
||
|
@@ -181,7 +174,7 @@ private function checkIfUnSerializationIsSupported(ReflectionClass $reflectionCl | |
$message, | ||
$code, | ||
$file, | ||
$line | ||
$line, | ||
); | ||
|
||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot to remove that
@deprecated
tagThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Wanna submit a PR?