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
2 changes: 2 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
env:
update: true

- name: "Cache dependencies"
uses: "actions/cache@v2"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
env:
update: true

- name: "Cache dependencies"
uses: "actions/cache@v2"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
env:
update: true

- name: "Cache dependencies"
uses: "actions/cache@v2"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/demo-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
env:
update: true

- name: "Cache dependencies"
uses: "actions/cache@v2"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/mutation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1, zend.assertions=1
env:
update: true

- name: "Cache dependencies"
uses: "actions/cache@v2"
Expand Down Expand Up @@ -64,6 +66,8 @@ jobs:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
env:
update: true

- name: "Infection"
run: "vendor/bin/roave-infection-static-analysis-plugin --coverage=coverage --threads=$(nproc)"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
php-version: "${{ matrix.php-version }}"
# No deprecated errors
ini-values: memory_limit=-1, error_reporting=24575
env:
update: true

- name: "Cache dependencies"
uses: "actions/cache@v2"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
env:
update: true

- name: "Cache dependencies"
uses: "actions/cache@v2"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
env:
update: true

- name: "Cache dependencies"
uses: "actions/cache@v2"
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.0 || ~8.1.0",
"php": "~8.0.12 || ~8.1.0",
"ext-json": "*",
"jetbrains/phpstorm-stubs": "2021.2",
"nikic/php-parser": "^4.13.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.

4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ parameters:
bootstrapFiles:
- stubs/ReflectionIntersectionType.php

# Needs new PHPStan version with newer stubs
excludePaths:
- src/Reflection/Adapter/ReflectionAttribute.php

ignoreErrors:
-
message: '#Access to an undefined property PhpParser\\Node\\Param::\$isOptional#'
Expand Down
48 changes: 48 additions & 0 deletions src/Reflection/Adapter/ReflectionAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Roave\BetterReflection\Reflection\Adapter;

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

final class ReflectionAttribute extends CoreReflectionAttribute
{
public function __construct(private BetterReflectionAttribute $betterReflectionAttribute)
{
}

public function getName(): string
{
return $this->betterReflectionAttribute->getName();
}

public function getTarget(): int
{
return $this->betterReflectionAttribute->getTarget();
}

public function isRepeated(): bool
{
return $this->betterReflectionAttribute->isRepeated();
}

/**
* @return array<int|string, mixed>
*/
public function getArguments(): array
{
return $this->betterReflectionAttribute->getArguments();
}

public function newInstance(): object
{
throw new Exception\NotImplemented('Not implemented');
}

public function __toString(): string
{
return $this->betterReflectionAttribute->__toString();
}
}
18 changes: 14 additions & 4 deletions src/Reflection/Adapter/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Roave\BetterReflection\Reflection\Adapter;

use OutOfBoundsException;
use ReflectionAttribute as CoreReflectionAttribute;
use ReflectionClass as CoreReflectionClass;
use ReflectionException as CoreReflectionException;
use ReflectionExtension as CoreReflectionExtension;
use ReflectionMethod as CoreReflectionMethod;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
use Roave\BetterReflection\Reflection\ReflectionClass as BetterReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionClassConstant as BetterReflectionClassConstant;
use Roave\BetterReflection\Reflection\ReflectionMethod as BetterReflectionMethod;
Expand Down Expand Up @@ -453,13 +453,23 @@ public function getShortName(): string
}

/**
* @return list<CoreReflectionAttribute>
* @param class-string|null $name
*
* @psalm-suppress LessSpecificImplementedReturnType
* @return list<ReflectionAttribute>
*
* @psalm-suppress ImplementedReturnTypeMismatch
*/
public function getAttributes(?string $name = null, int $flags = 0): array
{
throw new Exception\NotImplemented('Not implemented');
if ($name !== null && $flags & ReflectionAttribute::IS_INSTANCEOF) {
$attributes = $this->betterReflectionClass->getAttributesByInstance($name);
} elseif ($name !== null) {
$attributes = $this->betterReflectionClass->getAttributesByName($name);
} else {
$attributes = $this->betterReflectionClass->getAttributes();
}

return array_map(static fn (BetterReflectionAttribute $betterReflectionAttribute): ReflectionAttribute => new ReflectionAttribute($betterReflectionAttribute), $attributes);
}

public function isEnum(): bool
Expand Down
18 changes: 15 additions & 3 deletions src/Reflection/Adapter/ReflectionClassConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Roave\BetterReflection\Reflection\Adapter;

use ReflectionAttribute as CoreReflectionAttribute;
use ReflectionClassConstant as CoreReflectionClassConstant;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
use Roave\BetterReflection\Reflection\ReflectionClassConstant as BetterReflectionClassConstant;

use function array_map;

final class ReflectionClassConstant extends CoreReflectionClassConstant
{
public function __construct(private BetterReflectionClassConstant $betterClassConstant)
Expand Down Expand Up @@ -92,11 +94,21 @@ public function __toString(): string
}

/**
* @return list<CoreReflectionAttribute>
* @param class-string|null $name
*
* @return list<ReflectionAttribute>
*/
public function getAttributes(?string $name = null, int $flags = 0): array
{
throw new Exception\NotImplemented('Not implemented');
if ($name !== null && $flags & ReflectionAttribute::IS_INSTANCEOF) {
$attributes = $this->betterClassConstant->getAttributesByInstance($name);
} elseif ($name !== null) {
$attributes = $this->betterClassConstant->getAttributesByName($name);
} else {
$attributes = $this->betterClassConstant->getAttributes();
}

return array_map(static fn (BetterReflectionAttribute $betterReflectionAttribute): ReflectionAttribute => new ReflectionAttribute($betterReflectionAttribute), $attributes);
}

public function isFinal(): bool
Expand Down
31 changes: 21 additions & 10 deletions src/Reflection/Adapter/ReflectionFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
namespace Roave\BetterReflection\Reflection\Adapter;

use Closure;
use ReflectionAttribute as CoreReflectionAttribute;
use ReflectionClass as CoreReflectionClass;
use ReflectionException as CoreReflectionException;
use ReflectionExtension as CoreReflectionExtension;
use ReflectionFunction as CoreReflectionFunction;
use ReflectionType as CoreReflectionType;
use Roave\BetterReflection\Reflection\Adapter\Exception\NotImplemented;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
use Roave\BetterReflection\Reflection\ReflectionFunction as BetterReflectionFunction;
use Roave\BetterReflection\Util\FileHelper;
use Throwable;

use function array_map;
use function func_get_args;

final class ReflectionFunction extends CoreReflectionFunction
Expand Down Expand Up @@ -204,9 +205,9 @@ public function getClosure(): Closure
}

/**
* @return list<CoreReflectionAttribute>
* @return mixed[]
*/
public function getAttributes(?string $name = null, int $flags = 0): array
public function getClosureUsedVariables(): array
{
throw new Exception\NotImplemented('Not implemented');
}
Expand All @@ -221,16 +222,26 @@ public function getTentativeReturnType(): ?CoreReflectionType
return ReflectionType::fromTypeOrNull($this->betterReflectionFunction->getTentativeReturnType());
}

/**
* @return mixed[]
*/
public function getClosureUsedVariables(): array
public function isStatic(): bool
{
throw new Exception\NotImplemented('Not implemented');
return $this->betterReflectionFunction->isStatic();
}

public function isStatic(): bool
/**
* @param class-string|null $name
*
* @return list<ReflectionAttribute>
*/
public function getAttributes(?string $name = null, int $flags = 0): array
{
return $this->betterReflectionFunction->isStatic();
if ($name !== null && $flags & ReflectionAttribute::IS_INSTANCEOF) {
$attributes = $this->betterReflectionFunction->getAttributesByInstance($name);
} elseif ($name !== null) {
$attributes = $this->betterReflectionFunction->getAttributesByName($name);
} else {
$attributes = $this->betterReflectionFunction->getAttributes();
}

return array_map(static fn (BetterReflectionAttribute $betterReflectionAttribute): ReflectionAttribute => new ReflectionAttribute($betterReflectionAttribute), $attributes);
}
}
17 changes: 14 additions & 3 deletions src/Reflection/Adapter/ReflectionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
namespace Roave\BetterReflection\Reflection\Adapter;

use Closure;
use ReflectionAttribute as CoreReflectionAttribute;
use ReflectionClass as CoreReflectionClass;
use ReflectionException as CoreReflectionException;
use ReflectionExtension as CoreReflectionExtension;
use ReflectionMethod as CoreReflectionMethod;
use ReflectionType as CoreReflectionType;
use Roave\BetterReflection\Reflection\Adapter\Exception\NotImplemented;
use Roave\BetterReflection\Reflection\Exception\NoObjectProvided;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
use Roave\BetterReflection\Reflection\ReflectionMethod as BetterReflectionMethod;
use Roave\BetterReflection\Util\FileHelper;
use Throwable;
use TypeError;
use ValueError;

use function array_map;
use function func_get_args;

final class ReflectionMethod extends CoreReflectionMethod
Expand Down Expand Up @@ -290,11 +291,21 @@ private function isAccessible(): bool
}

/**
* @return list<CoreReflectionAttribute>
* @param class-string|null $name
*
* @return list<ReflectionAttribute>
*/
public function getAttributes(?string $name = null, int $flags = 0): array
{
throw new Exception\NotImplemented('Not implemented');
if ($name !== null && $flags & ReflectionAttribute::IS_INSTANCEOF) {
$attributes = $this->betterReflectionMethod->getAttributesByInstance($name);
} elseif ($name !== null) {
$attributes = $this->betterReflectionMethod->getAttributesByName($name);
} else {
$attributes = $this->betterReflectionMethod->getAttributes();
}

return array_map(static fn (BetterReflectionAttribute $betterReflectionAttribute): ReflectionAttribute => new ReflectionAttribute($betterReflectionAttribute), $attributes);
}

public function hasTentativeReturnType(): bool
Expand Down
18 changes: 14 additions & 4 deletions src/Reflection/Adapter/ReflectionObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Roave\BetterReflection\Reflection\Adapter;

use ReflectionAttribute as CoreReflectionAttribute;
use ReflectionClass as CoreReflectionClass;
use ReflectionException as CoreReflectionException;
use ReflectionExtension as CoreReflectionExtension;
use ReflectionObject as CoreReflectionObject;
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
use Roave\BetterReflection\Reflection\ReflectionClass as BetterReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionClassConstant as BetterReflectionClassConstant;
use Roave\BetterReflection\Reflection\ReflectionMethod as BetterReflectionMethod;
Expand Down Expand Up @@ -454,13 +454,23 @@ public function isAnonymous(): bool
}

/**
* @return list<CoreReflectionAttribute>
* @param class-string|null $name
*
* @psalm-suppress LessSpecificImplementedReturnType
* @return list<ReflectionAttribute>
*
* @psalm-suppress ImplementedReturnTypeMismatch
*/
public function getAttributes(?string $name = null, int $flags = 0): array
{
throw new Exception\NotImplemented('Not implemented');
if ($name !== null && $flags & ReflectionAttribute::IS_INSTANCEOF) {
$attributes = $this->betterReflectionObject->getAttributesByInstance($name);
} elseif ($name !== null) {
$attributes = $this->betterReflectionObject->getAttributesByName($name);
} else {
$attributes = $this->betterReflectionObject->getAttributes();
}

return array_map(static fn (BetterReflectionAttribute $betterReflectionAttribute): ReflectionAttribute => new ReflectionAttribute($betterReflectionAttribute), $attributes);
}

public function isEnum(): bool
Expand Down
Loading