Skip to content

Commit

Permalink
feature #5776 DX: test on PHP 8.1 (kubawerlos)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

DX: test on PHP 8.1

Changes in `composer.json` must be reverted, this require:

- [x] [justinrainbow/json-schema](https://github.com/justinrainbow/json-schema) to be released with the fix: justinrainbow/json-schema#666
- [x] [mikey179/vfsstream](https://github.com/bovigo/vfsStream) new v1 version to be released
- [x] [mikey179/vfsstream](https://github.com/bovigo/vfsStream) another version (with bovigo/vfsStream#261) to be released
- [x] [symfony/symfony](https://github.com/symfony/symfony) new version (with symfony/symfony#42260) to be released

Commits
-------

a4358ec Test on PHP 8.1
  • Loading branch information
SpacePossum committed Dec 1, 2021
2 parents 77790a8 + a4358ec commit 075082e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -41,6 +41,10 @@ jobs:
calculate-code-coverage: 'yes'
phpunit-flags: '--testsuite coverage --exclude-group covers-nothing --coverage-clover build/logs/clover.xml'

- operating-system: 'ubuntu-20.04'
php-version: '8.1'
PHP_CS_FIXER_IGNORE_ENV: 1

- operating-system: 'windows-latest'
php-version: '7.4'
job-description: 'on Windows'
Expand Down
4 changes: 4 additions & 0 deletions src/Fixer/Operator/NewWithBracesFixer.php
Expand Up @@ -108,6 +108,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
[CT::T_BRACE_CLASS_INSTANTIATION_OPEN],
[CT::T_BRACE_CLASS_INSTANTIATION_CLOSE],
];
if (\defined('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG')) { // @TODO: drop condition when PHP 8.1+ is required
$nextTokenKinds[] = [T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG];
$nextTokenKinds[] = [T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG];
}
}

for ($index = $tokens->count() - 3; $index > 0; --$index) {
Expand Down
9 changes: 9 additions & 0 deletions src/Tokenizer/Token.php
Expand Up @@ -140,6 +140,15 @@ public static function getObjectOperatorKinds(): array
*/
public function equals($other, bool $caseSensitive = true): bool
{
if (\defined('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG')) { // @TODO: drop condition with new MAJOR release 4.0
if ('&' === $other) {
return '&' === $this->content && (null === $this->id || $this->isGivenKind([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG]));
}
if (null === $this->id && '&' === $this->content) {
return $other instanceof self && '&' === $other->content && (null === $other->id || $other->isGivenKind([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG]));
}
}

if ($other instanceof self) {
// Inlined getPrototype() on this very hot path.
// We access the private properties of $other directly to save function call overhead.
Expand Down
12 changes: 8 additions & 4 deletions src/Tokenizer/TokensAnalyzer.php
Expand Up @@ -569,6 +569,14 @@ public function isBinaryOperator(int $index): bool
$tokens = $this->tokens;
$token = $tokens[$index];

if ($token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) {
return false;
}

if (isset($potentialUnaryNonArrayOperators[$token->getContent()])) {
return !$this->isUnaryPredecessorOperator($index);
}

if ($token->isArray()) {
return isset($arrayOperators[$token->getId()]);
}
Expand All @@ -577,10 +585,6 @@ public function isBinaryOperator(int $index): bool
return true;
}

if (isset($potentialUnaryNonArrayOperators[$token->getContent()])) {
return !$this->isUnaryPredecessorOperator($index);
}

return false;
}

Expand Down
5 changes: 1 addition & 4 deletions src/Tokenizer/Transformer/ReturnRefTransformer.php
Expand Up @@ -46,10 +46,7 @@ public function process(Tokens $tokens, Token $token, int $index): void
$prevKinds[] = T_FN;
}

if (
($token->equals('&') || (\defined('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') && $token->isGivenKind(T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG)))
&& $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind($prevKinds)
) {
if (($token->equals('&')) && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind($prevKinds)) {
$tokens[$index] = new Token([CT::T_RETURN_REF, '&']);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Fixer/Basic/PsrAutoloadingFixerTest.php
Expand Up @@ -178,6 +178,7 @@ public function provideFixCases(): \Generator
{
$fileProphecy = $this->prophesize();
$fileProphecy->willExtend(\SplFileInfo::class);
$fileProphecy->willBeConstructedWith(['']);
$fileProphecy->getBasename('.php')->willReturn('Bar');
$fileProphecy->getExtension()->willReturn('php');
$fileProphecy->getRealPath()->willReturn(__DIR__.\DIRECTORY_SEPARATOR.'Psr'.\DIRECTORY_SEPARATOR.'Foo'.\DIRECTORY_SEPARATOR.'Bar.php');
Expand Down
8 changes: 8 additions & 0 deletions tests/Tokenizer/TokenTest.php
Expand Up @@ -346,6 +346,14 @@ public function provideEqualsCases(): \Generator
yield [$function, false, [T_FUNCTION, 'function', 'unexpected']];

yield [new Token('&'), true, '&'];
if (\defined('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG')) { // @TODO: drop condition with new MAJOR release 4.0
yield [new Token('&'), true, new Token([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, '&'])];
yield [new Token('&'), true, new Token([T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&'])];
yield [new Token([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, '&']), true, '&'];
yield [new Token([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, '&']), true, new Token([T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, '&'])];
yield [new Token([T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&']), true, '&'];
yield [new Token([T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&']), true, new Token([T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, '&'])];
}
}

public function testEqualsAnyDefaultIsCaseSensitive(): void
Expand Down

0 comments on commit 075082e

Please sign in to comment.