Skip to content

Commit

Permalink
Merge pull request #1191 from kukulich/82
Browse files Browse the repository at this point in the history
Basic support for PHP 8.2
  • Loading branch information
Ocramius authored Sep 10, 2022
2 parents 2658607 + 0c0a243 commit 55b41a4
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
php-version:
- "8.0"
- "8.1"
- "8.2"
operating-system:
- "ubuntu-latest"
- "windows-latest"
Expand Down Expand Up @@ -58,6 +59,7 @@ jobs:
php-version:
- "8.0"
- "8.1"
- "8.2"
operating-system:
- "ubuntu-latest"

Expand Down Expand Up @@ -92,6 +94,7 @@ jobs:
php-version:
- "8.0"
- "8.1"
- "8.2"
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.0.12 || ~8.1.0",
"php": "~8.0.12 || ~8.1.0 || ~8.2.0",
"ext-json": "*",
"jetbrains/phpstorm-stubs": "2022.2",
"nikic/php-parser": "^4.15.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.

10 changes: 10 additions & 0 deletions src/Reflection/Adapter/ReflectionFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function getClosureScopeClass(): CoreReflectionClass|null
throw new NotImplemented('Not implemented');
}

public function getClosureCalledClass(): CoreReflectionClass|null
{
throw new NotImplemented('Not implemented');
}

public function getDocComment(): string|false
{
return $this->betterReflectionFunction->getDocComment() ?: false;
Expand Down Expand Up @@ -248,4 +253,9 @@ public function __get(string $name): mixed

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

public function isAnonymous(): bool
{
return $this->betterReflectionFunction->isClosure();
}
}
17 changes: 17 additions & 0 deletions src/Reflection/Adapter/ReflectionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use ReflectionMethod as CoreReflectionMethod;
use ReflectionType as CoreReflectionType;
use Roave\BetterReflection\Reflection\Adapter\Exception\NotImplemented;
use Roave\BetterReflection\Reflection\Exception\MethodPrototypeNotFound;
use Roave\BetterReflection\Reflection\Exception\NoObjectProvided;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
use Roave\BetterReflection\Reflection\ReflectionMethod as BetterReflectionMethod;
Expand Down Expand Up @@ -72,6 +73,11 @@ public function getClosureScopeClass(): CoreReflectionClass|null
throw new NotImplemented('Not implemented');
}

public function getClosureCalledClass(): CoreReflectionClass|null
{
throw new NotImplemented('Not implemented');
}

public function getDocComment(): string|false
{
return $this->betterReflectionMethod->getDocComment() ?: false;
Expand Down Expand Up @@ -260,6 +266,17 @@ public function getPrototype(): ReflectionMethod
return new self($this->betterReflectionMethod->getPrototype());
}

public function hasPrototype(): bool
{
try {
$this->betterReflectionMethod->getPrototype();

return true;
} catch (MethodPrototypeNotFound) {
return false;
}
}

/**
* @codeCoverageIgnore
* @infection-ignore-all
Expand Down
3 changes: 3 additions & 0 deletions test/unit/Fixture/DefaultProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Roave\BetterReflectionTest\Fixture;

use AllowDynamicProperties;

trait DefaultPropertiesTrait
{
public $fromTrait = 'anything';
}

#[AllowDynamicProperties]
class DefaultProperties
{
use DefaultPropertiesTrait;
Expand Down
3 changes: 3 additions & 0 deletions test/unit/Fixture/RuntimeProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Roave\BetterReflectionTest\Fixture;

use AllowDynamicProperties;

#[AllowDynamicProperties]
class RuntimeProperties
{
public $publicProperty;
Expand Down
3 changes: 3 additions & 0 deletions test/unit/Fixture/StringCastClassObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Roave\BetterReflectionTest\Fixture;

use AllowDynamicProperties;

#[AllowDynamicProperties]
class StringCastClassObject
{
public $notDynamicProperty;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Fixture/StringCastClassObjectExpected.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Object of class [ <user> class Roave\BetterReflectionTest\Fixture\StringCastClassObject ] {
@@ %s/Fixture/StringCastClassObject.php 5-8
@@ %s/Fixture/StringCastClassObject.php 7-11

- Constants [0] {
}
Expand Down
13 changes: 13 additions & 0 deletions test/unit/Reflection/Adapter/ReflectionFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function methodExpectationProvider(): array
['isUserDefined', [], true, null, true, null],
['getClosureThis', [], null, NotImplemented::class, null, null],
['getClosureScopeClass', [], null, NotImplemented::class, null, null],
['getClosureCalledClass', [], null, NotImplemented::class, null, null],
['getDocComment', [], '', null, false, null],
['getStartLine', [], 123, null, 123, null],
['getEndLine', [], 123, null, 123, null],
Expand Down Expand Up @@ -430,4 +431,16 @@ public function testUnknownProperty(): void
/** @phpstan-ignore-next-line */
$reflectionFunctionAdapter->foo;
}

public function testIsAnonymous(): void
{
$betterReflectionFunction = $this->createMock(BetterReflectionFunction::class);
$betterReflectionFunction
->method('isClosure')
->willReturn(true);

$reflectionFunctionAdapter = new ReflectionFunctionAdapter($betterReflectionFunction);

self::assertTrue($reflectionFunctionAdapter->isAnonymous());
}
}
26 changes: 26 additions & 0 deletions test/unit/Reflection/Adapter/ReflectionMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Roave\BetterReflection\Reflection\Adapter\ReflectionMethod as ReflectionMethodAdapter;
use Roave\BetterReflection\Reflection\Adapter\ReflectionNamedType as ReflectionNamedTypeAdapter;
use Roave\BetterReflection\Reflection\Adapter\ReflectionParameter as ReflectionParameterAdapter;
use Roave\BetterReflection\Reflection\Exception\MethodPrototypeNotFound;
use Roave\BetterReflection\Reflection\Exception\NoObjectProvided;
use Roave\BetterReflection\Reflection\Exception\ObjectNotInstanceOfClass;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
Expand Down Expand Up @@ -75,6 +76,7 @@ public function methodExpectationProvider(): array
['isUserDefined', [], true, null, true, null],
['getClosureThis', [], null, NotImplemented::class, null, null],
['getClosureScopeClass', [], null, NotImplemented::class, null, null],
['getClosureCalledClass', [], null, NotImplemented::class, null, null],
['getDocComment', [], '', null, false, null],
['getStartLine', [], 123, null, 123, null],
['getEndLine', [], 123, null, 123, null],
Expand Down Expand Up @@ -560,4 +562,28 @@ public function testUnknownProperty(): void
/** @phpstan-ignore-next-line */
$reflectionMethodAdapter->foo;
}

public function testHasPrototypeReturnsTrueWhenPrototypeExists(): void
{
$betterReflectionMethod = $this->createMock(BetterReflectionMethod::class);
$betterReflectionMethod
->method('getPrototype')
->willReturn($this->createMock(BetterReflectionMethod::class));

$reflectionMethodAdapter = new ReflectionMethodAdapter($betterReflectionMethod);

self::assertTrue($reflectionMethodAdapter->hasPrototype());
}

public function testHasPrototypeReturnsFalseWhenNoPrototype(): void
{
$betterReflectionMethod = $this->createMock(BetterReflectionMethod::class);
$betterReflectionMethod
->method('getPrototype')
->willThrowException(new MethodPrototypeNotFound());

$reflectionMethodAdapter = new ReflectionMethodAdapter($betterReflectionMethod);

self::assertFalse($reflectionMethodAdapter->hasPrototype());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
$this->assertSameInterfaces($original, $stubbed);

foreach ($original->getMethods() as $method) {
if (
PHP_VERSION_ID >= 80200
&& $original->getName() === 'SplFixedArray'
&& in_array($method->getName(), ['__serialize', '__unserialize'], true)
) {
// https://github.com/JetBrains/phpstorm-stubs/pull/1439
continue;
}

$this->assertSameMethodAttributes($method, $stubbed->getMethod($method->getName()));
}

Expand Down Expand Up @@ -349,6 +358,33 @@ public function internalConstantsProvider(): array
}

foreach ($extensionConstants as $constantName => $constantValue) {
// https://github.com/JetBrains/phpstorm-stubs/pull/1440
if (
in_array($constantName, [
'DECIMAL_POINT',
'THOUSANDS_SEP',
'GROUPING',
'ERA_YEAR',
'INT_CURR_SYMBOL',
'CURRENCY_SYMBOL',
'MON_DECIMAL_POINT',
'MON_THOUSANDS_SEP',
'MON_GROUPING',
'POSITIVE_SIGN',
'NEGATIVE_SIGN',
'INT_FRAC_DIGITS',
'FRAC_DIGITS',
'P_CS_PRECEDES',
'P_SEP_BY_SPACE',
'N_CS_PRECEDES',
'N_SEP_BY_SPACE',
'P_SIGN_POSN',
'N_SIGN_POSN',
], true)
) {
continue;
}

$provider[] = [$constantName, $constantValue, $extensionName];
}
}
Expand Down

0 comments on commit 55b41a4

Please sign in to comment.