Skip to content

Commit

Permalink
minor #5532 Apply PHP 7.1 typing (keradus)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 3.0 branch.

Discussion
----------

Apply PHP 7.1 typing

Commits
-------

b567e30 Apply PHP 7.1 typing
  • Loading branch information
keradus committed Mar 7, 2021
2 parents a01d9a5 + b567e30 commit 55158a6
Show file tree
Hide file tree
Showing 881 changed files with 6,886 additions and 10,708 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -12,6 +12,7 @@ jobs:
include:
- operating-system: 'ubuntu-20.04'
php-version: '7.1'
job-description: 'with lowest deps'
composer-flags: '--prefer-stable --prefer-lowest' # should be checked on lowest supported PHP version

- operating-system: 'ubuntu-20.04'
Expand Down Expand Up @@ -114,7 +115,7 @@ jobs:
- name: Execute migration rules
if: matrix.execute-migration-rules == 'yes'
run: php php-cs-fixer fix --rules @PHP80Migration,@PHP80Migration:risky,blank_line_after_opening_tag,-list_syntax -q
run: php php-cs-fixer fix --rules @PHP80Migration,@PHP80Migration:risky -q

- name: Disable time limit for tests when collecting coverage
if: matrix.calculate-code-coverage == 'yes'
Expand Down
5 changes: 2 additions & 3 deletions .php_cs.dist
Expand Up @@ -15,20 +15,19 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->append([
__DIR__.'/dev-tools/doc.php',
__DIR__.'/php-cs-fixer',
// __DIR__.'/php-cs-fixer', disabled, as we want to be able to run bootstrap file even on lower PHP version, to show nice message
])
;

$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setRules([
'@PHP56Migration:risky' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'header_comment' => ['header' => $header],
'list_syntax' => ['syntax' => 'long'],
])
->setFinder($finder)
;
Expand Down
7 changes: 1 addition & 6 deletions dev-tools/composer-alias-update.php
Expand Up @@ -5,12 +5,7 @@

const COMPOSER_JSON_FILE = __DIR__.'/../composer.json';

/**
* @param string $version
*
* @return string
*/
function convertAppVersionToAliasedVersion($version)
function convertAppVersionToAliasedVersion(string $version): string
{
$parts = explode('.', $version, 3);

Expand Down
16 changes: 0 additions & 16 deletions phpstan.neon
Expand Up @@ -16,26 +16,10 @@ parameters:
-
message: '/^Strict comparison using !== between ''@git-commit@'' and ''@git-commit@'' will always evaluate to false\.$/'
path: src/Console/Application.php
-
message: '/^Result of && is always false\.$/'
path: src/Config.php
-
message: '/^Strict comparison using === between false and true will always evaluate to false\.$/'
path: src/Config.php
-
message: '/^Else branch is unreachable because ternary operator condition is always true\.$/'
paths:
- src/Config.php
- src/Tokenizer/Token.php
-
message: '/^Parameter #1 \$fixers of method PhpCsFixer\\Config::registerCustomFixers\(\) expects iterable<PhpCsFixer\\Fixer\\FixerInterface>, string given\.$/'
path: tests/ConfigTest.php
-
message: '/^Parameter #1 \$function of function register_shutdown_function expects callable\(\): void, array\(\$this\(PhpCsFixer\\FileRemoval\), ''clean''\) given\.$/'
path: src/FileRemoval.php
-
message: '/^Parameter #1 \$finder of method PhpCsFixer\\Config::setFinder\(\) expects iterable<string>, int given\.$/'
path: tests/ConfigTest.php
- # https://github.com/phpstan/phpstan/issues/1215
message: '/^Strict comparison using === between false and string will always evaluate to false\.$/'
path: src/Fixer/StringNotation/NoTrailingWhitespaceInStringFixer.php
Expand Down
20 changes: 9 additions & 11 deletions src/AbstractDoctrineAnnotationFixer.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of PHP CS Fixer.
*
Expand All @@ -15,6 +17,7 @@
use PhpCsFixer\Doctrine\Annotation\Tokens as DoctrineAnnotationTokens;
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
use PhpCsFixer\Tokenizer\CT;
use PhpCsFixer\Tokenizer\Token;
Expand All @@ -34,15 +37,15 @@ abstract class AbstractDoctrineAnnotationFixer extends AbstractFixer implements
/**
* {@inheritdoc}
*/
public function isCandidate(Tokens $tokens)
public function isCandidate(Tokens $tokens): bool
{
return $tokens->isTokenKindFound(T_DOC_COMMENT);
}

/**
* {@inheritdoc}
*/
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
{
// fetch indexes one time, this is safe as we never add or remove a token during fixing
$analyzer = new TokensAnalyzer($tokens);
Expand All @@ -66,17 +69,17 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
/**
* Fixes Doctrine annotations from the given PHPDoc style comment.
*/
abstract protected function fixAnnotations(DoctrineAnnotationTokens $doctrineAnnotationTokens);
abstract protected function fixAnnotations(DoctrineAnnotationTokens $doctrineAnnotationTokens): void;

/**
* {@inheritdoc}
*/
protected function createConfigurationDefinition()
protected function createConfigurationDefinition(): FixerConfigurationResolverInterface
{
return new FixerConfigurationResolver([
(new FixerOptionBuilder('ignored_tags', 'List of tags that must not be treated as Doctrine Annotations.'))
->setAllowedTypes(['array'])
->setAllowedValues([static function ($values) {
->setAllowedValues([static function (array $values) {
foreach ($values as $value) {
if (!\is_string($value)) {
return false;
Expand Down Expand Up @@ -194,12 +197,7 @@ protected function createConfigurationDefinition()
]);
}

/**
* @param int $index
*
* @return bool
*/
private function nextElementAcceptsDoctrineAnnotations(Tokens $tokens, $index)
private function nextElementAcceptsDoctrineAnnotations(Tokens $tokens, int $index): bool
{
do {
$index = $tokens->getNextMeaningfulToken($index);
Expand Down
27 changes: 13 additions & 14 deletions src/AbstractFixer.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of PHP CS Fixer.
*
Expand Down Expand Up @@ -63,7 +65,7 @@ public function __construct()
}
}

final public function fix(\SplFileInfo $file, Tokens $tokens)
final public function fix(\SplFileInfo $file, Tokens $tokens): void
{
if ($this instanceof ConfigurableFixerInterface && null === $this->configuration) {
throw new RequiredFixerConfigurationException($this->getName(), 'Configuration is required.');
Expand All @@ -77,15 +79,15 @@ final public function fix(\SplFileInfo $file, Tokens $tokens)
/**
* {@inheritdoc}
*/
public function isRisky()
public function isRisky(): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
$nameParts = explode('\\', static::class);
$name = substr(end($nameParts), 0, -\strlen('Fixer'));
Expand All @@ -96,20 +98,20 @@ public function getName()
/**
* {@inheritdoc}
*/
public function getPriority()
public function getPriority(): int
{
return 0;
}

/**
* {@inheritdoc}
*/
public function supports(\SplFileInfo $file)
public function supports(\SplFileInfo $file): bool
{
return true;
}

public function configure(array $configuration)
public function configure(array $configuration): void
{
if (!$this instanceof ConfigurableFixerInterface) {
throw new \LogicException('Cannot configure using Abstract parent, child not implementing "PhpCsFixer\Fixer\ConfigurableFixerInterface".');
Expand Down Expand Up @@ -164,7 +166,7 @@ public function configure(array $configuration)
/**
* {@inheritdoc}
*/
public function getConfigurationDefinition()
public function getConfigurationDefinition(): FixerConfigurationResolverInterface
{
if (!$this instanceof ConfigurableFixerInterface) {
throw new \LogicException(sprintf('Cannot get configuration definition using Abstract parent, child "%s" not implementing "PhpCsFixer\Fixer\ConfigurableFixerInterface".', static::class));
Expand All @@ -177,7 +179,7 @@ public function getConfigurationDefinition()
return $this->configurationDefinition;
}

public function setWhitespacesConfig(WhitespacesFixerConfig $config)
public function setWhitespacesConfig(WhitespacesFixerConfig $config): void
{
if (!$this instanceof WhitespacesAwareFixerInterface) {
throw new \LogicException('Cannot run method for class not implementing "PhpCsFixer\Fixer\WhitespacesAwareFixerInterface".');
Expand All @@ -186,12 +188,9 @@ public function setWhitespacesConfig(WhitespacesFixerConfig $config)
$this->whitespacesConfig = $config;
}

abstract protected function applyFix(\SplFileInfo $file, Tokens $tokens);
abstract protected function applyFix(\SplFileInfo $file, Tokens $tokens): void;

/**
* @return FixerConfigurationResolverInterface
*/
protected function createConfigurationDefinition()
protected function createConfigurationDefinition(): FixerConfigurationResolverInterface
{
if (!$this instanceof ConfigurableFixerInterface) {
throw new \LogicException('Cannot create configuration definition using Abstract parent, child not implementing "PhpCsFixer\Fixer\ConfigurableFixerInterface".');
Expand All @@ -200,7 +199,7 @@ protected function createConfigurationDefinition()
throw new \LogicException('Not implemented.');
}

private function getDefaultWhitespacesFixerConfig()
private function getDefaultWhitespacesFixerConfig(): WhitespacesFixerConfig
{
static $defaultWhitespacesFixerConfig = null;

Expand Down
15 changes: 6 additions & 9 deletions src/AbstractFopenFlagFixer.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of PHP CS Fixer.
*
Expand All @@ -25,15 +27,15 @@ abstract class AbstractFopenFlagFixer extends AbstractFunctionReferenceFixer
/**
* {@inheritdoc}
*/
public function isCandidate(Tokens $tokens)
public function isCandidate(Tokens $tokens): bool
{
return $tokens->isAllTokenKindsFound([T_STRING, T_CONSTANT_ENCAPSED_STRING]);
}

/**
* {@inheritdoc}
*/
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
{
$argumentsAnalyzer = new ArgumentsAnalyzer();

Expand Down Expand Up @@ -71,14 +73,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
}
}

abstract protected function fixFopenFlagToken(Tokens $tokens, $argumentStartIndex, $argumentEndIndex);
abstract protected function fixFopenFlagToken(Tokens $tokens, int $argumentStartIndex, int $argumentEndIndex): void;

/**
* @param string $mode
*
* @return bool
*/
protected function isValidModeString($mode)
protected function isValidModeString(string $mode): bool
{
$modeLength = \strlen($mode);
if ($modeLength < 1 || $modeLength > 13) { // 13 === length 'r+w+a+x+c+etb'
Expand Down
10 changes: 4 additions & 6 deletions src/AbstractFunctionReferenceFixer.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of PHP CS Fixer.
*
Expand All @@ -25,7 +27,7 @@ abstract class AbstractFunctionReferenceFixer extends AbstractFixer
/**
* {@inheritdoc}
*/
public function isRisky()
public function isRisky(): bool
{
return true;
}
Expand All @@ -34,13 +36,9 @@ public function isRisky()
* Looks up Tokens sequence for suitable candidates and delivers boundaries information,
* which can be supplied by other methods in this abstract class.
*
* @param string $functionNameToSearch
* @param int $start
* @param null|int $end
*
* @return null|int[] returns $functionName, $openParenthesis, $closeParenthesis packed into array
*/
protected function find($functionNameToSearch, Tokens $tokens, $start = 0, $end = null)
protected function find(string $functionNameToSearch, Tokens $tokens, int $start = 0, ?int $end = null): ?array
{
// make interface consistent with findSequence
$end = null === $end ? $tokens->count() : $end;
Expand Down
5 changes: 3 additions & 2 deletions src/AbstractLinesBeforeNamespaceFixer.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of PHP CS Fixer.
*
Expand Down Expand Up @@ -29,11 +31,10 @@ abstract class AbstractLinesBeforeNamespaceFixer extends AbstractFixer implement
/**
* Make sure # of line breaks prefixing namespace is within given range.
*
* @param int $index
* @param int $expectedMin min. # of line breaks
* @param int $expectedMax max. # of line breaks
*/
protected function fixLinesBeforeNamespace(Tokens $tokens, $index, $expectedMin, $expectedMax)
protected function fixLinesBeforeNamespace(Tokens $tokens, int $index, int $expectedMin, int $expectedMax): void
{
// Let's determine the total numbers of new lines before the namespace
// and the opening token
Expand Down

0 comments on commit 55158a6

Please sign in to comment.