Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 4.4:
  [Config] fix tracking attributes in ReflectionClassResource
  [Process] Fix incorrect parameter type
  [HttpFoundation] Handle tentative return types
  • Loading branch information
nicolas-grekas committed Jun 12, 2021
2 parents bae5fe0 + 7c97a6d commit 82a7f66
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Resource/ReflectionClassResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ private function computeHash(): string

private function generateSignature(\ReflectionClass $class): iterable
{
if (\PHP_VERSION_ID >= 80000) {
$attributes = [];
foreach ($class->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
}

yield $class->getDocComment();
yield (int) $class->isFinal();
yield (int) $class->isAbstract();
Expand All @@ -137,6 +146,14 @@ private function generateSignature(\ReflectionClass $class): iterable
$defaults = $class->getDefaultProperties();

foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
if (\PHP_VERSION_ID >= 80000) {
foreach ($p->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
}

yield $p->getDocComment();
yield $p->isDefault() ? '<default>' : '';
yield $p->isPublic() ? 'public' : 'protected';
Expand All @@ -147,9 +164,25 @@ private function generateSignature(\ReflectionClass $class): iterable
}

foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
if (\PHP_VERSION_ID >= 80000) {
foreach ($m->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
}

$defaults = [];
$parametersWithUndefinedConstants = [];
foreach ($m->getParameters() as $p) {
if (\PHP_VERSION_ID >= 80000) {
foreach ($p->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
}

if (!$p->isDefaultValueAvailable()) {
$defaults[$p->name] = null;

Expand Down
11 changes: 11 additions & 0 deletions Tests/Resource/ReflectionClassResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public function provideHashedSignature(): iterable
{
yield [false, 0, "// line change\n\n"];
yield [true, 0, '/** class docblock */'];

if (\PHP_VERSION_ID >= 80000) {
yield [true, 0, '#[Foo]'];
}

yield [true, 1, 'abstract class %s'];
yield [true, 1, 'final class %s'];
yield [true, 1, 'class %s extends Exception'];
Expand All @@ -140,6 +145,12 @@ public function provideHashedSignature(): iterable
yield [false, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"];
yield [true, 12, '/** prot docblock */'];
yield [true, 13, 'protected function prot($a = [123]) {}'];

if (\PHP_VERSION_ID >= 80000) {
yield [true, 13, '#[Foo] protected function prot($a = []) {}'];
yield [true, 13, 'protected function prot(#[Foo] $a = []) {}'];
}

yield [false, 14, '/** priv docblock */'];
yield [false, 15, ''];

Expand Down

0 comments on commit 82a7f66

Please sign in to comment.