Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumped PHP version to 7.4 #1582

Closed
wants to merge 3 commits into from
Closed
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: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: true
matrix:
operating-system: [ ubuntu-latest ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
dependencies: [ 'lowest', 'highest' ]
exclude:
- php: '8.1'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: true
matrix:
operating-system: [ ubuntu-latest ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
dependencies: [ 'highest' ]

name: PHP ${{ matrix.php }} on ${{ matrix.operating-system }} with ${{ matrix.dependencies }} dependencies
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
},
"require": {
"php": ">=7.2",
"php": ">=7.4",
"ext-json": "*",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^2 || ^3",
Expand All @@ -62,6 +62,7 @@
"friendsofphp/php-cs-fixer": "^2.17 || ^3.47.1",
"phpstan/phpstan": "^1.6",
"phpunit/phpunit": ">=8",
"rector/rector": "^1.0",
"vimeo/psalm": "^4.23"
},
"suggest": {
Expand All @@ -84,6 +85,7 @@
"testlegacy": "Run tests using the legacy TokenAnalyser",
"testall": "Run all tests (test + testlegacy)",
"analyse": "Run static analysis (phpstan/psalm)",
"rector": "Automatic refactoring",
"spectral-examples": "Run spectral lint over all .yaml files in the Examples folder",
"spectral-scratch": "Run spectral lint over all .yaml files in the tests/Fixtures/Scratch folder",
"spectral": "Run all spectral tests",
Expand All @@ -107,6 +109,7 @@
"export XDEBUG_MODE=off && phpstan analyse --memory-limit=2G",
"export XDEBUG_MODE=off && psalm"
],
"rector": "rector process src --dry-run",
"spectral-examples": "for ff in `find Examples -name '*.yaml'`; do spectral lint $ff; done",
"spectral-scratch": "for ff in `find tests/Fixtures/Scratch -name '*.yaml'`; do spectral lint $ff; done",
"spectral": [
Expand Down
17 changes: 17 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->withRules([
TypedPropertyFromStrictConstructorRector::class
])
->withSkip([
ExplicitBoolCompareRector::class,
])
->withPreparedSets(true, true)
->withPhpVersion(PhpVersion::PHP_74)
;
27 changes: 12 additions & 15 deletions src/Analysers/AttributeAnnotationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ public function build(\Reflector $reflector, Context $context): array
}
$instance->nullable = $nullable ?: Generator::UNDEFINED;

if ($rp->isPromoted()) {
// promoted parameter - docblock is available via class/property
if ($comment = $rp->getDeclaringClass()->getProperty($rp->getName())->getDocComment()) {
$instance->_context->comment = $comment;
}
// promoted parameter - docblock is available via class/property
if ($rp->isPromoted() && ($comment = $rp->getDeclaringClass()->getProperty($rp->getName())->getDocComment())) {
$instance->_context->comment = $comment;
}
} else {
if (!$instance->name || Generator::isDefault($instance->name)) {
Expand Down Expand Up @@ -118,28 +116,27 @@ public function build(\Reflector $reflector, Context $context): array

$isParentAllowed = false;
// support Attachable subclasses
if ($isAttachable = $annotation instanceof OA\Attachable) {
if (!$isParentAllowed = (null === $annotation->allowedParents())) {
// check for allowed parents
foreach ($annotation->allowedParents() as $allowedParent) {
if ($possibleParent instanceof $allowedParent) {
$isParentAllowed = true;
break;
}
if (($isAttachable = $annotation instanceof OA\Attachable) && !$isParentAllowed = (null === $annotation->allowedParents())) {
// check for allowed parents
foreach ($annotation->allowedParents() as $allowedParent) {
if ($possibleParent instanceof $allowedParent) {
$isParentAllowed = true;
break;
}
}
}

// Property can be nested...
return $annotation->getRoot() != $possibleParent->getRoot()
return $annotation->getRoot() !== $possibleParent->getRoot()
&& ($explicitParent || ($isAttachable && $isParentAllowed));
};

$annotationsWithoutParent = [];
foreach ($annotations as $index => $annotation) {
$mergedIntoParent = false;
$counter = count($annotations);

for ($ii = 0; $ii < count($annotations); ++$ii) {
for ($ii = 0; $ii < $counter; ++$ii) {
if ($ii === $index) {
continue;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Analysers/DocBlockAnnotationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@

class DocBlockAnnotationFactory implements AnnotationFactoryInterface
{
/** @var DocBlockParser|null */
protected $docBlockParser = null;
protected DocBlockParser $docBlockParser;

/** @var Generator|null */
protected $generator = null;
protected $generator;

public function __construct(?DocBlockParser $docBlockParser = null)
{
Expand Down
5 changes: 2 additions & 3 deletions src/Analysers/ReflectionAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class ReflectionAnalyser implements AnalyserInterface
{
/** @var AnnotationFactoryInterface[] */
protected $annotationFactories;
protected $annotationFactories = [];

/** @var Generator|null */
protected $generator;
Expand All @@ -32,7 +32,6 @@ class ReflectionAnalyser implements AnalyserInterface
*/
public function __construct(array $annotationFactories = [])
{
$this->annotationFactories = [];
foreach ($annotationFactories as $annotationFactory) {
if ($annotationFactory->isSupported()) {
$this->annotationFactories[] = $annotationFactory;
Expand Down Expand Up @@ -118,7 +117,7 @@ protected function analyzeFqdn(string $fqdn, Analysis $analysis, array $details)
if ($parentClass = $rc->getParentClass()) {
$definition['extends'] = $normaliseClass($parentClass->getName());
}
$definition[$contextType == 'class' ? 'implements' : 'extends'] = array_map($normaliseClass, $details['interfaces']);
$definition[$contextType === 'class' ? 'implements' : 'extends'] = array_map($normaliseClass, $details['interfaces']);
$definition['traits'] = array_map($normaliseClass, $details['traits']);

foreach ($this->annotationFactories as $annotationFactory) {
Expand Down
36 changes: 19 additions & 17 deletions src/Analysers/TokenAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ public function setGenerator(Generator $generator): void
*/
public function fromFile(string $filename, Context $context): Analysis
{
if (function_exists('opcache_get_status') && function_exists('opcache_get_configuration')) {
if (empty($GLOBALS['openapi_opcache_warning'])) {
$GLOBALS['openapi_opcache_warning'] = true;
$status = opcache_get_status();
$config = opcache_get_configuration();
if (is_array($status) && $status['opcache_enabled'] && $config['directives']['opcache.save_comments'] == false) {
$context->logger->error("php.ini \"opcache.save_comments = 0\" interferes with extracting annotations.\n[LINK] https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.save-comments");
}
if (function_exists('opcache_get_status') && function_exists('opcache_get_configuration') && empty($GLOBALS['openapi_opcache_warning'])) {
$GLOBALS['openapi_opcache_warning'] = true;
$status = opcache_get_status();
$config = opcache_get_configuration();
if (is_array($status) && $status['opcache_enabled'] && $config['directives']['opcache.save_comments'] == false) {
$context->logger->error("php.ini \"opcache.save_comments = 0\" interferes with extracting annotations.\n[LINK] https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.save-comments");
}
}
$tokens = token_get_all(file_get_contents($filename));
Expand Down Expand Up @@ -166,7 +164,9 @@ protected function fromTokens(array $tokens, Context $parseContext): Analysis

if ($token[0] === T_IMPLEMENTS) {
$schemaContext->implements = $this->parseNamespaceList($tokens, $token, $parseContext);
$classDefinition['implements'] = array_map([$schemaContext, 'fullyQualifiedName'], $schemaContext->implements);
$classDefinition['implements'] = array_map(function (?string $source) use ($schemaContext): string {
return $schemaContext->fullyQualifiedName($source);
}, $schemaContext->implements);
}

if ($comment) {
Expand Down Expand Up @@ -207,7 +207,9 @@ protected function fromTokens(array $tokens, Context $parseContext): Analysis

if ($token[0] === T_EXTENDS) {
$schemaContext->extends = $this->parseNamespaceList($tokens, $token, $parseContext);
$interfaceDefinition['extends'] = array_map([$schemaContext, 'fullyQualifiedName'], $schemaContext->extends);
$interfaceDefinition['extends'] = array_map(function (?string $source) use ($schemaContext): string {
return $schemaContext->fullyQualifiedName($source);
}, $schemaContext->extends);
}

if ($comment) {
Expand Down Expand Up @@ -394,13 +396,11 @@ protected function fromTokens(array $tokens, Context $parseContext): Analysis
}
}

if (in_array($token[0], [T_NAMESPACE, T_USE]) === false) {
// Skip "use" & "namespace" to prevent "never imported" warnings)
if ($comment) {
// Not a doc-comment for a class, property or method?
$this->analyseComment($analysis, $docBlockParser, $comment, new Context(['line' => $line], $schemaContext));
$comment = false;
}
// Skip "use" & "namespace" to prevent "never imported" warnings)
if (in_array($token[0], [T_NAMESPACE, T_USE]) === false && $comment) {
// Not a doc-comment for a class, property or method?
$this->analyseComment($analysis, $docBlockParser, $comment, new Context(['line' => $line], $schemaContext));
$comment = false;
}

if ($token[0] === T_NAMESPACE) {
Expand Down Expand Up @@ -495,6 +495,8 @@ private function nextToken(array &$tokens, Context $context)

return $token;
}

return null;
}

private function parseAttribute(array &$tokens, &$token, Context $parseContext): void
Expand Down
14 changes: 6 additions & 8 deletions src/Analysers/TokenScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function scanTokens(array $tokens): array
break;
case '}':
array_pop($stack);
if (count($stack) == $unitLevel) {
if (count($stack) === $unitLevel) {
$currentName = null;
}
break;
Expand All @@ -76,7 +76,7 @@ protected function scanTokens(array $tokens): array

switch ($token[0]) {
case T_ABSTRACT:
if (count($stack)) {
if ($stack !== []) {
$isAbstractFunction = true;
}
break;
Expand Down Expand Up @@ -115,7 +115,7 @@ protected function scanTokens(array $tokens): array
// unless ...
if (is_string($token) && ($token === '(' || $token === '{')) {
// new class[()] { ... }
if ('{' == $token) {
if ('{' === $token) {
prev($tokens);
}
break;
Expand Down Expand Up @@ -219,10 +219,8 @@ protected function nextToken(array &$tokens)
$token = true;
while ($token) {
$token = next($tokens);
if (is_array($token)) {
if (in_array($token[0], [T_WHITESPACE, T_COMMENT])) {
continue;
}
if (is_array($token) && in_array($token[0], [T_WHITESPACE, T_COMMENT])) {
continue;
}

return $token;
Expand Down Expand Up @@ -254,7 +252,7 @@ protected function resolveFQN(array $names, string $namespace, array $uses): arr
protected function skipTo(array &$tokens, string $char, bool $prev = false): void
{
while (false !== ($token = next($tokens))) {
if (is_string($token) && $token == $char) {
if (is_string($token) && $token === $char) {
if ($prev) {
prev($tokens);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class Analysis
*
* @var OA\OpenApi|null
*/
public $openapi = null;
public $openapi;

/**
* @var Context|null
*/
public $context = null;
public $context;

public function __construct(array $annotations = [], ?Context $context = null)
{
Expand Down Expand Up @@ -347,7 +347,7 @@ public function getAnnotationForSource(string $fqdn, string $class): ?OA\Abstrac
if (is_iterable($definition['context']->annotations)) {
/** @var OA\AbstractAnnotation $annotation */
foreach (array_reverse($definition['context']->annotations) as $annotation) {
if (is_a($annotation, $class) && $annotation->isRoot($class) && !$annotation->_context->is('generated')) {
if ($annotation instanceof $class && $annotation->isRoot($class) && !$annotation->_context->is('generated')) {
return $annotation;
}
}
Expand Down
Loading