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.4 support #1462

Merged
merged 24 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
51496aa
Run checks on PHP 8.4
kukulich Nov 22, 2024
2260394
Hack temporarily PhpStormStubsSourceStubber tests for PHP 8.4 until J…
kukulich Nov 23, 2024
1f86834
Improved ReflectionSourceStubber tests for internal enums
kukulich Nov 23, 2024
e37298d
Don't check deprecated functions in ReflectionSourceStubber tests bec…
kukulich Nov 23, 2024
902ca0d
Implement isDeprecated() in ReflectionClassConstant adapter
kukulich Nov 23, 2024
bc78b96
Implement isDeprecated() in ReflectionEnumBackedCase adapter
kukulich Nov 23, 2024
be7fdfd
Implement isDeprecated() in ReflectionEnumUnitCase adapter
kukulich Nov 23, 2024
68c6901
Added DeprecatedHelper - it checks new #[Deprecated] attribute too
kukulich Nov 23, 2024
70d20b6
Added methods for lazy objects to ReflectionClass adapter
kukulich Nov 23, 2024
70780e2
Added methods for lazy objects to ReflectionObject adapter
kukulich Nov 23, 2024
8bb15aa
Added methods for lazy objects to ReflectionEnum adapter
kukulich Nov 23, 2024
8fcd904
Added methods for lazy objects to ReflectionProperty adapter
kukulich Nov 23, 2024
af9adcb
Implemented ReflectionProperty::isFinal()
kukulich Nov 23, 2024
2a7c667
Implemented ReflectionProperty::isDynamic()
kukulich Nov 23, 2024
5151935
Implemented asymetric visibility for properties
kukulich Nov 23, 2024
600802a
Implemented property hooks
kukulich Nov 23, 2024
23a7c07
PhpInternalSourceLocator supports aliased class names
kukulich Nov 28, 2024
3a4b4ce
Implemented $name property in ReflectionAttribute adapter
kukulich Nov 27, 2024
153efc4
ReflectionProperty::__toString() returns also the doccomment
kukulich Nov 27, 2024
62722a3
ReflectionClassConstant::__toString() ReflectionEnumCase::__toString(…
kukulich Nov 27, 2024
1ff051f
Added ReflectionStringCastHelper
kukulich Nov 28, 2024
cbc8d7a
Added NotImplementedBecauseItTriggersAutoloading exception
kukulich Nov 28, 2024
86057e4
Added @return never
kukulich Nov 28, 2024
6bfdd81
Simplification
kukulich Dec 2, 2024
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
12 changes: 8 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
php-version:
- "8.2"
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"
- "windows-latest"
Expand Down Expand Up @@ -67,6 +68,7 @@ jobs:
php-version:
- "8.2"
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"

Expand Down Expand Up @@ -107,6 +109,7 @@ jobs:
dependencies:
- "locked"
php-version:
# Throws deprecated errors on 8.4
- "8.3"
operating-system:
- "ubuntu-latest"
Expand Down Expand Up @@ -148,6 +151,7 @@ jobs:
dependencies:
- "locked"
php-version:
# Does not work on 8.4
- "8.3"
operating-system:
- "ubuntu-latest"
Expand Down Expand Up @@ -192,7 +196,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"
- "windows-latest"
Expand Down Expand Up @@ -234,7 +238,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"

Expand Down Expand Up @@ -268,7 +272,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"
- "windows-latest"
Expand Down Expand Up @@ -347,7 +351,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Better Reflection - an improved code reflection API",
"license": "MIT",
"require": {
"php": "~8.2.0 || ~8.3.2",
"php": "~8.2.0 || ~8.3.2 || ~8.4.1",
"ext-json": "*",
"jetbrains/phpstorm-stubs": "2024.2",
"nikic/php-parser": "^5.3.1"
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ parameters:
- phar://%currentWorkingDirectory%/test/unit/Fixture/autoload.phar/vendor/autoload.php

ignoreErrors:
-
identifier: class.notFound
message: '#(unknown class|invalid type) PropertyHookType#'
Ocramius marked this conversation as resolved.
Show resolved Hide resolved

-
identifier: missingType.generics
-
Expand Down
12 changes: 12 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@
<code><![CDATA[getEndLine]]></code>
<code><![CDATA[getEndLine]]></code>
<code><![CDATA[getEndLine]]></code>
<code><![CDATA[getEndLine]]></code>
<code><![CDATA[getReturnType]]></code>
<code><![CDATA[getStartLine]]></code>
<code><![CDATA[getStartLine]]></code>
<code><![CDATA[getStartLine]]></code>
<code><![CDATA[getStartLine]]></code>
<code><![CDATA[getStartLine]]></code>
<code><![CDATA[getStmts]]></code>
<code><![CDATA[getStmts]]></code>
<code><![CDATA[getSubNodeNames]]></code>
<code><![CDATA[traverse]]></code>
</ImpureMethodCall>
Expand Down Expand Up @@ -201,14 +205,22 @@
<ImpureMethodCall>
<code><![CDATA[__invoke]]></code>
<code><![CDATA[classExists]]></code>
<code><![CDATA[createFromNode]]></code>
<code><![CDATA[getEndLine]]></code>
<code><![CDATA[getStartLine]]></code>
<code><![CDATA[getStmts]]></code>
<code><![CDATA[getStmts]]></code>
<code><![CDATA[isPrivate]]></code>
<code><![CDATA[isPrivateSet]]></code>
<code><![CDATA[isProtected]]></code>
<code><![CDATA[isProtectedSet]]></code>
<code><![CDATA[isPublic]]></code>
<code><![CDATA[isPublic]]></code>
<code><![CDATA[isReadonly]]></code>
<code><![CDATA[isStatic]]></code>
<code><![CDATA[traitExists]]></code>
<code><![CDATA[traverse]]></code>
<code><![CDATA[traverse]]></code>
</ImpureMethodCall>
</file>
<file src="src/Reflection/ReflectionType.php">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Roave\BetterReflection\Reflection\Adapter\Exception;

class NotImplementedBecauseItTriggersAutoloading extends NotImplemented
{
public static function create(): self
{
return new self('Not implemented because it triggers autoloading');
}
}
16 changes: 15 additions & 1 deletion src/Reflection/Adapter/ReflectionAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
namespace Roave\BetterReflection\Reflection\Adapter;

use Attribute;
use OutOfBoundsException;
use ReflectionAttribute as CoreReflectionAttribute;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;

use function sprintf;

/** @template-extends CoreReflectionAttribute<object> */
final class ReflectionAttribute extends CoreReflectionAttribute
{
public function __construct(private BetterReflectionAttribute $betterReflectionAttribute)
{
unset($this->name);
}

/** @psalm-mutation-free */
Expand Down Expand Up @@ -44,14 +48,24 @@ public function getArguments(): array
return $this->betterReflectionAttribute->getArguments();
}

/** @return never */
public function newInstance(): object
{
throw new Exception\NotImplemented('Not implemented');
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @return non-empty-string */
public function __toString(): string
{
return $this->betterReflectionAttribute->__toString();
}

public function __get(string $name): mixed
Ocramius marked this conversation as resolved.
Show resolved Hide resolved
{
if ($name === 'name') {
return $this->betterReflectionAttribute->getName();
}

throw new OutOfBoundsException(sprintf('Property %s::$%s does not exist.', self::class, $name));
}
}
85 changes: 81 additions & 4 deletions src/Reflection/Adapter/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
*/
final class ReflectionClass extends CoreReflectionClass
{
/**
* @internal
*
* @see CoreReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE_COMPATIBILITY
*/
public const SKIP_INITIALIZATION_ON_SERIALIZE_COMPATIBILITY = 8;

/**
* @internal
*
* @see CoreReflectionClass::SKIP_DESTRUCTOR
*/
public const SKIP_DESTRUCTOR_COMPATIBILITY = 16;

public function __construct(private BetterReflectionClass|BetterReflectionEnum $betterReflectionClass)
{
unset($this->name);
Expand Down Expand Up @@ -435,19 +449,78 @@ public function isInstance(object $object): bool
return $this->betterReflectionClass->isInstance($object);
}

/** @return never */
public function newInstance(mixed ...$args): self
{
throw new Exception\NotImplemented('Not implemented');
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @return never */
public function newInstanceWithoutConstructor(): object
{
throw new Exception\NotImplemented('Not implemented');
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @return never */
public function newInstanceArgs(array|null $args = null): object
{
throw new Exception\NotImplemented('Not implemented');
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/**
* @param int-mask-of<self::SKIP_*> $options
*
* @return never
*/
public function newLazyGhost(callable $initializer, int $options = 0): object
{
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/**
* @param int-mask-of<self::SKIP_*> $options
*
* @return never
*/
public function newLazyProxy(callable $factory, int $options = 0): object
{
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @return never */
public function markLazyObjectAsInitialized(object $object): object
{
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @return never */
public function getLazyInitializer(object $object): callable|null
{
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @return never */
public function initializeLazyObject(object $object): object
{
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @return never */
public function isUninitializedLazyObject(object $object): bool
{
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @param int-mask-of<self::SKIP_*> $options */
public function resetAsLazyGhost(object $object, callable $initializer, int $options = 0): never
{
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @param int-mask-of<self::SKIP_*> $options */
public function resetAsLazyProxy(object $object, callable $factory, int $options = 0): never
{
throw Exception\NotImplementedBecauseItTriggersAutoloading::create();
}

/** @psalm-mutation-free */
Expand Down Expand Up @@ -566,7 +639,11 @@ public function implementsInterface(CoreReflectionClass|string $interface): bool
return $this->betterReflectionClass->implementsInterface($realInterfaceName);
}

/** @psalm-mutation-free */
/**
* @return never
*
* @psalm-mutation-free
*/
public function getExtension(): CoreReflectionExtension|null
{
throw new Exception\NotImplemented('Not implemented');
Expand Down
5 changes: 5 additions & 0 deletions src/Reflection/Adapter/ReflectionClassConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public function isEnumCase(): bool
return $this->betterClassConstantOrEnumCase instanceof BetterReflectionEnumCase;
}

public function isDeprecated(): bool
{
return $this->betterClassConstantOrEnumCase->isDeprecated();
}

public function __get(string $name): mixed
{
if ($name === 'name') {
Expand Down
Loading