mirror of
https://github.com/doctrine/reflection.git
synced 2026-03-24 08:42:07 +01:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa587178be | ||
|
|
dc269e064a | ||
|
|
a8d82251c6 | ||
|
|
f3ade869eb | ||
|
|
06eec07aa3 | ||
|
|
2336d15b1a | ||
|
|
a82bebf801 | ||
|
|
e65c2eb6a8 | ||
|
|
e3c48f5fbd | ||
|
|
cac3bcb8fc | ||
|
|
db4b566464 | ||
|
|
486d0cbea5 | ||
|
|
cea2760c34 | ||
|
|
4f143d5384 | ||
|
|
efdbb0f82a | ||
|
|
edfb312da0 | ||
|
|
344bc74ba8 | ||
|
|
1b33070b49 | ||
|
|
41a2f0f445 | ||
|
|
d11bac73db | ||
|
|
1c7272c98a | ||
|
|
8f7fdc01b3 | ||
|
|
55e71912df | ||
|
|
fbc77cc1c8 | ||
|
|
79de2517ba | ||
|
|
827618c360 | ||
|
|
1a5837f909 | ||
|
|
1ab281861b |
@@ -5,21 +5,27 @@
|
||||
"docsSlug": "doctrine-reflection",
|
||||
"versions": [
|
||||
{
|
||||
"name": "1.2",
|
||||
"name": "1.3",
|
||||
"branchName": "master",
|
||||
"slug": "latest",
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "1.1",
|
||||
"branchName": "1.1.x",
|
||||
"slug": "1.1",
|
||||
"name": "1.2",
|
||||
"branchName": "1.2.x",
|
||||
"slug": "1.2",
|
||||
"current": true,
|
||||
"aliases": [
|
||||
"current",
|
||||
"stable"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "1.1",
|
||||
"branchName": "1.1.x",
|
||||
"slug": "1.1",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "1.0",
|
||||
"branchName": "1.0",
|
||||
|
||||
50
.github/workflows/coding-standards.yml
vendored
Normal file
50
.github/workflows/coding-standards.yml
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
name: "Coding Standards"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "*.x"
|
||||
- "master"
|
||||
push:
|
||||
branches:
|
||||
- "*.x"
|
||||
- "master"
|
||||
|
||||
env:
|
||||
COMPOSER_ROOT_VERSION: "1.2"
|
||||
|
||||
jobs:
|
||||
coding-standards:
|
||||
name: "Coding Standards"
|
||||
runs-on: "ubuntu-20.04"
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
php-version:
|
||||
- "7.4"
|
||||
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v2"
|
||||
|
||||
- name: "Install PHP"
|
||||
uses: "shivammathur/setup-php@v2"
|
||||
with:
|
||||
coverage: "none"
|
||||
php-version: "${{ matrix.php-version }}"
|
||||
tools: "cs2pr"
|
||||
|
||||
- name: "Cache dependencies installed with Composer"
|
||||
uses: "actions/cache@v2"
|
||||
with:
|
||||
path: "~/.composer/cache"
|
||||
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
|
||||
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
|
||||
|
||||
- name: "Install dependencies with Composer"
|
||||
run: "composer install --no-interaction --no-progress --no-suggest"
|
||||
|
||||
# https://github.com/doctrine/.github/issues/3
|
||||
- name: "Run PHP_CodeSniffer"
|
||||
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr"
|
||||
45
.github/workflows/release-on-milestone-closed.yml
vendored
Normal file
45
.github/workflows/release-on-milestone-closed.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: "Automatic Releases"
|
||||
|
||||
on:
|
||||
milestone:
|
||||
types:
|
||||
- "closed"
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: "Git tag, release & create merge-up PR"
|
||||
runs-on: "ubuntu-20.04"
|
||||
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v2"
|
||||
|
||||
- name: "Release"
|
||||
uses: "laminas/automatic-releases@v1"
|
||||
with:
|
||||
command-name: "laminas:automatic-releases:release"
|
||||
env:
|
||||
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
|
||||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
|
||||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
|
||||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
|
||||
|
||||
- name: "Create Merge-Up Pull Request"
|
||||
uses: "laminas/automatic-releases@v1"
|
||||
with:
|
||||
command-name: "laminas:automatic-releases:create-merge-up-pull-request"
|
||||
env:
|
||||
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
|
||||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
|
||||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
|
||||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
|
||||
|
||||
- name: "Create new milestones"
|
||||
uses: "laminas/automatic-releases@v1"
|
||||
with:
|
||||
command-name: "laminas:automatic-releases:create-milestones"
|
||||
env:
|
||||
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
|
||||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
|
||||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
|
||||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
|
||||
@@ -1,29 +0,0 @@
|
||||
build:
|
||||
nodes:
|
||||
analysis:
|
||||
environment:
|
||||
php:
|
||||
version: 7.1
|
||||
cache:
|
||||
disabled: false
|
||||
directories:
|
||||
- ~/.composer/cache
|
||||
project_setup:
|
||||
override: true
|
||||
tests:
|
||||
override:
|
||||
- php-scrutinizer-run
|
||||
- phpcs-run
|
||||
dependencies:
|
||||
override:
|
||||
- composer install -noa
|
||||
|
||||
tools:
|
||||
external_code_coverage:
|
||||
timeout: 600
|
||||
|
||||
build_failure_conditions:
|
||||
- 'elements.rating(<= C).new.exists' # No new classes/methods with a rating of C or worse allowed
|
||||
- 'issues.label("coding-style").new.exists' # No new coding style issues allowed
|
||||
- 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity
|
||||
- 'project.metric_change("scrutinizer.test_coverage", < 0)' # Code Coverage decreased from previous inspection
|
||||
21
.travis.yml
21
.travis.yml
@@ -1,7 +1,11 @@
|
||||
dist: trusty
|
||||
dist: xenial
|
||||
sudo: false
|
||||
language: php
|
||||
|
||||
env:
|
||||
global:
|
||||
- COMPOSER_ROOT_VERSION=1.2
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
@@ -17,6 +21,7 @@ before_install:
|
||||
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
|
||||
|
||||
install:
|
||||
- composer validate --strict
|
||||
- rm composer.lock
|
||||
- travis_retry composer update -n --prefer-dist
|
||||
|
||||
@@ -33,16 +38,12 @@ jobs:
|
||||
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
|
||||
script:
|
||||
- ./vendor/bin/phpunit --coverage-clover clover.xml
|
||||
after_script:
|
||||
- wget https://scrutinizer-ci.com/ocular.phar
|
||||
- php ocular.phar code-coverage:upload --format=php-clover clover.xml
|
||||
|
||||
- stage: Coding standard
|
||||
install:
|
||||
- travis_retry composer install -n --prefer-dist
|
||||
script:
|
||||
- ./vendor/bin/phpcs
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
- stage: Lint
|
||||
install:
|
||||
# Use lock file for install so old version of phpstan is used.
|
||||
- travis_retry composer install -n --prefer-dist
|
||||
php: 7.4
|
||||
script: vendor/bin/phpstan analyse
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# Doctrine Reflection
|
||||
|
||||
[](https://travis-ci.org/doctrine/reflection)
|
||||
[](https://scrutinizer-ci.com/g/doctrine/reflection/?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/doctrine/reflection/?branch=master)
|
||||
[](https://codecov.io/gh/doctrine/reflection/branch/master)
|
||||
|
||||
The Doctrine Reflection project is a simple library used by the various Doctrine projects which adds some additional functionality on top of the reflection functionality that comes with PHP. It allows you to get the reflection information about classes, methods and properties statically.
|
||||
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
{"name": "Marco Pivetta", "email": "ocramius@gmail.com"}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1",
|
||||
"php": "^7.1 || ^8.0",
|
||||
"ext-tokenizer": "*",
|
||||
"doctrine/annotations": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^0.11.0",
|
||||
"phpstan/phpstan-phpunit": "^0.11.0",
|
||||
"phpunit/phpunit": "^7.0",
|
||||
"doctrine/coding-standard": "^5.0",
|
||||
"doctrine/common": "^2.10"
|
||||
"doctrine/coding-standard": "^6.0 || ^8.2.0",
|
||||
"doctrine/common": "^2.10",
|
||||
"phpstan/phpstan": "^0.11.0 || ^0.12.20",
|
||||
"phpstan/phpstan-phpunit": "^0.11.0 || ^0.12.16",
|
||||
"phpunit/phpunit": "^7.5 || ^9.1.5"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/common": "<2.9"
|
||||
@@ -42,6 +42,9 @@
|
||||
"Doctrine\\Tests_PHP74\\": "tests/Doctrine/Tests_PHP74"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.2.x-dev"
|
||||
|
||||
1518
composer.lock
generated
1518
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Reflection\Compatibility\Php7;
|
||||
|
||||
use ReflectionException;
|
||||
|
||||
trait ReflectionClass
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConstants()
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function newInstance($args)
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Reflection\Compatibility\Php7;
|
||||
|
||||
use ReflectionException;
|
||||
|
||||
trait ReflectionMethod
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function invoke($object, $parameter = null)
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Reflection\Compatibility\Php8;
|
||||
|
||||
use ReflectionException;
|
||||
|
||||
trait ReflectionClass
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConstants(?int $filter = null)
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function newInstance(mixed ...$args)
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Reflection\Compatibility\Php8;
|
||||
|
||||
use ReflectionException;
|
||||
|
||||
trait ReflectionMethod
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function invoke(?object $object, mixed ...$args)
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Reflection\Compatibility;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
use function class_alias;
|
||||
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
class_alias('Doctrine\Common\Reflection\Compatibility\Php8\ReflectionClass', 'Doctrine\Common\Reflection\Compatibility\ReflectionClass');
|
||||
} else {
|
||||
class_alias('Doctrine\Common\Reflection\Compatibility\Php7\ReflectionClass', 'Doctrine\Common\Reflection\Compatibility\ReflectionClass');
|
||||
}
|
||||
|
||||
if (false) {
|
||||
class ReflectionClass
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Reflection\Compatibility;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
use function class_alias;
|
||||
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
class_alias('Doctrine\Common\Reflection\Compatibility\Php8\ReflectionMethod', 'Doctrine\Common\Reflection\Compatibility\ReflectionMethod');
|
||||
} else {
|
||||
class_alias('Doctrine\Common\Reflection\Compatibility\Php7\ReflectionMethod', 'Doctrine\Common\Reflection\Compatibility\ReflectionMethod');
|
||||
}
|
||||
|
||||
if (false) {
|
||||
class ReflectionMethod
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace Doctrine\Common\Reflection;
|
||||
|
||||
use Doctrine\Common\Reflection\Compatibility\ReflectionClass as CompatibilityReflectionClass;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
|
||||
class StaticReflectionClass extends ReflectionClass
|
||||
{
|
||||
use CompatibilityReflectionClass;
|
||||
|
||||
/**
|
||||
* The static reflection parser object.
|
||||
*
|
||||
@@ -83,14 +86,6 @@ class StaticReflectionClass extends ReflectionClass
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConstants()
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -371,14 +366,6 @@ class StaticReflectionClass extends ReflectionClass
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function newInstance($args)
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace Doctrine\Common\Reflection;
|
||||
|
||||
use Doctrine\Common\Reflection\Compatibility\ReflectionMethod as CompatibilityReflectionMethod;
|
||||
use ReflectionException;
|
||||
use ReflectionMethod;
|
||||
|
||||
class StaticReflectionMethod extends ReflectionMethod
|
||||
{
|
||||
use CompatibilityReflectionMethod;
|
||||
|
||||
/**
|
||||
* The PSR-0 parser object.
|
||||
*
|
||||
@@ -110,14 +113,6 @@ class StaticReflectionMethod extends ReflectionMethod
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function invoke($object, $parameter = null)
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,7 @@ use const T_VAR;
|
||||
use const T_VARIABLE;
|
||||
use function array_merge;
|
||||
use function file_get_contents;
|
||||
use function is_array;
|
||||
use function ltrim;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
@@ -189,6 +190,9 @@ class StaticReflectionParser implements ReflectionProviderInterface
|
||||
while (($token = $tokenParser->next()) && $token[0] !== T_STRING) {
|
||||
continue;
|
||||
}
|
||||
if ($token === null) {
|
||||
break;
|
||||
}
|
||||
$methodName = $token[1];
|
||||
$this->docComment['method'][$methodName] = $docComment;
|
||||
$docComment = '';
|
||||
@@ -222,7 +226,7 @@ class StaticReflectionParser implements ReflectionProviderInterface
|
||||
break;
|
||||
}
|
||||
|
||||
$last_token = $token[0];
|
||||
$last_token = is_array($token) ? $token[0] : false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class TypedNoDefaultReflectionProperty extends ReflectionProperty
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Checks that a typed property is initialized before accessing its value.
|
||||
* This is neccessary to avoid PHP error "Error: Typed property must not be accessed before initialization".
|
||||
* This is necessary to avoid PHP error "Error: Typed property must not be accessed before initialization".
|
||||
* Should be used only for reflecting typed properties without a default value.
|
||||
*/
|
||||
public function getValue($object = null)
|
||||
@@ -31,7 +31,7 @@ class TypedNoDefaultReflectionProperty extends ReflectionProperty
|
||||
*/
|
||||
public function setValue($object, $value = null)
|
||||
{
|
||||
if ($value === null) {
|
||||
if ($value === null && $this->hasType() && ! $this->getType()->allowsNull()) {
|
||||
$propertyName = $this->getName();
|
||||
|
||||
$unsetter = function () use ($propertyName) {
|
||||
|
||||
@@ -7,5 +7,8 @@ parameters:
|
||||
ignoreErrors:
|
||||
- '#Doctrine\\Common\\Reflection\\StaticReflection[a-zA-Z0-9_]+::__construct\(\) does not call parent constructor from Reflection[a-zA-Z0-9_]+#'
|
||||
|
||||
excludes_analyse:
|
||||
- lib/Doctrine/Common/Reflection/Compatibility/ReflectionClass.php
|
||||
- lib/Doctrine/Common/Reflection/Compatibility/ReflectionMethod.php
|
||||
includes:
|
||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests_PHP74\Common\Reflection\Dummies;
|
||||
|
||||
trait TokenParserAnonymousFunctionTestClass
|
||||
{
|
||||
protected function method()
|
||||
{
|
||||
return static function ($value) {
|
||||
return $value;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests_PHP74\Common\Reflection;
|
||||
|
||||
use Doctrine\Common\Reflection\Psr0FindFile;
|
||||
use Doctrine\Common\Reflection\StaticReflectionParser;
|
||||
use Doctrine\Tests_PHP74\Common\Reflection\Dummies\TokenParserAnonymousFunctionTestClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
|
||||
class TokenParserAnonymousFunctionTest extends TestCase
|
||||
{
|
||||
public function testGetValue() : void
|
||||
{
|
||||
$testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1);
|
||||
$paths = [
|
||||
'Doctrine\\Tests_PHP74' => [$testsRoot],
|
||||
];
|
||||
$staticReflectionParser = new StaticReflectionParser(TokenParserAnonymousFunctionTestClass::class, new Psr0FindFile($paths));
|
||||
|
||||
self::assertEquals('', $staticReflectionParser->getDocComment());
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,26 @@ class TypedNoDefaultReflectionPropertyTest extends TestCase
|
||||
$object = new TypedFoo();
|
||||
$object->setId(1);
|
||||
|
||||
self::assertTrue($reflection->isInitialized($object));
|
||||
|
||||
$reflection->setValue($object, null);
|
||||
|
||||
self::assertNull($reflection->getValue($object));
|
||||
self::assertFalse($reflection->isInitialized($object));
|
||||
}
|
||||
|
||||
public function testSetValueNullOnNullableProperty() : void
|
||||
{
|
||||
$reflection = new TypedNoDefaultReflectionProperty(TypedNullableFoo::class, 'value');
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
$object = new TypedNullableFoo();
|
||||
|
||||
$reflection->setValue($object, null);
|
||||
|
||||
self::assertNull($reflection->getValue($object));
|
||||
self::assertTrue($reflection->isInitialized($object));
|
||||
self::assertNull($object->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,3 +69,18 @@ class TypedFoo
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
|
||||
class TypedNullableFoo
|
||||
{
|
||||
private ?string $value;
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user