Skip to content

Commit

Permalink
Merge pull request #1462 from kukulich/php84
Browse files Browse the repository at this point in the history
PHP 8.4 support
  • Loading branch information
Ocramius authored Dec 2, 2024
2 parents a67876e + 6bfdd81 commit 6ff8860
Show file tree
Hide file tree
Showing 66 changed files with 2,348 additions and 175 deletions.
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#'

-
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
{
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

0 comments on commit 6ff8860

Please sign in to comment.