Skip to content
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
4 changes: 4 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"
operating-system:
- "ubuntu-latest"
- "windows-latest"
Expand Down Expand Up @@ -69,6 +70,7 @@ jobs:
- "8.2"
- "8.3"
- "8.4"
- "8.5"
operating-system:
- "ubuntu-latest"

Expand Down Expand Up @@ -110,6 +112,8 @@ jobs:
- "locked"
php-version:
- "8.4"
# Psalm currently fails
# - "8.5"
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 || ~8.4.1",
"php": "~8.2.0 || ~8.3.2 || ~8.4.1 || ~8.5.0",
"ext-json": "*",
"jetbrains/phpstorm-stubs": "2024.3",
"nikic/php-parser": "^5.6.0"
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.

6 changes: 6 additions & 0 deletions src/Reflection/Adapter/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ReflectionException as CoreReflectionException;
use ReflectionMethod as CoreReflectionMethod;
use ReflectionProperty as CoreReflectionProperty;
use Roave\BetterReflection\Reflection\Adapter\Exception\NotImplemented;
use Roave\BetterReflection\Reflection\Exception\NoObjectProvided;
use Roave\BetterReflection\Reflection\Exception\NotAnObject;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
Expand Down Expand Up @@ -355,4 +356,9 @@ public function __get(string $name): mixed

throw new OutOfBoundsException(sprintf('Property %s::$%s does not exist.', self::class, $name));
}

public function getMangledName(): string
{
throw new NotImplemented('Not implemented');
}
}
14 changes: 14 additions & 0 deletions test/unit/Fixture/PHP85ClassForSourceStubber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Roave\BetterReflectionTest\Fixture;

class ParentClassForSourceStubber
{
}

abstract class PHP85ClassForSourceStubber extends ParentClassForSourceStubber
{
public function methodWithSelfAndParentParameters(self $self, parent $parent) : void
{
}
}
10 changes: 10 additions & 0 deletions test/unit/Fixture/PHP85ClassForSourceStubberExpected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Roave\BetterReflectionTest\Fixture;

abstract class PHP85ClassForSourceStubber extends \Roave\BetterReflectionTest\Fixture\ParentClassForSourceStubber
{
public function methodWithSelfAndParentParameters(\Roave\BetterReflectionTest\Fixture\PHP85ClassForSourceStubber $self, \Roave\BetterReflectionTest\Fixture\ParentClassForSourceStubber $parent): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ static function (string $className): bool {
return false;
}

// https://github.com/JetBrains/phpstorm-stubs/pull/1781
/** @var list<class-string> $missingClasses */
$missingClasses = [
'NoDiscard',
'DelayedTargetValidation',
];
if (
PHP_VERSION_ID >= 80500
&& in_array($className, $missingClasses, true)
) {
return false;
}

// Check only always enabled extensions
return in_array($reflection->getExtensionName(), self::EXTENSIONS, true);
},
Expand Down Expand Up @@ -188,8 +201,17 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
$this->assertSameInterfaces($original, $stubbed);

foreach ($original->getMethods() as $method) {
$methodName = $original->getName() . '#' . $method->getName();

// https://github.com/JetBrains/phpstorm-stubs/pull/1781
if (
in_array($methodName, ['Closure#getCurrent'], true)
) {
continue;
}

$stubbedMethod = $stubbed->getMethod($method->getName());
self::assertNotNull($stubbedMethod);
self::assertNotNull($stubbedMethod, $methodName);

$this->assertSameMethodAttributes($method, $stubbedMethod);
}
Expand All @@ -204,10 +226,19 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
$originalConstantName = $originalConstant->getName();
assert($originalConstantName !== '');

$constantName = $original->getName() . '::' . $originalConstant->getName();

// https://github.com/JetBrains/phpstorm-stubs/pull/1781
if (
in_array($constantName, ['Attribute::TARGET_CONSTANT'], true)
) {
continue;
}

$stubbedConstant = $stubbed->getConstant($originalConstantName);

self::assertNotNull($stubbedConstant);
self::assertSame($originalConstant->getValue(), $stubbedConstant->getValue());
self::assertNotNull($stubbedConstant, $constantName);
self::assertSame($originalConstant->getValue(), $stubbedConstant->getValue(), $constantName);
}
}

Expand Down Expand Up @@ -301,6 +332,20 @@ public static function internalFunctionsProvider(): array
static function (string $functionName): bool {
$reflection = new CoreReflectionFunction($functionName);

// https://github.com/JetBrains/phpstorm-stubs/pull/1781
if (
PHP_VERSION_ID >= 80500
&& in_array($functionName, [
'array_first',
'array_last',
'clone',
'get_error_handler',
'get_exception_handler',
], true)
) {
return false;
}

// Check only always enabled extensions
return in_array($reflection->getExtensionName(), self::EXTENSIONS, true);
},
Expand Down Expand Up @@ -361,6 +406,18 @@ public static function internalConstantsProvider(): array
}

foreach ($extensionConstants as $constantName => $constantValue) {
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
if (
PHP_VERSION_ID >= 80500
&& in_array($constantName, [
'IMAGETYPE_SVG',
'IMAGETYPE_HEIF',
'PHP_BUILD_DATE',
], true)
) {
continue;
}

$provider[] = [$constantName, $constantValue, $extensionName];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Roave\BetterReflectionTest\Fixture\InterfaceForSourceStubber;
use Roave\BetterReflectionTest\Fixture\PHP81ClassForSourceStubber;
use Roave\BetterReflectionTest\Fixture\PHP83ClassForSourceStubber;
use Roave\BetterReflectionTest\Fixture\PHP85ClassForSourceStubber;
use Roave\BetterReflectionTest\Fixture\PHP8ClassForSourceStubber;
use Roave\BetterReflectionTest\Fixture\TraitForSourceStubber;
use stdClass;
Expand Down Expand Up @@ -116,6 +117,7 @@ public function testCanStubTraits(): void
self::assertNull($stubData->getExtensionName());
}

#[RequiresPhp('< 8.5')]
public function testClassStub(): void
{
require_once __DIR__ . '/../../Fixture/ClassForSourceStubber.php';
Expand Down Expand Up @@ -189,6 +191,17 @@ public function testClassStubWithTypedConstants(): void
self::assertStringEqualsFile(__DIR__ . '/../../Fixture/PHP83ClassForSourceStubberExpected.php', $stubData->getStub());
}

#[RequiresPhp('8.5')]
public function testClassStubWithPHP85Changes(): void
{
require_once __DIR__ . '/../../Fixture/PHP85ClassForSourceStubber.php';

$stubData = $this->stubber->generateClassStub(PHP85ClassForSourceStubber::class);

self::assertNotNull($stubData);
self::assertStringEqualsFile(__DIR__ . '/../../Fixture/PHP85ClassForSourceStubberExpected.php', $stubData->getStub());
}

public function testClassWithoutNamespaceStub(): void
{
require_once __DIR__ . '/../../Fixture/ClassWithoutNamespaceForSourceStubber.php';
Expand Down
Loading