From c388430ae3d37e7a37389e9a3bf1d49c69ff7941 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Thu, 31 May 2018 23:53:25 +0200 Subject: [PATCH] apply CS --- src/AbstractAlignFixerHelper.php | 4 +- src/AbstractDoctrineAnnotationFixer.php | 2 +- src/AbstractFixer.php | 2 +- src/AbstractProxyFixer.php | 2 +- src/Cache/Cache.php | 8 ++-- src/Cache/Directory.php | 2 +- src/Cache/Signature.php | 4 +- src/Config.php | 8 ++-- src/Console/Command/DescribeCommand.php | 10 ++--- src/Console/Command/FixCommand.php | 14 +++---- src/Console/Command/HelpCommand.php | 12 +++--- src/Console/Command/SelfUpdateCommand.php | 2 +- src/Console/ConfigurationResolver.php | 34 +++++++-------- src/Console/Output/ErrorOutput.php | 10 ++--- src/Console/Output/ProcessOutput.php | 4 +- src/Console/WarningsDetector.php | 2 +- src/DocBlock/Annotation.php | 4 +- src/DocBlock/DocBlock.php | 4 +- src/DocBlock/Tag.php | 2 +- src/DocBlock/TagComparator.php | 2 +- src/Doctrine/Annotation/Token.php | 4 +- src/Doctrine/Annotation/Tokens.php | 26 ++++++------ src/Fixer/Alias/BacktickToShellExecFixer.php | 2 +- src/Fixer/Alias/MbStrFunctionsFixer.php | 2 +- src/Fixer/Alias/PowToExponentiationFixer.php | 6 +-- src/Fixer/Alias/RandomApiMigrationFixer.php | 6 +-- src/Fixer/Alias/SetTypeToCastFixer.php | 4 +- src/Fixer/Basic/BracesFixer.php | 8 ++-- .../Basic/NonPrintableCharacterFixer.php | 2 +- src/Fixer/Basic/Psr0Fixer.php | 14 +++---- src/Fixer/Basic/Psr4Fixer.php | 2 +- .../CastNotation/NoShortBoolCastFixer.php | 2 +- .../ClassNotation/ClassDefinitionFixer.php | 4 +- .../ClassNotation/FinalInternalClassFixer.php | 4 +- .../ClassNotation/NoPhp4ConstructorFixer.php | 4 +- .../NoUnneededFinalMethodFixer.php | 4 +- .../OrderedClassElementsFixer.php | 10 ++--- .../ClassNotation/ProtectedToPrivateFixer.php | 2 +- .../SingleClassElementPerStatementFixer.php | 2 +- .../ClassNotation/VisibilityRequiredFixer.php | 4 +- src/Fixer/Comment/CommentToPhpdocFixer.php | 4 +- src/Fixer/Comment/HeaderCommentFixer.php | 4 +- src/Fixer/Comment/NoEmptyCommentFixer.php | 4 +- .../Comment/SingleLineCommentStyleFixer.php | 4 +- .../NoAlternativeSyntaxFixer.php | 4 +- .../ControlStructure/NoBreakCommentFixer.php | 6 +-- .../NoUnneededControlParenthesesFixer.php | 2 +- .../NoUnneededCurlyBracesFixer.php | 2 +- src/Fixer/ControlStructure/YodaStyleFixer.php | 14 +++---- .../DoctrineAnnotationBracesFixer.php | 2 +- .../DoctrineAnnotationIndentationFixer.php | 4 +- .../DoctrineAnnotationSpacesFixer.php | 2 +- .../Import/FullyQualifiedStrictTypesFixer.php | 4 +- src/Fixer/Import/NoUnusedImportsFixer.php | 4 +- src/Fixer/Import/OrderedImportsFixer.php | 20 ++++----- .../Import/SingleImportPerStatementFixer.php | 2 +- .../Import/SingleLineAfterImportsFixer.php | 2 +- .../ClassKeywordRemoveFixer.php | 14 +++---- .../CombineConsecutiveIssetsFixer.php | 4 +- .../CombineConsecutiveUnsetsFixer.php | 2 +- .../ErrorSuppressionFixer.php | 2 +- src/Fixer/LanguageConstruct/IsNullFixer.php | 2 +- .../NoLeadingNamespaceWhitespaceFixer.php | 2 +- .../Operator/BinaryOperatorSpacesFixer.php | 22 +++++----- src/Fixer/Operator/NewWithBracesFixer.php | 2 +- src/Fixer/PhpTag/FullOpeningTagFixer.php | 8 ++-- src/Fixer/PhpTag/NoClosingTagFixer.php | 2 +- src/Fixer/PhpTag/NoShortEchoTagFixer.php | 2 +- .../PhpUnit/PhpUnitDedicateAssertFixer.php | 6 +-- src/Fixer/PhpUnit/PhpUnitExpectationFixer.php | 2 +- .../PhpUnit/PhpUnitInternalClassFixer.php | 10 ++--- .../PhpUnit/PhpUnitTestAnnotationFixer.php | 8 ++-- .../PhpUnitTestCaseStaticMethodCallsFixer.php | 4 +- .../PhpUnitTestClassRequiresCoversFixer.php | 2 +- .../GeneralPhpdocAnnotationRemoveFixer.php | 2 +- .../PhpdocAddMissingParamAnnotationFixer.php | 6 +-- src/Fixer/Phpdoc/PhpdocAlignFixer.php | 20 ++++----- .../PhpdocAnnotationWithoutDotFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php | 4 +- .../Phpdoc/PhpdocNoUselessInheritdocFixer.php | 2 +- .../Phpdoc/PhpdocReturnSelfReferenceFixer.php | 14 +++---- src/Fixer/Phpdoc/PhpdocScalarFixer.php | 2 +- .../PhpdocSingleLineVarSpacingFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocTypesFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php | 4 +- .../Phpdoc/PhpdocVarWithoutNameFixer.php | 4 +- .../ReturnNotation/ReturnAssignmentFixer.php | 4 +- ...ltilineWhitespaceBeforeSemicolonsFixer.php | 4 +- .../SemicolonAfterInstructionFixer.php | 2 +- .../Semicolon/SpaceAfterSemicolonFixer.php | 2 +- src/Fixer/Strict/DeclareStrictTypesFixer.php | 4 +- src/Fixer/Strict/StrictParamFixer.php | 4 +- .../ExplicitStringVariableFixer.php | 4 +- .../Whitespace/ArrayIndentationFixer.php | 4 +- src/Fixer/Whitespace/LineEndingFixer.php | 2 +- .../MethodChainingIndentationFixer.php | 2 +- .../Whitespace/NoExtraBlankLinesFixer.php | 4 +- .../Whitespace/NoSpacesAroundOffsetFixer.php | 4 +- .../Whitespace/NoTrailingWhitespaceFixer.php | 2 +- .../NoWhitespaceInBlankLineFixer.php | 4 +- src/FixerConfiguration/AllowedValueSubset.php | 4 +- .../FixerConfigurationResolver.php | 4 +- .../FixerConfigurationResolverRootless.php | 2 +- src/FixerDefinition/FixerDefinition.php | 4 +- src/FixerDefinition/VersionSpecification.php | 4 +- src/FixerFactory.php | 10 ++--- src/Linter/TokenizerLinter.php | 2 +- src/Preg.php | 4 +- src/Report/CheckstyleReporter.php | 2 +- src/Report/JunitReporter.php | 8 ++-- src/Report/XmlReporter.php | 2 +- src/RuleSet.php | 4 +- src/Runner/FileFilterIterator.php | 2 +- src/Test/AccessibleObject.php | 6 +-- src/Tokenizer/AbstractTransformer.php | 2 +- src/Tokenizer/Analyzer/ArgumentsAnalyzer.php | 2 +- src/Tokenizer/Analyzer/CommentsAnalyzer.php | 2 +- src/Tokenizer/Analyzer/NamespacesAnalyzer.php | 6 +-- .../NamespacedStringTokenGenerator.php | 2 +- .../Resolver/TypeShortNameResolver.php | 2 +- src/Tokenizer/Token.php | 28 ++++++------- src/Tokenizer/Tokens.php | 42 +++++++++---------- src/Tokenizer/TokensAnalyzer.php | 8 ++-- .../WhitespacyCommentTransformer.php | 2 +- src/ToolInfo.php | 2 +- src/Utils.php | 4 +- src/WhitespacesFixerConfig.php | 4 +- src/WordMatcher.php | 2 +- tests/AutoReview/CommandTest.php | 6 +-- tests/AutoReview/FixerFactoryTest.php | 14 +++---- tests/AutoReview/FixerTest.php | 6 +-- tests/AutoReview/ProjectCodeTest.php | 12 +++--- tests/Console/Command/DescribeCommandTest.php | 2 +- tests/Console/ConfigurationResolverTest.php | 8 ++-- tests/Console/Output/ErrorOutputTest.php | 2 +- tests/Fixer/Basic/Psr0FixerTest.php | 2 +- tests/Fixer/Basic/Psr4FixerTest.php | 2 +- ...pdocAddMissingParamAnnotationFixerTest.php | 2 +- .../PhpdocAnnotationWithoutDotFixerTest.php | 8 ++-- .../Whitespace/IndentationTypeFixerTest.php | 2 +- tests/FixerFactoryTest.php | 10 ++--- tests/IntegrationTest.php | 2 +- tests/Linter/LinterTest.php | 2 +- tests/PregTest.php | 12 +++--- tests/RuleSetTest.php | 4 +- tests/Smoke/CiIntegrationTest.php | 2 +- tests/Test/AbstractFixerTestCase.php | 4 +- tests/Test/AbstractIntegrationCaseFactory.php | 16 +++---- tests/Test/AbstractIntegrationTestCase.php | 6 +-- tests/Test/AbstractTransformerTestCase.php | 6 +-- tests/Test/Assert/AssertTokensTrait.php | 2 +- tests/Test/IntegrationCase.php | 4 +- tests/Test/InternalIntegrationCaseFactory.php | 2 +- .../Analyzer/ArgumentsAnalyzerTest.php | 2 +- tests/Tokenizer/CTTest.php | 2 +- tests/Tokenizer/TokensAnalyzerTest.php | 2 +- tests/Tokenizer/TokensTest.php | 8 ++-- .../SquareBraceTransformerTest.php | 2 +- 158 files changed, 426 insertions(+), 426 deletions(-) diff --git a/src/AbstractAlignFixerHelper.php b/src/AbstractAlignFixerHelper.php index ca2b1cf0ddb..57fe143e781 100644 --- a/src/AbstractAlignFixerHelper.php +++ b/src/AbstractAlignFixerHelper.php @@ -47,7 +47,7 @@ public function fix(Tokens $tokens) // To handle that unwanted behavior we work on clone of Tokens collection and then override original collection with fixed collection. $tokensClone = clone $tokens; - $this->injectAlignmentPlaceholders($tokensClone, 0, count($tokens)); + $this->injectAlignmentPlaceholders($tokensClone, 0, \count($tokens)); $content = $this->replacePlaceholder($tokensClone); $tokens->setCode($content); @@ -96,7 +96,7 @@ protected function replacePlaceholder(Tokens $tokens) } foreach ($linesWithPlaceholder as $group) { - if (count($group) < 1) { + if (\count($group) < 1) { continue; } diff --git a/src/AbstractDoctrineAnnotationFixer.php b/src/AbstractDoctrineAnnotationFixer.php index 122f6ac126a..6f2d49e627b 100644 --- a/src/AbstractDoctrineAnnotationFixer.php +++ b/src/AbstractDoctrineAnnotationFixer.php @@ -79,7 +79,7 @@ protected function createConfigurationDefinition() ->setAllowedTypes(['array']) ->setAllowedValues([static function ($values) { foreach ($values as $value) { - if (!is_string($value)) { + if (!\is_string($value)) { return false; } } diff --git a/src/AbstractFixer.php b/src/AbstractFixer.php index 999e0efddca..44a07d83b1c 100644 --- a/src/AbstractFixer.php +++ b/src/AbstractFixer.php @@ -90,7 +90,7 @@ public function isRisky() public function getName() { $nameParts = explode('\\', static::class); - $name = substr(end($nameParts), 0, -strlen('Fixer')); + $name = substr(end($nameParts), 0, -\strlen('Fixer')); return Utils::camelCaseToUnderscore($name); } diff --git a/src/AbstractProxyFixer.php b/src/AbstractProxyFixer.php index 3a4566dbe7b..b17336120bc 100644 --- a/src/AbstractProxyFixer.php +++ b/src/AbstractProxyFixer.php @@ -70,7 +70,7 @@ public function isRisky() */ public function getPriority() { - if (count($this->proxyFixers) > 1) { + if (\count($this->proxyFixers) > 1) { throw new \LogicException('You need to override this method to provide the priority of combined fixers.'); } diff --git a/src/Cache/Cache.php b/src/Cache/Cache.php index 2e608ed8a26..23403bc9e9b 100644 --- a/src/Cache/Cache.php +++ b/src/Cache/Cache.php @@ -55,10 +55,10 @@ public function get($file) public function set($file, $hash) { - if (!is_int($hash)) { + if (!\is_int($hash)) { throw new \InvalidArgumentException(sprintf( 'Value needs to be an integer, got "%s".', - is_object($hash) ? get_class($hash) : gettype($hash) + \is_object($hash) ? \get_class($hash) : \gettype($hash) )); } @@ -103,7 +103,7 @@ public static function fromJson($json) if (null === $data && JSON_ERROR_NONE !== json_last_error()) { throw new \InvalidArgumentException(sprintf( 'Value needs to be a valid JSON string, got "%s", error: "%s".', - is_object($json) ? get_class($json) : gettype($json), + \is_object($json) ? \get_class($json) : \gettype($json), json_last_error_msg() )); } @@ -117,7 +117,7 @@ public static function fromJson($json) $missingKeys = array_diff_key(array_flip($requiredKeys), $data); - if (count($missingKeys)) { + if (\count($missingKeys)) { throw new \InvalidArgumentException(sprintf( 'JSON data is missing keys "%s"', implode('", "', $missingKeys) diff --git a/src/Cache/Directory.php b/src/Cache/Directory.php index d8277f86a7c..15aa74253f8 100644 --- a/src/Cache/Directory.php +++ b/src/Cache/Directory.php @@ -43,7 +43,7 @@ public function getRelativePathTo($file) return $file; } - return substr($file, strlen($this->directoryName) + 1); + return substr($file, \strlen($this->directoryName) + 1); } private function normalizePath($path) diff --git a/src/Cache/Signature.php b/src/Cache/Signature.php index b0313b6b9ea..2407f548e17 100644 --- a/src/Cache/Signature.php +++ b/src/Cache/Signature.php @@ -70,12 +70,12 @@ public function equals(SignatureInterface $signature) private static function utf8Encode(array $data) { - if (!function_exists('mb_detect_encoding')) { + if (!\function_exists('mb_detect_encoding')) { return $data; } array_walk_recursive($data, static function (&$item) { - if (is_string($item) && !mb_detect_encoding($item, 'utf-8', true)) { + if (\is_string($item) && !mb_detect_encoding($item, 'utf-8', true)) { $item = utf8_encode($item); } }); diff --git a/src/Config.php b/src/Config.php index 576a2f051ad..d5d7cc8d16a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -152,10 +152,10 @@ public function getUsingCache() */ public function registerCustomFixers($fixers) { - if (false === is_array($fixers) && false === $fixers instanceof \Traversable) { + if (false === \is_array($fixers) && false === $fixers instanceof \Traversable) { throw new \InvalidArgumentException(sprintf( 'Argument must be an array or a Traversable, got "%s".', - is_object($fixers) ? get_class($fixers) : gettype($fixers) + \is_object($fixers) ? \get_class($fixers) : \gettype($fixers) )); } @@ -181,10 +181,10 @@ public function setCacheFile($cacheFile) */ public function setFinder($finder) { - if (false === is_array($finder) && false === $finder instanceof \Traversable) { + if (false === \is_array($finder) && false === $finder instanceof \Traversable) { throw new \InvalidArgumentException(sprintf( 'Argument must be an array or a Traversable, got "%s".', - is_object($finder) ? get_class($finder) : gettype($finder) + \is_object($finder) ? \get_class($finder) : \gettype($finder) )); } diff --git a/src/Console/Command/DescribeCommand.php b/src/Console/Command/DescribeCommand.php index 958db24ee99..498113e8a7b 100644 --- a/src/Console/Command/DescribeCommand.php +++ b/src/Console/Command/DescribeCommand.php @@ -161,7 +161,7 @@ private function describeRule(OutputInterface $output, $name) $output->writeln(sprintf('Description of %s rule.', $name)); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { - $output->writeln(sprintf('Fixer class: %s.', get_class($fixer))); + $output->writeln(sprintf('Fixer class: %s.', \get_class($fixer))); } $output->writeln($description); @@ -184,7 +184,7 @@ private function describeRule(OutputInterface $output, $name) $configurationDefinition = $fixer->getConfigurationDefinition(); $options = $configurationDefinition->getOptions(); - $output->writeln(sprintf('Fixer is configurable using following option%s:', 1 === count($options) ? '' : 's')); + $output->writeln(sprintf('Fixer is configurable using following option%s:', 1 === \count($options) ? '' : 's')); foreach ($options as $option) { $line = '* '.OutputFormatter::escape($option->getName()).''; @@ -259,7 +259,7 @@ function ($type) { return true; }); - if (!count($codeSamples)) { + if (!\count($codeSamples)) { $output->writeln([ 'Fixing examples can not be demonstrated on the current PHP version.', '', @@ -313,7 +313,7 @@ function ($type) { */ private function describeSet(OutputInterface $output, $name) { - if (!in_array($name, $this->getSetNames(), true)) { + if (!\in_array($name, $this->getSetNames(), true)) { throw new DescribeNameNotFoundException($name, 'set'); } @@ -400,7 +400,7 @@ private function describeList(OutputInterface $output, $type) foreach ($describe as $list => $items) { $output->writeln(sprintf('Defined %s:', $list)); foreach ($items as $name => $item) { - $output->writeln(sprintf('* %s', is_string($name) ? $name : $item)); + $output->writeln(sprintf('* %s', \is_string($name) ? $name : $item)); } } } diff --git a/src/Console/Command/FixCommand.php b/src/Console/Command/FixCommand.php index 615ad42f804..91314a490a9 100644 --- a/src/Console/Command/FixCommand.php +++ b/src/Console/Command/FixCommand.php @@ -199,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $stdErr, $this->eventDispatcher, 'estimating' !== $progressType ? (new Terminal())->getWidth() : null, - count($finder) + \count($finder) ); } @@ -245,15 +245,15 @@ protected function execute(InputInterface $input, OutputInterface $output) if (null !== $stdErr) { $errorOutput = new ErrorOutput($stdErr); - if (count($invalidErrors) > 0) { + if (\count($invalidErrors) > 0) { $errorOutput->listErrors('linting before fixing', $invalidErrors); } - if (count($exceptionErrors) > 0) { + if (\count($exceptionErrors) > 0) { $errorOutput->listErrors('fixing', $exceptionErrors); } - if (count($lintErrors) > 0) { + if (\count($lintErrors) > 0) { $errorOutput->listErrors('linting after fixing', $lintErrors); } } @@ -262,9 +262,9 @@ protected function execute(InputInterface $input, OutputInterface $output) return $exitStatusCalculator->calculate( $resolver->isDryRun(), - count($changed) > 0, - count($invalidErrors) > 0, - count($exceptionErrors) > 0 + \count($changed) > 0, + \count($invalidErrors) > 0, + \count($exceptionErrors) > 0 ); } } diff --git a/src/Console/Command/HelpCommand.php b/src/Console/Command/HelpCommand.php index 3e4c6501775..c7e7a708731 100644 --- a/src/Console/Command/HelpCommand.php +++ b/src/Console/Command/HelpCommand.php @@ -284,7 +284,7 @@ public static function getHelpCopy() ), '%%%CI_INTEGRATION%%%' => implode("\n", array_map( static function ($line) { return ' $ '.$line; }, - array_slice(file(__DIR__.'/../../../dev-tools/ci-integration.sh', FILE_IGNORE_NEW_LINES), 3) + \array_slice(file(__DIR__.'/../../../dev-tools/ci-integration.sh', FILE_IGNORE_NEW_LINES), 3) )), '%%%FIXERS_DETAILS%%%' => self::getFixersHelp(), ]); @@ -297,7 +297,7 @@ static function ($line) { return ' $ '.$line; }, */ public static function toString($value) { - if (is_array($value)) { + if (\is_array($value)) { // Output modifications: // - remove new-lines // - combine multiple whitespaces @@ -362,7 +362,7 @@ public static function getDisplayableAllowedValues(FixerOptionInterface $option) ); }); - if (0 === count($allowed)) { + if (0 === \count($allowed)) { $allowed = null; } } @@ -468,7 +468,7 @@ static function (FixerInterface $a, FixerInterface $b) { return $sets; }; - $count = count($fixers) - 1; + $count = \count($fixers) - 1; foreach ($fixers as $i => $fixer) { $sets = $getSetsWithRule($fixer->getName()); @@ -511,7 +511,7 @@ static function (FixerInterface $a, FixerInterface $b) { if ($fixer instanceof ConfigurationDefinitionFixerInterface) { $configurationDefinition = $fixer->getConfigurationDefinition(); $configurationDefinitionOptions = $configurationDefinition->getOptions(); - if (count($configurationDefinitionOptions)) { + if (\count($configurationDefinitionOptions)) { $help .= " |\n | Configuration options:\n"; usort( @@ -601,7 +601,7 @@ private static function wordwrap($string, $width) $currentLine = 0; $lineLength = 0; foreach (explode(' ', $string) as $word) { - $wordLength = strlen(Preg::replace('~~', '', $word)); + $wordLength = \strlen(Preg::replace('~~', '', $word)); if (0 !== $lineLength) { ++$wordLength; // space before word } diff --git a/src/Console/Command/SelfUpdateCommand.php b/src/Console/Command/SelfUpdateCommand.php index 0becd316244..9ae53d3b10a 100644 --- a/src/Console/Command/SelfUpdateCommand.php +++ b/src/Console/Command/SelfUpdateCommand.php @@ -149,7 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } - $tempFilename = dirname($localFilename).'/'.basename($localFilename, '.phar').'-tmp.phar'; + $tempFilename = \dirname($localFilename).'/'.basename($localFilename, '.phar').'-tmp.phar'; $remoteFilename = $this->toolInfo->getPharDownloadUri($remoteTag); if (false === @copy($remoteFilename, $tempFilename)) { diff --git a/src/Console/ConfigurationResolver.php b/src/Console/ConfigurationResolver.php index 6bae34893b3..a95eb14189a 100644 --- a/src/Console/ConfigurationResolver.php +++ b/src/Console/ConfigurationResolver.php @@ -232,7 +232,7 @@ public function getConfig() // verify that the config has an instance of Config if (!$config instanceof ConfigInterface) { - throw new InvalidConfigurationException(sprintf('The config file: "%s" does not return a "PhpCsFixer\ConfigInterface" instance. Got: "%s".', $configFile, is_object($config) ? get_class($config) : gettype($config))); + throw new InvalidConfigurationException(sprintf('The config file: "%s" does not return a "PhpCsFixer\ConfigInterface" instance. Got: "%s".', $configFile, \is_object($config) ? \get_class($config) : \gettype($config))); } $this->config = $config; @@ -311,7 +311,7 @@ public function getDirectory() ? $path : $this->cwd.DIRECTORY_SEPARATOR.$path; - $this->directory = new Directory(dirname($absolutePath)); + $this->directory = new Directory(\dirname($absolutePath)); } return $this->directory; @@ -341,7 +341,7 @@ static function (FixerInterface $fixer) { ) ); - if (count($riskyFixers)) { + if (\count($riskyFixers)) { throw new InvalidConfigurationException(sprintf('The rules contain risky fixers (%s), but they are not allowed to run. Perhaps you forget to use --allow-risky option?', implode(', ', $riskyFixers))); } } @@ -373,7 +373,7 @@ public function getPath() $filesystem = new Filesystem(); $cwd = $this->cwd; - if (1 === count($this->options['path']) && '-' === $this->options['path'][0]) { + if (1 === \count($this->options['path']) && '-' === $this->options['path'][0]) { $this->path = $this->options['path']; } else { $this->path = array_map( @@ -419,13 +419,13 @@ public function getProgress() } $progressType = $this->getConfig()->getHideProgress() ? 'none' : $default; - } elseif (!in_array($progressType, $progressTypes, true)) { + } elseif (!\in_array($progressType, $progressTypes, true)) { throw new InvalidConfigurationException(sprintf( 'The progress type "%s" is not defined, supported are "%s".', $progressType, implode('", "', $progressTypes) )); - } elseif (in_array($progressType, ['estimating', 'estimating-max', 'run-in'], true)) { + } elseif (\in_array($progressType, ['estimating', 'estimating-max', 'run-in'], true)) { $message = 'Passing `estimating`, `estimating-max` or `run-in` is deprecated and will not be supported in 3.0, use `none` or `dots` instead.'; if (getenv('PHP_CS_FIXER_FUTURE_MODE')) { @@ -574,9 +574,9 @@ private function computeConfigFiles() $path = $this->getPath(); - if ($this->isStdIn() || 0 === count($path)) { + if ($this->isStdIn() || 0 === \count($path)) { $configDir = $this->cwd; - } elseif (1 < count($path)) { + } elseif (1 < \count($path)) { throw new InvalidConfigurationException('For multiple paths config parameter is required.'); } elseif (is_file($path[0]) && $dirName = pathinfo($path[0], PATHINFO_DIRNAME)) { $configDir = $dirName; @@ -645,7 +645,7 @@ private function getRuleSet() private function isStdIn() { if (null === $this->isStdIn) { - $this->isStdIn = 1 === count($this->options['path']) && '-' === $this->options['path'][0]; + $this->isStdIn = 1 === \count($this->options['path']) && '-' === $this->options['path'][0]; } return $this->isStdIn; @@ -658,7 +658,7 @@ private function isStdIn() */ private function iterableToTraversable($iterable) { - return is_array($iterable) ? new \ArrayIterator($iterable) : $iterable; + return \is_array($iterable) ? new \ArrayIterator($iterable) : $iterable; } /** @@ -718,7 +718,7 @@ private function validateRules(array $rules) */ $ruleSet = []; foreach ($rules as $key => $value) { - if (is_int($key)) { + if (\is_int($key)) { throw new InvalidConfigurationException(sprintf('Missing value for "%s" rule/set.', $value)); } @@ -741,7 +741,7 @@ private function validateRules(array $rules) $availableFixers ); - if (count($unknownFixers)) { + if (\count($unknownFixers)) { $matcher = new WordMatcher($availableFixers); $message = 'The rules contain unknown fixers: '; @@ -789,7 +789,7 @@ private function resolveFinder() $modes = [self::PATH_MODE_OVERRIDE, self::PATH_MODE_INTERSECTION]; - if (!in_array( + if (!\in_array( $this->options['path-mode'], $modes, true @@ -810,7 +810,7 @@ static function ($path) { $this->getPath() )); - if (!count($paths)) { + if (!\count($paths)) { if ($isIntersectionPathMode) { return new \ArrayIterator([]); } @@ -851,7 +851,7 @@ static function ($path) { static function (\SplFileInfo $current) use ($pathsByType) { $currentRealPath = $current->getRealPath(); - if (in_array($currentRealPath, $pathsByType['file'], true)) { + if (\in_array($currentRealPath, $pathsByType['file'], true)) { return true; } @@ -901,11 +901,11 @@ private function setOption($name, $value) private function resolveOptionBooleanValue($optionName) { $value = $this->options[$optionName]; - if (is_bool($value)) { + if (\is_bool($value)) { return $value; } - if (!is_string($value)) { + if (!\is_string($value)) { throw new InvalidConfigurationException(sprintf('Expected boolean or string value for option "%s".', $optionName)); } diff --git a/src/Console/Output/ErrorOutput.php b/src/Console/Output/ErrorOutput.php index 587663359c1..ffedf13f7ab 100644 --- a/src/Console/Output/ErrorOutput.php +++ b/src/Console/Output/ErrorOutput.php @@ -61,14 +61,14 @@ public function listErrors($process, array $errors) continue; } - $class = sprintf('[%s]', get_class($e)); + $class = sprintf('[%s]', \get_class($e)); $message = $e->getMessage(); $code = $e->getCode(); if (0 !== $code) { $message .= " (${code})"; } - $length = max(strlen($class), strlen($message)); + $length = max(\strlen($class), \strlen($message)); $lines = [ '', $class, @@ -79,8 +79,8 @@ public function listErrors($process, array $errors) $this->output->writeln(''); foreach ($lines as $line) { - if (strlen($line) < $length) { - $line .= str_repeat(' ', $length - strlen($line)); + if (\strlen($line) < $length) { + $line .= str_repeat(' ', $length - \strlen($line)); } $this->output->writeln(sprintf(' %s ', $this->prepareOutput($line))); @@ -100,7 +100,7 @@ public function listErrors($process, array $errors) } } - if (Error::TYPE_LINT === $error->getType() && 0 < count($error->getAppliedFixers())) { + if (Error::TYPE_LINT === $error->getType() && 0 < \count($error->getAppliedFixers())) { $this->output->writeln(''); $this->output->writeln(sprintf(' Applied fixers: %s', implode(', ', $error->getAppliedFixers()))); diff --git a/src/Console/Output/ProcessOutput.php b/src/Console/Output/ProcessOutput.php index 37f5f03888c..b6c0adc2edb 100644 --- a/src/Console/Output/ProcessOutput.php +++ b/src/Console/Output/ProcessOutput.php @@ -84,7 +84,7 @@ public function __construct(OutputInterface $output, EventDispatcherInterface $d // max number of characters per line // - total length x 2 (e.g. " 1 / 123" => 6 digits and padding spaces) // - 11 (extra spaces, parentheses and percentage characters, e.g. " x / x (100%)") - $this->symbolsPerLine = max(1, ($width ?: 80) - strlen((string) $this->files) * 2 - 11); + $this->symbolsPerLine = max(1, ($width ?: 80) - \strlen((string) $this->files) * 2 - 11); } } @@ -115,7 +115,7 @@ public function onFixerFileProcessed(FixerFileProcessedEvent $event) if (0 === $symbolsOnCurrentLine || $isLast) { $this->output->write(sprintf( - '%s %'.strlen((string) $this->files).'d / %d (%3d%%)', + '%s %'.\strlen((string) $this->files).'d / %d (%3d%%)', $isLast && 0 !== $symbolsOnCurrentLine ? str_repeat(' ', $this->symbolsPerLine - $symbolsOnCurrentLine) : '', $this->processedFiles, $this->files, diff --git a/src/Console/WarningsDetector.php b/src/Console/WarningsDetector.php index c5e1c573ea0..3f5d130d91d 100644 --- a/src/Console/WarningsDetector.php +++ b/src/Console/WarningsDetector.php @@ -62,7 +62,7 @@ public function detectOldVendor() */ public function getWarnings() { - if (!count($this->warnings)) { + if (!\count($this->warnings)) { return []; } diff --git a/src/DocBlock/Annotation.php b/src/DocBlock/Annotation.php index f43f8a61af0..6ee09298c4e 100644 --- a/src/DocBlock/Annotation.php +++ b/src/DocBlock/Annotation.php @@ -205,7 +205,7 @@ public function getTypes() ); $this->types[] = $matches['type']; - $content = substr($content, strlen($matches['type']) + 1); + $content = substr($content, \strlen($matches['type']) + 1); } } @@ -250,7 +250,7 @@ public function getContent() public function supportTypes() { - return in_array($this->getTag()->getName(), self::$tags, true); + return \in_array($this->getTag()->getName(), self::$tags, true); } /** diff --git a/src/DocBlock/DocBlock.php b/src/DocBlock/DocBlock.php index 808c72d918c..b6c5f149454 100644 --- a/src/DocBlock/DocBlock.php +++ b/src/DocBlock/DocBlock.php @@ -92,12 +92,12 @@ public function getAnnotations() { if (null === $this->annotations) { $this->annotations = []; - $total = count($this->lines); + $total = \count($this->lines); for ($index = 0; $index < $total; ++$index) { if ($this->lines[$index]->containsATag()) { // get all the lines that make up the annotation - $lines = array_slice($this->lines, $index, $this->findAnnotationLength($index), true); + $lines = \array_slice($this->lines, $index, $this->findAnnotationLength($index), true); $annotation = new Annotation($lines); // move the index to the end of the annotation to avoid // checking it again because we know the lines inside the diff --git a/src/DocBlock/Tag.php b/src/DocBlock/Tag.php index dc8087d31f0..625ec42506d 100644 --- a/src/DocBlock/Tag.php +++ b/src/DocBlock/Tag.php @@ -108,6 +108,6 @@ public function setName($name) */ public function valid() { - return in_array($this->getName(), self::$tags, true); + return \in_array($this->getName(), self::$tags, true); } } diff --git a/src/DocBlock/TagComparator.php b/src/DocBlock/TagComparator.php index 96ede80ab45..dc8f32d0f28 100644 --- a/src/DocBlock/TagComparator.php +++ b/src/DocBlock/TagComparator.php @@ -50,7 +50,7 @@ public static function shouldBeTogether(Tag $first, Tag $second) } foreach (self::$groups as $group) { - if (in_array($firstName, $group, true) && in_array($secondName, $group, true)) { + if (\in_array($firstName, $group, true) && \in_array($secondName, $group, true)) { return true; } } diff --git a/src/Doctrine/Annotation/Token.php b/src/Doctrine/Annotation/Token.php index 931646af186..890b5e48db6 100644 --- a/src/Doctrine/Annotation/Token.php +++ b/src/Doctrine/Annotation/Token.php @@ -82,11 +82,11 @@ public function setContent($content) */ public function isType($types) { - if (!is_array($types)) { + if (!\is_array($types)) { $types = [$types]; } - return in_array($this->getType(), $types, true); + return \in_array($this->getType(), $types, true); } /** diff --git a/src/Doctrine/Annotation/Tokens.php b/src/Doctrine/Annotation/Tokens.php index 59da4bbe0d8..640b4000e0c 100644 --- a/src/Doctrine/Annotation/Tokens.php +++ b/src/Doctrine/Annotation/Tokens.php @@ -62,14 +62,14 @@ public static function createFromDocComment(PhpToken $input, array $ignoredTags } if (1 === $index) { - if (DocLexer::T_IDENTIFIER !== $token['type'] || in_array($token['value'], $ignoredTags, true)) { + if (DocLexer::T_IDENTIFIER !== $token['type'] || \in_array($token['value'], $ignoredTags, true)) { break; } $nbScannedTokensToUse = 2; } - if ($index >= 2 && 0 === $nbScopes && !in_array($token['type'], [DocLexer::T_NONE, DocLexer::T_OPEN_PARENTHESIS], true)) { + if ($index >= 2 && 0 === $nbScopes && !\in_array($token['type'], [DocLexer::T_NONE, DocLexer::T_OPEN_PARENTHESIS], true)) { break; } @@ -79,7 +79,7 @@ public static function createFromDocComment(PhpToken $input, array $ignoredTags ++$nbScopes; } elseif (DocLexer::T_CLOSE_PARENTHESIS === $token['type']) { if (0 === --$nbScopes) { - $nbScannedTokensToUse = count($scannedTokens); + $nbScannedTokensToUse = \count($scannedTokens); break; } @@ -99,7 +99,7 @@ public static function createFromDocComment(PhpToken $input, array $ignoredTags } $lastTokenEndIndex = 0; - foreach (array_slice($scannedTokens, 0, $nbScannedTokensToUse) as $token) { + foreach (\array_slice($scannedTokens, 0, $nbScannedTokensToUse) as $token) { if (DocLexer::T_STRING === $token['type']) { $token['value'] = '"'.str_replace('"', '""', $token['value']).'"'; } @@ -114,16 +114,16 @@ public static function createFromDocComment(PhpToken $input, array $ignoredTags } $tokens[] = new Token($token['type'], $token['value']); - $lastTokenEndIndex = $token['position'] + strlen($token['value']); + $lastTokenEndIndex = $token['position'] + \strlen($token['value']); } - $currentPosition = $ignoredTextPosition = $nextAtPosition + $token['position'] + strlen($token['value']); + $currentPosition = $ignoredTextPosition = $nextAtPosition + $token['position'] + \strlen($token['value']); } else { $currentPosition = $nextAtPosition + 1; } } - if ($ignoredTextPosition < strlen($content)) { + if ($ignoredTextPosition < \strlen($content)) { $tokens[] = new Token(DocLexer::T_NONE, substr($content, $ignoredTextPosition)); } @@ -206,7 +206,7 @@ public function getAnnotationEnd($index) if (null !== $currentIndex) { $level = 0; - for ($max = count($this); $currentIndex < $max; ++$currentIndex) { + for ($max = \count($this); $currentIndex < $max; ++$currentIndex) { if ($this[$currentIndex]->isType(DocLexer::T_OPEN_PARENTHESIS)) { ++$level; } elseif ($this[$currentIndex]->isType(DocLexer::T_CLOSE_PARENTHESIS)) { @@ -234,7 +234,7 @@ public function getAnnotationEnd($index) public function getArrayEnd($index) { $level = 1; - for (++$index, $max = count($this); $index < $max; ++$index) { + for (++$index, $max = \count($this); $index < $max; ++$index) { if ($this[$index]->isType(DocLexer::T_OPEN_CURLY_BRACES)) { ++$level; } elseif ($this[$index]->isType($index, DocLexer::T_CLOSE_CURLY_BRACES)) { @@ -289,9 +289,9 @@ public function insertAt($index, Token $token) public function offsetSet($index, $token) { if (!$token instanceof Token) { - $type = gettype($token); + $type = \gettype($token); if ('object' === $type) { - $type = get_class($token); + $type = \get_class($token); } throw new \InvalidArgumentException(sprintf( @@ -301,7 +301,7 @@ public function offsetSet($index, $token) } if (null === $index) { - $index = count($this); + $index = \count($this); $this->setSize($this->getSize() + 1); } @@ -319,7 +319,7 @@ public function offsetUnset($index) throw new \OutOfBoundsException(sprintf('Index %s is invalid or does not exist.', $index)); } - $max = count($this) - 1; + $max = \count($this) - 1; while ($index < $max) { $this[$index] = $this[$index + 1]; ++$index; diff --git a/src/Fixer/Alias/BacktickToShellExecFixer.php b/src/Fixer/Alias/BacktickToShellExecFixer.php index 371d84348a7..08ffe4d7c66 100644 --- a/src/Fixer/Alias/BacktickToShellExecFixer.php +++ b/src/Fixer/Alias/BacktickToShellExecFixer.php @@ -108,7 +108,7 @@ private function fixBackticks(Tokens $tokens, array $backtickTokens) // Double-quoted strings are parsed differently if they contain // variables or not, so we need to build the new token array accordingly - $count = count($backtickTokens); + $count = \count($backtickTokens); $newTokens = [ new Token([T_STRING, 'shell_exec']), diff --git a/src/Fixer/Alias/MbStrFunctionsFixer.php b/src/Fixer/Alias/MbStrFunctionsFixer.php index e00f8fab65d..edf5e9cdfd0 100644 --- a/src/Fixer/Alias/MbStrFunctionsFixer.php +++ b/src/Fixer/Alias/MbStrFunctionsFixer.php @@ -98,7 +98,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) list($functionName, $openParenthesis, $closeParenthesis) = $boundaries; $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $closeParenthesis); - if (!in_array($count, $functionReplacement['argumentCount'], true)) { + if (!\in_array($count, $functionReplacement['argumentCount'], true)) { continue 2; } diff --git a/src/Fixer/Alias/PowToExponentiationFixer.php b/src/Fixer/Alias/PowToExponentiationFixer.php index 500eecce6f2..8377f76325f 100644 --- a/src/Fixer/Alias/PowToExponentiationFixer.php +++ b/src/Fixer/Alias/PowToExponentiationFixer.php @@ -69,7 +69,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $argumentsAnalyzer = new ArgumentsAnalyzer(); $numberOfTokensAdded = 0; - $previousCloseParenthesisIndex = count($tokens); + $previousCloseParenthesisIndex = \count($tokens); foreach (array_reverse($candidates) as $candidate) { // if in the previous iteration(s) tokens were added to the collection and this is done within the tokens // indexes of the current candidate than the index of the close ')' of the candidate has moved and so @@ -83,7 +83,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $arguments = $argumentsAnalyzer->getArguments($tokens, $candidate[1], $candidate[2]); - if (2 !== count($arguments)) { + if (2 !== \count($arguments)) { continue; } @@ -107,7 +107,7 @@ private function findPowCalls(Tokens $tokens) $candidates = []; // Minimal candidate to fix is seven tokens: pow(x,x); - $end = count($tokens) - 6; + $end = \count($tokens) - 6; // First possible location is after the open token: 1 for ($i = 1; $i < $end; ++$i) { diff --git a/src/Fixer/Alias/RandomApiMigrationFixer.php b/src/Fixer/Alias/RandomApiMigrationFixer.php index 6cff11af002..30b451b31dc 100644 --- a/src/Fixer/Alias/RandomApiMigrationFixer.php +++ b/src/Fixer/Alias/RandomApiMigrationFixer.php @@ -103,7 +103,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) list($functionName, $openParenthesis, $closeParenthesis) = $boundaries; $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $closeParenthesis); - if (!in_array($count, $functionReplacement['argumentCount'], true)) { + if (!\in_array($count, $functionReplacement['argumentCount'], true)) { continue 2; } @@ -145,11 +145,11 @@ protected function createConfigurationDefinition() )); } - if (!is_string($replacement)) { + if (!\is_string($replacement)) { throw new InvalidOptionsException(sprintf( 'Replacement for function "%s" must be a string, "%s" given.', $functionName, - is_object($replacement) ? get_class($replacement) : gettype($replacement) + \is_object($replacement) ? \get_class($replacement) : \gettype($replacement) )); } } diff --git a/src/Fixer/Alias/SetTypeToCastFixer.php b/src/Fixer/Alias/SetTypeToCastFixer.php index a02f78a7964..3afe9d4f1f8 100644 --- a/src/Fixer/Alias/SetTypeToCastFixer.php +++ b/src/Fixer/Alias/SetTypeToCastFixer.php @@ -77,7 +77,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $functionNameIndex = $candidate[0]; $arguments = $argumentsAnalyzer->getArguments($tokens, $candidate[1], $candidate[2]); - if (2 !== count($arguments)) { + if (2 !== \count($arguments)) { continue; // function must be overridden or used incorrectly } @@ -156,7 +156,7 @@ private function findSettypeCalls(Tokens $tokens) { $candidates = []; - $end = count($tokens); + $end = \count($tokens); for ($i = 1; $i < $end; ++$i) { $candidate = $this->find('settype', $tokens, $i, $end); if (null === $candidate) { diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index a3d51126339..5c45c2712cc 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -235,7 +235,7 @@ private function fixControlContinuationBraces(Tokens $tokens) { $controlContinuationTokens = $this->getControlContinuationTokens(); - for ($index = count($tokens) - 1; 0 <= $index; --$index) { + for ($index = \count($tokens) - 1; 0 <= $index; --$index) { $token = $tokens[$index]; if (!$token->isGivenKind($controlContinuationTokens)) { @@ -261,7 +261,7 @@ private function fixControlContinuationBraces(Tokens $tokens) private function fixDoWhile(Tokens $tokens) { - for ($index = count($tokens) - 1; 0 <= $index; --$index) { + for ($index = \count($tokens) - 1; 0 <= $index; --$index) { $token = $tokens[$index]; if (!$token->isGivenKind(T_DO)) { @@ -295,7 +295,7 @@ static function ($item) { ); $tokensAnalyzer = new TokensAnalyzer($tokens); - for ($index = 0, $limit = count($tokens); $index < $limit; ++$index) { + for ($index = 0, $limit = \count($tokens); $index < $limit; ++$index) { $token = $tokens[$index]; // if token is not a structure element - continue @@ -582,7 +582,7 @@ static function ($item) { } // reset loop limit due to collection change - $limit = count($tokens); + $limit = \count($tokens); } } diff --git a/src/Fixer/Basic/NonPrintableCharacterFixer.php b/src/Fixer/Basic/NonPrintableCharacterFixer.php index 138fe3c09b3..8d2a34ad8dc 100644 --- a/src/Fixer/Basic/NonPrintableCharacterFixer.php +++ b/src/Fixer/Basic/NonPrintableCharacterFixer.php @@ -93,7 +93,7 @@ public function isRisky() */ public function isCandidate(Tokens $tokens) { - return count($tokens) > 1 && $tokens->isAnyTokenKindsFound(self::$tokens); + return \count($tokens) > 1 && $tokens->isAnyTokenKindsFound(self::$tokens); } /** diff --git a/src/Fixer/Basic/Psr0Fixer.php b/src/Fixer/Basic/Psr0Fixer.php index 63bb7d8e3a7..383aa96f4ad 100644 --- a/src/Fixer/Basic/Psr0Fixer.php +++ b/src/Fixer/Basic/Psr0Fixer.php @@ -102,25 +102,25 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) if (false !== $namespace) { $normNamespace = str_replace('\\', '/', $namespace); $path = str_replace('\\', '/', $file->getRealPath()); - $dir = dirname($path); + $dir = \dirname($path); if ('' !== $this->configuration['dir']) { - $dir = substr($dir, strlen(realpath($this->configuration['dir'])) + 1); + $dir = substr($dir, \strlen(realpath($this->configuration['dir'])) + 1); if (false === $dir) { $dir = ''; } - if (strlen($normNamespace) > strlen($dir)) { + if (\strlen($normNamespace) > \strlen($dir)) { if ('' !== $dir) { - $normNamespace = substr($normNamespace, -strlen($dir)); + $normNamespace = substr($normNamespace, -\strlen($dir)); } else { $normNamespace = ''; } } } - $dir = substr($dir, -strlen($normNamespace)); + $dir = substr($dir, -\strlen($normNamespace)); if (false === $dir) { $dir = ''; } @@ -135,7 +135,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) for ($i = $namespaceIndex; $i <= $namespaceEndIndex; ++$i) { $tokens->clearAt($i); } - $namespace = substr($namespace, 0, -strlen($dir)).str_replace('/', '\\', $dir); + $namespace = substr($namespace, 0, -\strlen($dir)).str_replace('/', '\\', $dir); $newNamespace = Tokens::fromCode('clearRange(0, 2); @@ -146,7 +146,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } else { $normClass = str_replace('_', '/', $classyName); $path = str_replace('\\', '/', $file->getRealPath()); - $filename = substr($path, -strlen($normClass) - 4, -4); + $filename = substr($path, -\strlen($normClass) - 4, -4); if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) { $tokens[$classyIndex] = new Token([T_STRING, str_replace('/', '_', $filename)]); diff --git a/src/Fixer/Basic/Psr4Fixer.php b/src/Fixer/Basic/Psr4Fixer.php index 8c49065f803..a828aee4bfc 100644 --- a/src/Fixer/Basic/Psr4Fixer.php +++ b/src/Fixer/Basic/Psr4Fixer.php @@ -90,7 +90,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } } else { $normClass = str_replace('_', '/', $classyName); - $filename = substr(str_replace('\\', '/', $file->getRealPath()), -strlen($normClass) - 4, -4); + $filename = substr(str_replace('\\', '/', $file->getRealPath()), -\strlen($normClass) - 4, -4); if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) { $tokens[$classyIndex] = new Token([T_STRING, str_replace('/', '_', $filename)]); diff --git a/src/Fixer/CastNotation/NoShortBoolCastFixer.php b/src/Fixer/CastNotation/NoShortBoolCastFixer.php index 2caae37fff6..495a17aa95f 100644 --- a/src/Fixer/CastNotation/NoShortBoolCastFixer.php +++ b/src/Fixer/CastNotation/NoShortBoolCastFixer.php @@ -56,7 +56,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - for ($index = count($tokens) - 1; $index > 1; --$index) { + for ($index = \count($tokens) - 1; $index > 1; --$index) { if ($tokens[$index]->equals('!')) { $index = $this->fixShortCast($tokens, $index); } diff --git a/src/Fixer/ClassNotation/ClassDefinitionFixer.php b/src/Fixer/ClassNotation/ClassDefinitionFixer.php index e02c0676d95..e0932583dc3 100644 --- a/src/Fixer/ClassNotation/ClassDefinitionFixer.php +++ b/src/Fixer/ClassNotation/ClassDefinitionFixer.php @@ -301,11 +301,11 @@ private function getClassyDefinitionInfo(Tokens $tokens, $classyIndex) if (!$tokens[$classyIndex]->isGivenKind(T_TRAIT)) { $extends = $tokens->findGivenKind(T_EXTENDS, $classyIndex, $openIndex); - $extends = count($extends) ? $this->getClassyInheritanceInfo($tokens, key($extends), 'numberOfExtends') : false; + $extends = \count($extends) ? $this->getClassyInheritanceInfo($tokens, key($extends), 'numberOfExtends') : false; if (!$tokens[$classyIndex]->isGivenKind(T_INTERFACE)) { $implements = $tokens->findGivenKind(T_IMPLEMENTS, $classyIndex, $openIndex); - $implements = count($implements) ? $this->getClassyInheritanceInfo($tokens, key($implements), 'numberOfImplements') : false; + $implements = \count($implements) ? $this->getClassyInheritanceInfo($tokens, key($implements), 'numberOfImplements') : false; $tokensAnalyzer = new TokensAnalyzer($tokens); $anonymousClass = $tokensAnalyzer->isAnonymousClass($classyIndex); } diff --git a/src/Fixer/ClassNotation/FinalInternalClassFixer.php b/src/Fixer/ClassNotation/FinalInternalClassFixer.php index 94949181c47..c229dddb4d1 100644 --- a/src/Fixer/ClassNotation/FinalInternalClassFixer.php +++ b/src/Fixer/ClassNotation/FinalInternalClassFixer.php @@ -42,7 +42,7 @@ public function configure(array $configuration = null) $this->configuration['annotation-black-list'] ); - if (count($intersect)) { + if (\count($intersect)) { throw new InvalidFixerConfigurationException($this->getName(), sprintf('Annotation cannot be used in both the white- and black list, got duplicates: "%s".', implode('", "', array_keys($intersect)))); } } @@ -112,7 +112,7 @@ protected function createConfigurationDefinition() { $annotationsAsserts = [static function (array $values) { foreach ($values as $value) { - if (!is_string($value) || '' === $value) { + if (!\is_string($value) || '' === $value) { return false; } } diff --git a/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php b/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php index fe34d351f7c..b38d232dae1 100644 --- a/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php +++ b/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php @@ -78,7 +78,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { $tokensAnalyzer = new TokensAnalyzer($tokens); $classes = array_keys($tokens->findGivenKind(T_CLASS)); - $numClasses = count($classes); + $numClasses = \count($classes); for ($i = 0; $i < $numClasses; ++$i) { $index = $classes[$i]; @@ -310,7 +310,7 @@ private function getWrapperMethodSequence(Tokens $tokens, $method, $startIndex, } // append a comma if it's not the first variable - if (count($seq) > 5) { + if (\count($seq) > 5) { $seq[] = ','; } diff --git a/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php b/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php index 9e5db292d16..fff2adddd53 100644 --- a/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php +++ b/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php @@ -63,7 +63,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - $tokensCount = count($tokens); + $tokensCount = \count($tokens); for ($index = 0; $index < $tokensCount; ++$index) { if (!$tokens[$index]->isGivenKind(T_CLASS)) { continue; @@ -84,7 +84,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) */ private function fixClass(Tokens $tokens, $classOpenIndex, $classIsFinal) { - $tokensCount = count($tokens); + $tokensCount = \count($tokens); for ($index = $classOpenIndex + 1; $index < $tokensCount; ++$index) { // Class end if ($tokens[$index]->equals('}')) { diff --git a/src/Fixer/ClassNotation/OrderedClassElementsFixer.php b/src/Fixer/ClassNotation/OrderedClassElementsFixer.php index 04e28a3c60d..b742a31826c 100644 --- a/src/Fixer/ClassNotation/OrderedClassElementsFixer.php +++ b/src/Fixer/ClassNotation/OrderedClassElementsFixer.php @@ -123,7 +123,7 @@ public function configure(array $configuration = null) $this->typePosition[$type] = null; } - $lastPosition = count($this->configuration['order']); + $lastPosition = \count($this->configuration['order']); foreach ($this->typePosition as &$pos) { if (null === $pos) { $pos = $lastPosition; @@ -236,7 +236,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $sorted = $this->sortElements($elements); - $endIndex = $elements[count($elements) - 1]['end']; + $endIndex = $elements[\count($elements) - 1]['end']; if ($sorted !== $elements) { $this->sortTokens($tokens, $i, $endIndex, $sorted); @@ -324,7 +324,7 @@ private function getElements(Tokens $tokens, $startIndex) } $type = $this->detectElementType($tokens, $i); - if (is_array($type)) { + if (\is_array($type)) { $element['type'] = $type[0]; $element['name'] = $type[1]; } else { @@ -333,7 +333,7 @@ private function getElements(Tokens $tokens, $startIndex) if ('property' === $element['type']) { $element['name'] = $tokens[$i]->getContent(); - } elseif (in_array($element['type'], ['use_trait', 'constant', 'method', 'magic'], true)) { + } elseif (\in_array($element['type'], ['use_trait', 'constant', 'method', 'magic'], true)) { $element['name'] = $tokens[$tokens->getNextMeaningfulToken($i)]->getContent(); } @@ -448,7 +448,7 @@ private function sortElements(array $elements) $type = 'method'; } - if (in_array($type, ['constant', 'property', 'method'], true)) { + if (\in_array($type, ['constant', 'property', 'method'], true)) { $type .= '_'.$element['visibility']; if ($element['static']) { $type .= '_static'; diff --git a/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php b/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php index 0e6fff3f554..b4d89da6c1f 100644 --- a/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php +++ b/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php @@ -68,7 +68,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - $end = count($tokens) - 3; // min. number of tokens to form a class candidate to fix + $end = \count($tokens) - 3; // min. number of tokens to form a class candidate to fix for ($index = 0; $index < $end; ++$index) { if (!$tokens[$index]->isGivenKind(T_CLASS)) { continue; diff --git a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php index 95a9e2f6e1a..65b5f67f909 100644 --- a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php +++ b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php @@ -83,7 +83,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $elements = array_reverse($analyzer->getClassyElements(), true); foreach ($elements as $index => $element) { - if (!in_array($element['type'], $this->configuration['elements'], true)) { + if (!\in_array($element['type'], $this->configuration['elements'], true)) { continue; // not in configuration } diff --git a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php index d8521fd82e2..794ed2d8d18 100644 --- a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php +++ b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php @@ -87,7 +87,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $elements = $tokensAnalyzer->getClassyElements(); foreach (array_reverse($elements, true) as $index => $element) { - if (!in_array($element['type'], $this->configuration['elements'], true)) { + if (!\in_array($element['type'], $this->configuration['elements'], true)) { continue; } @@ -111,7 +111,7 @@ protected function createConfigurationDefinition() ->setAllowedTypes(['array']) ->setAllowedValues([new AllowedValueSubset(['property', 'method', 'const'])]) ->setNormalizer(static function (Options $options, $value) { - if (PHP_VERSION_ID < 70100 && in_array('const', $value, true)) { + if (PHP_VERSION_ID < 70100 && \in_array('const', $value, true)) { throw new InvalidOptionsForEnvException('"const" option can only be enabled with PHP 7.1+.'); } diff --git a/src/Fixer/Comment/CommentToPhpdocFixer.php b/src/Fixer/Comment/CommentToPhpdocFixer.php index 3417aeea0fc..949679a46a4 100644 --- a/src/Fixer/Comment/CommentToPhpdocFixer.php +++ b/src/Fixer/Comment/CommentToPhpdocFixer.php @@ -72,7 +72,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { $commentsAnalyzer = new CommentsAnalyzer(); - for ($index = 0, $limit = count($tokens); $index < $limit; ++$index) { + for ($index = 0, $limit = \count($tokens); $index < $limit; ++$index) { $token = $tokens[$index]; if (!$token->isGivenKind(T_COMMENT)) { @@ -120,7 +120,7 @@ function ($carry, $index) use ($tokens) { */ private function fixComment(Tokens $tokens, $indices) { - if (1 === count($indices)) { + if (1 === \count($indices)) { $this->fixCommentSingleLine($tokens, reset($indices)); } else { $this->fixCommentMultiLine($tokens, $indices); diff --git a/src/Fixer/Comment/HeaderCommentFixer.php b/src/Fixer/Comment/HeaderCommentFixer.php index dbf56a7460d..1711ac9c88d 100644 --- a/src/Fixer/Comment/HeaderCommentFixer.php +++ b/src/Fixer/Comment/HeaderCommentFixer.php @@ -272,11 +272,11 @@ private function fixWhiteSpaceAroundHeader(Tokens $tokens, $headerIndex) // fix lines after header comment $expectedLineCount = 'both' === $this->configuration['separate'] || 'bottom' === $this->configuration['separate'] ? 2 : 1; - if ($headerIndex === count($tokens) - 1) { + if ($headerIndex === \count($tokens) - 1) { $tokens->insertAt($headerIndex + 1, new Token([T_WHITESPACE, str_repeat($lineEnding, $expectedLineCount)])); } else { $afterCommentIndex = $tokens->getNextNonWhitespace($headerIndex); - $lineBreakCount = $this->getLineBreakCount($tokens, $headerIndex + 1, null === $afterCommentIndex ? count($tokens) : $afterCommentIndex); + $lineBreakCount = $this->getLineBreakCount($tokens, $headerIndex + 1, null === $afterCommentIndex ? \count($tokens) : $afterCommentIndex); if ($lineBreakCount < $expectedLineCount) { $missing = str_repeat($lineEnding, $expectedLineCount - $lineBreakCount); if ($tokens[$headerIndex + 1]->isWhitespace()) { diff --git a/src/Fixer/Comment/NoEmptyCommentFixer.php b/src/Fixer/Comment/NoEmptyCommentFixer.php index c4e36ccf828..6336a3ae351 100644 --- a/src/Fixer/Comment/NoEmptyCommentFixer.php +++ b/src/Fixer/Comment/NoEmptyCommentFixer.php @@ -60,7 +60,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - for ($index = 1, $count = count($tokens); $index < $count; ++$index) { + for ($index = 1, $count = \count($tokens); $index < $count; ++$index) { if (!$tokens[$index]->isGivenKind(T_COMMENT)) { continue; } @@ -89,7 +89,7 @@ private function getCommentBlock(Tokens $tokens, $index) $commentType = $this->getCommentType($tokens[$index]->getContent()); $empty = $this->isEmptyComment($tokens[$index]->getContent()); $start = $index; - $count = count($tokens); + $count = \count($tokens); ++$index; for (; $index < $count; ++$index) { diff --git a/src/Fixer/Comment/SingleLineCommentStyleFixer.php b/src/Fixer/Comment/SingleLineCommentStyleFixer.php index 245b054c381..58fdc1319a1 100644 --- a/src/Fixer/Comment/SingleLineCommentStyleFixer.php +++ b/src/Fixer/Comment/SingleLineCommentStyleFixer.php @@ -45,8 +45,8 @@ public function configure(array $configuration = null) { parent::configure($configuration); - $this->asteriskEnabled = in_array('asterisk', $this->configuration['comment_types'], true); - $this->hashEnabled = in_array('hash', $this->configuration['comment_types'], true); + $this->asteriskEnabled = \in_array('asterisk', $this->configuration['comment_types'], true); + $this->hashEnabled = \in_array('hash', $this->configuration['comment_types'], true); } /** diff --git a/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php b/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php index a8b178e176a..80a89603377 100644 --- a/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php +++ b/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php @@ -75,7 +75,7 @@ public function getPriority() */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - for ($index = count($tokens) - 1; 0 <= $index; --$index) { + for ($index = \count($tokens) - 1; 0 <= $index; --$index) { $token = $tokens[$index]; $this->fixElseif($index, $token, $tokens); $this->fixElse($index, $token, $tokens); @@ -209,7 +209,7 @@ private function addBraces(Tokens $tokens, Token $token, $index, $colonIndex) ); // increment the position of the colon by number of items inserted - $colonIndex += count($items); + $colonIndex += \count($items); $items = [new Token('{')]; if (!$tokens[$colonIndex + 1]->isWhitespace()) { diff --git a/src/Fixer/ControlStructure/NoBreakCommentFixer.php b/src/Fixer/ControlStructure/NoBreakCommentFixer.php index 9bffbf351ab..71fe369b479 100644 --- a/src/Fixer/ControlStructure/NoBreakCommentFixer.php +++ b/src/Fixer/ControlStructure/NoBreakCommentFixer.php @@ -75,7 +75,7 @@ protected function createConfigurationDefinition() ->setAllowedTypes(['string']) ->setAllowedValues([ function ($value) { - if (is_string($value) && Preg::match('/\R/', $value)) { + if (\is_string($value) && Preg::match('/\R/', $value)) { throw new InvalidOptionsException('The comment text must not contain new lines.'); } @@ -95,7 +95,7 @@ function ($value) { */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - for ($position = count($tokens) - 1; $position >= 0; --$position) { + for ($position = \count($tokens) - 1; $position >= 0; --$position) { if ($tokens[$position]->isGivenKind([T_CASE, T_DEFAULT])) { $this->fixCase($tokens, $position); } @@ -111,7 +111,7 @@ private function fixCase(Tokens $tokens, $casePosition) $empty = true; $fallThrough = true; $commentPosition = null; - for ($i = $tokens->getNextTokenOfKind($casePosition, [':', ';']) + 1, $max = count($tokens); $i < $max; ++$i) { + for ($i = $tokens->getNextTokenOfKind($casePosition, [':', ';']) + 1, $max = \count($tokens); $i < $max; ++$i) { if ($tokens[$i]->isGivenKind([T_SWITCH, T_IF, T_ELSE, T_ELSEIF, T_FOR, T_FOREACH, T_WHILE, T_DO, T_FUNCTION, T_CLASS])) { $empty = false; $i = $this->getStructureEnd($tokens, $i); diff --git a/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php b/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php index c75b76b0767..1f9a4c7dfa8 100644 --- a/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php @@ -47,7 +47,7 @@ public function __construct() parent::__construct(); // To be moved back to compile time property declaration when PHP support of PHP CS Fixer will be 7.0+ - if (defined('T_COALESCE')) { + if (\defined('T_COALESCE')) { self::$loops['clone']['forbiddenContents'][] = [T_COALESCE, '??']; } } diff --git a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php index 5b6344b57f7..7e95623b76e 100644 --- a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php @@ -88,7 +88,7 @@ private function clearOverCompleteBraces(Tokens $tokens, $openIndex, $closeIndex private function findCurlyBraceOpen(Tokens $tokens) { - for ($i = count($tokens) - 1; $i > 0; --$i) { + for ($i = \count($tokens) - 1; $i > 0; --$i) { if ($tokens[$i]->equals('{')) { yield $i; } diff --git a/src/Fixer/ControlStructure/YodaStyleFixer.php b/src/Fixer/ControlStructure/YodaStyleFixer.php index 4549fba720a..bddc7edd665 100644 --- a/src/Fixer/ControlStructure/YodaStyleFixer.php +++ b/src/Fixer/ControlStructure/YodaStyleFixer.php @@ -151,7 +151,7 @@ protected function createConfigurationDefinition() private function findComparisonEnd(Tokens $tokens, $index) { ++$index; - $count = count($tokens); + $count = \count($tokens); while ($index < $count) { $token = $tokens[$index]; if ($token->isGivenKind([T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) { @@ -241,12 +241,12 @@ private function findComparisonStart(Tokens $tokens, $index) */ private function fixTokens(Tokens $tokens) { - for ($i = count($tokens) - 1; $i > 1; --$i) { + for ($i = \count($tokens) - 1; $i > 1; --$i) { if ($tokens[$i]->isGivenKind($this->candidateTypes)) { $yoda = $this->candidateTypesConfiguration[$tokens[$i]->getId()]; } elseif ( - ($tokens[$i]->equals('<') && in_array('<', $this->candidateTypes, true)) - || ($tokens[$i]->equals('>') && in_array('>', $this->candidateTypes, true)) + ($tokens[$i]->equals('<') && \in_array('<', $this->candidateTypes, true)) + || ($tokens[$i]->equals('>') && \in_array('>', $this->candidateTypes, true)) ) { $yoda = $this->candidateTypesConfiguration[$tokens[$i]->getContent()]; } else { @@ -335,7 +335,7 @@ private function fixTokensComparePart(Tokens $tokens, $start, $end) { $newTokens = $tokens->generatePartialCode($start, $end); $newTokens = $this->fixTokens(Tokens::fromCode(sprintf('clearAt(count($newTokens) - 1); + $newTokens->clearAt(\count($newTokens) - 1); $newTokens->clearAt(0); $newTokens->clearEmptyTokens(); @@ -476,11 +476,11 @@ private function isOfLowerPrecedence(Token $token) T_OPEN_TAG_WITH_ECHO, ]; - if (defined('T_POW_EQUAL')) { + if (\defined('T_POW_EQUAL')) { $tokens[] = T_POW_EQUAL; // **= } - if (defined('T_COALESCE')) { + if (\defined('T_COALESCE')) { $tokens[] = T_COALESCE; // ?? } } diff --git a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationBracesFixer.php b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationBracesFixer.php index 89a9241d97f..08d84639415 100644 --- a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationBracesFixer.php +++ b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationBracesFixer.php @@ -98,7 +98,7 @@ private function addBracesToAnnotations(Tokens $tokens) */ private function removesBracesFromAnnotations(Tokens $tokens) { - for ($index = 0, $max = count($tokens); $index < $max; ++$index) { + for ($index = 0, $max = \count($tokens); $index < $max; ++$index) { if (!$tokens[$index]->isType(DocLexer::T_AT)) { continue; } diff --git a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php index 30469f26750..6c501edffad 100644 --- a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php +++ b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php @@ -62,7 +62,7 @@ protected function createConfigurationDefinition() protected function fixAnnotations(Tokens $tokens) { $annotationPositions = []; - for ($index = 0, $max = count($tokens); $index < $max; ++$index) { + for ($index = 0, $max = \count($tokens); $index < $max; ++$index) { if (!$tokens[$index]->isType(DocLexer::T_AT)) { continue; } @@ -187,7 +187,7 @@ private function indentationCanBeFixed(Tokens $tokens, $newLineTokenIndex, array } } - for ($index = $newLineTokenIndex + 1, $max = count($tokens); $index < $max; ++$index) { + for ($index = $newLineTokenIndex + 1, $max = \count($tokens); $index < $max; ++$index) { $token = $tokens[$index]; if (false !== strpos($token->getContent(), "\n")) { diff --git a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php index bf886c7c5cf..2285b1e9028 100644 --- a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php +++ b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php @@ -239,7 +239,7 @@ private function fixSpacesAroundCommas(Tokens $tokens) $token->clear(); } - if ($index < count($tokens) - 1 && !Preg::match('/^\s/', $tokens[$index + 1]->getContent())) { + if ($index < \count($tokens) - 1 && !Preg::match('/^\s/', $tokens[$index + 1]->getContent())) { $tokens->insertAt($index + 1, new Token(DocLexer::T_NONE, ' ')); } } diff --git a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php index 212cf4dad3c..cc8dad5edf2 100644 --- a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php +++ b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php @@ -76,8 +76,8 @@ public function doSomething(\Foo\Bar $foo): \Foo\Bar\Baz public function isCandidate(Tokens $tokens) { return $tokens->isTokenKindFound(T_FUNCTION) && ( - count((new NamespacesAnalyzer())->getDeclarations($tokens)) || - count((new NamespaceUsesAnalyzer())->getDeclarationsFromTokens($tokens)) + \count((new NamespacesAnalyzer())->getDeclarations($tokens)) || + \count((new NamespaceUsesAnalyzer())->getDeclarationsFromTokens($tokens)) ); } diff --git a/src/Fixer/Import/NoUnusedImportsFixer.php b/src/Fixer/Import/NoUnusedImportsFixer.php index 9bd36842fc2..416af8afa90 100644 --- a/src/Fixer/Import/NoUnusedImportsFixer.php +++ b/src/Fixer/Import/NoUnusedImportsFixer.php @@ -83,7 +83,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { $useDeclarations = (new NamespaceUsesAnalyzer())->getDeclarationsFromTokens($tokens); - if (0 === count($useDeclarations)) { + if (0 === \count($useDeclarations)) { return; } @@ -232,7 +232,7 @@ private function removeUseDeclaration(Tokens $tokens, NamespaceUseAnalysis $useD private function removeUsesInSameNamespace(Tokens $tokens, array $useDeclarations, NamespaceAnalysis $namespaceDeclaration) { $namespace = $namespaceDeclaration->getFullName(); - $nsLength = strlen($namespace.'\\'); + $nsLength = \strlen($namespace.'\\'); foreach ($useDeclarations as $useDeclaration) { if ($useDeclaration->isAliased()) { diff --git a/src/Fixer/Import/OrderedImportsFixer.php b/src/Fixer/Import/OrderedImportsFixer.php index ffb959a7e07..868d0c65cb7 100644 --- a/src/Fixer/Import/OrderedImportsFixer.php +++ b/src/Fixer/Import/OrderedImportsFixer.php @@ -181,7 +181,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $tokensAnalyzer = new TokensAnalyzer($tokens); $namespacesImports = $tokensAnalyzer->getImportUseIndexes(true); - if (0 === count($namespacesImports)) { + if (0 === \count($namespacesImports)) { return; } @@ -202,7 +202,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) foreach ($usesOrder as $index => $use) { $declarationTokens = Tokens::fromCode('clearRange(0, 2); // clear `clearAt(count($declarationTokens) - 1); // clear `;` + $declarationTokens->clearAt(\count($declarationTokens) - 1); // clear `;` $declarationTokens->clearEmptyTokens(); $tokens->overrideRange($index, $mapStartToEnd[$index], $declarationTokens); @@ -244,19 +244,19 @@ protected function createConfigurationDefinition() ->setAllowedValues([static function ($value) use ($supportedSortTypes) { if (null !== $value) { $missing = array_diff($supportedSortTypes, $value); - if (count($missing)) { + if (\count($missing)) { throw new InvalidOptionsException(sprintf( 'Missing sort %s "%s".', - 1 === count($missing) ? 'type' : 'types', + 1 === \count($missing) ? 'type' : 'types', implode('", "', $missing) )); } $unknown = array_diff($value, $supportedSortTypes); - if (count($unknown)) { + if (\count($unknown)) { throw new InvalidOptionsException(sprintf( 'Unknown sort %s "%s".', - 1 === count($unknown) ? 'type' : 'types', + 1 === \count($unknown) ? 'type' : 'types', implode('", "', $unknown) )); } @@ -307,8 +307,8 @@ private function sortByLength(array $first, array $second) $firstNamespace = $this->prepareNamespace($first['namespace']); $secondNamespace = $this->prepareNamespace($second['namespace']); - $firstNamespaceLength = strlen($firstNamespace); - $secondNamespaceLength = strlen($secondNamespace); + $firstNamespaceLength = \strlen($firstNamespace); + $secondNamespaceLength = \strlen($secondNamespace); if ($firstNamespaceLength === $secondNamespaceLength) { $sortResult = strcasecmp($firstNamespace, $secondNamespace); @@ -335,7 +335,7 @@ private function getNewOrder(array $uses, Tokens $tokens) $originalIndexes = []; $lineEnding = $this->whitespacesConfig->getLineEnding(); - for ($i = count($uses) - 1; $i >= 0; --$i) { + for ($i = \count($uses) - 1; $i >= 0; --$i) { $index = $uses[$i]; $startIndex = $tokens->getTokenNotOfKindSibling($index + 1, 1, [[T_WHITESPACE]]); @@ -362,7 +362,7 @@ private function getNewOrder(array $uses, Tokens $tokens) // if group import, sort the items within the group definition // figure out where the list of namespace parts within the group def. starts - $namespaceTokensCount = count($namespaceTokens) - 1; + $namespaceTokensCount = \count($namespaceTokens) - 1; $namespace = ''; for ($k = 0; $k < $namespaceTokensCount; ++$k) { if ($namespaceTokens[$k]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_OPEN)) { diff --git a/src/Fixer/Import/SingleImportPerStatementFixer.php b/src/Fixer/Import/SingleImportPerStatementFixer.php index 36be8ee64b8..c257e5f1022 100644 --- a/src/Fixer/Import/SingleImportPerStatementFixer.php +++ b/src/Fixer/Import/SingleImportPerStatementFixer.php @@ -201,7 +201,7 @@ private function fixGroupUse(Tokens $tokens, $index, $endIndex) list($groupPrefix, $groupOpenIndex, $groupCloseIndex, $comment) = $this->getGroupDeclaration($tokens, $index); $statements = $this->getGroupStatements($tokens, $groupPrefix, $groupOpenIndex, $groupCloseIndex, $comment); - if (count($statements) < 2) { + if (\count($statements) < 2) { return; } diff --git a/src/Fixer/Import/SingleLineAfterImportsFixer.php b/src/Fixer/Import/SingleLineAfterImportsFixer.php index 4f6fb0fa8c3..c3500c490a6 100644 --- a/src/Fixer/Import/SingleLineAfterImportsFixer.php +++ b/src/Fixer/Import/SingleLineAfterImportsFixer.php @@ -105,7 +105,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) ++$added; } - if ($semicolonIndex === count($tokens) - 1) { + if ($semicolonIndex === \count($tokens) - 1) { $tokens->insertAt($insertIndex + 1, new Token([T_WHITESPACE, $ending.$ending.$indent])); ++$added; } else { diff --git a/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php b/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php index 0c62161d3d0..7fd1a571829 100644 --- a/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php +++ b/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php @@ -79,7 +79,7 @@ private function replaceClassKeywords(Tokens $tokens, $namespaceNumber = -1) $namespaceIndexes = array_keys($tokens->findGivenKind(T_NAMESPACE)); // Namespace blocks - if (count($namespaceIndexes) && isset($namespaceIndexes[$namespaceNumber])) { + if (\count($namespaceIndexes) && isset($namespaceIndexes[$namespaceNumber])) { $startIndex = $namespaceIndexes[$namespaceNumber]; $namespaceBlockStartIndex = $tokens->getNextTokenOfKind($startIndex, [';', '{']); @@ -89,7 +89,7 @@ private function replaceClassKeywords(Tokens $tokens, $namespaceNumber = -1) $endIndex = $endIndex ?: $tokens->count() - 1; } elseif (-1 === $namespaceNumber) { // Out of any namespace block $startIndex = 0; - $endIndex = count($namespaceIndexes) ? $namespaceIndexes[0] : $tokens->count() - 1; + $endIndex = \count($namespaceIndexes) ? $namespaceIndexes[0] : $tokens->count() - 1; } else { return; } @@ -137,7 +137,7 @@ static function ($import) { $groupImportParts = array_map(static function ($import) { return trim($import); }, explode(' as ', $groupImport)); - if (2 === count($groupImportParts)) { + if (2 === \count($groupImportParts)) { $this->imports[$groupImportParts[1]] = $import.$groupImportParts[0]; } else { $this->imports[] = $import.$groupImport; @@ -204,7 +204,7 @@ private function replaceClassKeyword(Tokens $tokens, $classIndex) $classStringArray = explode('\\', $classString); $namespaceToTest = $classStringArray[0]; - if (0 === strcmp($namespaceToTest, substr($import, -strlen($namespaceToTest)))) { + if (0 === strcmp($namespaceToTest, substr($import, -\strlen($namespaceToTest)))) { $classImport = $import; break; @@ -236,16 +236,16 @@ private function makeClassFQN($classImport, $classString) } $classStringArray = explode('\\', $classString); - $classStringLength = count($classStringArray); + $classStringLength = \count($classStringArray); $classImportArray = explode('\\', $classImport); - $classImportLength = count($classImportArray); + $classImportLength = \count($classImportArray); if (1 === $classStringLength) { return $classImport; } return implode('\\', array_merge( - array_slice($classImportArray, 0, $classImportLength - $classStringLength + 1), + \array_slice($classImportArray, 0, $classImportLength - $classStringLength + 1), $classStringArray )); } diff --git a/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php b/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php index f8e4a0db22c..f85564351bc 100644 --- a/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php +++ b/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php @@ -81,7 +81,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $nextIssetInfo = $this->getIssetInfo($tokens, $issetIndex); // clone what we want to move, do not clone '(' and ')' of the 'isset' statement we're merging - $clones = $this->getTokenClones($tokens, array_slice($nextIssetInfo, 1, -1)); + $clones = $this->getTokenClones($tokens, \array_slice($nextIssetInfo, 1, -1)); // clean up no the tokens of the 'isset' statement we're merging $this->clearTokens($tokens, array_merge($nextIssetInfo, [$issetIndex, $booleanAndTokenIndex])); @@ -91,7 +91,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $tokens->insertAt($insertLocation, $clones); // correct some counts and offset based on # of tokens inserted - $numberOfTokensInserted = count($clones); + $numberOfTokensInserted = \count($clones); $tokenCount += $numberOfTokensInserted; $issetCloseBraceIndex += $numberOfTokensInserted; $insertLocation += $numberOfTokensInserted; diff --git a/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php b/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php index 32f6601f7dd..e7bfc162c88 100644 --- a/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php +++ b/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php @@ -62,7 +62,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $previousUnsetCall = $this->getPreviousUnsetCall($tokens, $index); - if (is_int($previousUnsetCall)) { + if (\is_int($previousUnsetCall)) { $index = $previousUnsetCall; continue; diff --git a/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php b/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php index 90bb728c41b..b3a2157e1c5 100644 --- a/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php +++ b/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php @@ -146,7 +146,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) continue; } - if ($this->configuration[self::OPTION_NOISE_REMAINING_USAGES] && !in_array($tokens[$functionIndex]->getContent(), $excludedFunctions, true)) { + if ($this->configuration[self::OPTION_NOISE_REMAINING_USAGES] && !\in_array($tokens[$functionIndex]->getContent(), $excludedFunctions, true)) { $tokens->clearAt($index); } } diff --git a/src/Fixer/LanguageConstruct/IsNullFixer.php b/src/Fixer/LanguageConstruct/IsNullFixer.php index 446bab75450..138263034be 100644 --- a/src/Fixer/LanguageConstruct/IsNullFixer.php +++ b/src/Fixer/LanguageConstruct/IsNullFixer.php @@ -129,7 +129,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $referenceEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $matches[1]); $isContainingDangerousConstructs = false; for ($paramTokenIndex = $matches[1]; $paramTokenIndex <= $referenceEnd; ++$paramTokenIndex) { - if (in_array($tokens[$paramTokenIndex]->getContent(), ['?', '?:', '='], true)) { + if (\in_array($tokens[$paramTokenIndex]->getContent(), ['?', '?:', '='], true)) { $isContainingDangerousConstructs = true; break; diff --git a/src/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixer.php b/src/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixer.php index 29535619e0a..ddb67adf77c 100644 --- a/src/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixer.php +++ b/src/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixer.php @@ -56,7 +56,7 @@ public function getDefinition() */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - for ($index = count($tokens) - 1; 0 <= $index; --$index) { + for ($index = \count($tokens) - 1; 0 <= $index; --$index) { $token = $tokens[$index]; if (!$token->isGivenKind(T_NAMESPACE)) { diff --git a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php index a9cc3aa99a4..f03a7cdb4c0 100644 --- a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php @@ -252,7 +252,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) --$index; } - if (count($this->alignOperatorTokens)) { + if (\count($this->alignOperatorTokens)) { $this->fixAlignment($tokens, $this->alignOperatorTokens); } } @@ -271,23 +271,23 @@ protected function createConfigurationDefinition() ->setAllowedTypes(['array']) ->setAllowedValues([static function ($option) { foreach ($option as $operator => $value) { - if (!in_array($operator, self::$supportedOperators, true)) { + if (!\in_array($operator, self::$supportedOperators, true)) { throw new InvalidOptionsException( sprintf( 'Unexpected "operators" key, expected any of "%s", got "%s".', implode('", "', self::$supportedOperators), - is_object($operator) ? get_class($operator) : gettype($operator).'#'.$operator + \is_object($operator) ? \get_class($operator) : \gettype($operator).'#'.$operator ) ); } - if (!in_array($value, self::$allowedValues, true)) { + if (!\in_array($value, self::$allowedValues, true)) { throw new InvalidOptionsException( sprintf( 'Unexpected value for operator "%s", expected any of "%s", got "%s".', $operator, implode('", "', self::$allowedValues), - is_object($value) ? get_class($value) : (null === $value ? 'null' : gettype($value).'#'.$value) + \is_object($value) ? \get_class($value) : (null === $value ? 'null' : \gettype($value).'#'.$value) ) ); } @@ -418,11 +418,11 @@ private function resolveOperatorsFromConfig() } } - if (!defined('T_SPACESHIP')) { + if (!\defined('T_SPACESHIP')) { unset($operators['<=>']); } - if (!defined('T_COALESCE')) { + if (!\defined('T_COALESCE')) { unset($operators['??']); } @@ -510,9 +510,9 @@ private function fixAlignment(Tokens $tokens, array $toAlign) $tokensClone = clone $tokens; if ('=>' === $tokenContent) { - $this->injectAlignmentPlaceholdersForArrow($tokensClone, 0, count($tokens)); + $this->injectAlignmentPlaceholdersForArrow($tokensClone, 0, \count($tokens)); } else { - $this->injectAlignmentPlaceholders($tokensClone, 0, count($tokens), $tokenContent); + $this->injectAlignmentPlaceholders($tokensClone, 0, \count($tokens), $tokenContent); } // for all tokens that should be aligned but do not have anything to align with, fix spacing if needed @@ -749,7 +749,7 @@ private function replacePlaceholders(Tokens $tokens, $alignStrategy) } foreach ($groups as $group) { - if (count($group) < 1) { + if (\count($group) < 1) { continue; } @@ -760,7 +760,7 @@ private function replacePlaceholders(Tokens $tokens, $alignStrategy) $before = substr($lines[$index], 0, $currentPosition); if (self::ALIGN_SINGLE_SPACE === $alignStrategy) { - if (1 > strlen($before) || ' ' !== substr($before, -1)) { // if last char of before-content is not ' '; add it + if (1 > \strlen($before) || ' ' !== substr($before, -1)) { // if last char of before-content is not ' '; add it $before .= ' '; } } elseif (self::ALIGN_SINGLE_SPACE_MINIMAL === $alignStrategy) { diff --git a/src/Fixer/Operator/NewWithBracesFixer.php b/src/Fixer/Operator/NewWithBracesFixer.php index 8a1880c611d..c3ab1afbd2d 100644 --- a/src/Fixer/Operator/NewWithBracesFixer.php +++ b/src/Fixer/Operator/NewWithBracesFixer.php @@ -95,7 +95,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) [CT::T_BRACE_CLASS_INSTANTIATION_CLOSE], ]; - if (defined('T_SPACESHIP')) { + if (\defined('T_SPACESHIP')) { $nextTokenKinds[] = [T_SPACESHIP]; } } diff --git a/src/Fixer/PhpTag/FullOpeningTagFixer.php b/src/Fixer/PhpTag/FullOpeningTagFixer.php index e884f763efe..db08c98e43f 100644 --- a/src/Fixer/PhpTag/FullOpeningTagFixer.php +++ b/src/Fixer/PhpTag/FullOpeningTagFixer.php @@ -94,7 +94,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokensOrg) } $tokensOldContent .= $tokenContent; - $tokensOldContentLength += strlen($tokenContent); + $tokensOldContentLength += \strlen($tokenContent); continue; } @@ -103,11 +103,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokensOrg) $tokenContent = ''; $tokenContentLength = 0; $parts = explode('getContent()); - $iLast = count($parts) - 1; + $iLast = \count($parts) - 1; foreach ($parts as $i => $part) { $tokenContent .= $part; - $tokenContentLength += strlen($part); + $tokenContentLength += \strlen($part); if ($i !== $iLast) { $originalTokenContent = substr($content, $tokensOldContentLength + $tokenContentLength, 5); @@ -126,7 +126,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokensOrg) } $tokensOldContent .= $token->getContent(); - $tokensOldContentLength += strlen($token->getContent()); + $tokensOldContentLength += \strlen($token->getContent()); } $tokensOrg->overrideRange(0, $tokensOrg->count() - 1, $tokens); diff --git a/src/Fixer/PhpTag/NoClosingTagFixer.php b/src/Fixer/PhpTag/NoClosingTagFixer.php index 1251cc9c99f..1411ef4d7f7 100644 --- a/src/Fixer/PhpTag/NoClosingTagFixer.php +++ b/src/Fixer/PhpTag/NoClosingTagFixer.php @@ -49,7 +49,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - if (count($tokens) < 2 || !$tokens->isMonolithicPhp()) { + if (\count($tokens) < 2 || !$tokens->isMonolithicPhp()) { return; } diff --git a/src/Fixer/PhpTag/NoShortEchoTagFixer.php b/src/Fixer/PhpTag/NoShortEchoTagFixer.php index fde49765bb9..b16c29fd344 100644 --- a/src/Fixer/PhpTag/NoShortEchoTagFixer.php +++ b/src/Fixer/PhpTag/NoShortEchoTagFixer.php @@ -47,7 +47,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - $i = count($tokens); + $i = \count($tokens); while ($i--) { $token = $tokens[$i]; diff --git a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php index 0340a28fd39..25267e7d022 100644 --- a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php @@ -194,7 +194,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $index = $this->getAssertCandidate($tokens, $methodIndex); - if (!is_array($index)) { + if (!\is_array($index)) { continue; } @@ -335,11 +335,11 @@ private function fixAssert(Tokens $tokens, array $assertIndexes) ) = $assertIndexes; $content = strtolower($tokens[$testIndex]->getContent()); - if (!in_array($content, $this->functions, true)) { + if (!\in_array($content, $this->functions, true)) { return $assertCallCloseIndex; } - if (is_array(self::$fixMap[$content])) { + if (\is_array(self::$fixMap[$content])) { if (false !== self::$fixMap[$content][$isPositive]) { $tokens[$assertCallIndex] = new Token([T_STRING, self::$fixMap[$content][$isPositive]]); $this->removeFunctionCall($tokens, $testDefaultNamespaceTokenIndex, $testIndex, $testOpenIndex, $testCloseIndex); diff --git a/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php b/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php index a61c0aabec7..118479922f1 100644 --- a/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php @@ -180,7 +180,7 @@ private function fixExpectation($tokens, $startIndex, $endIndex) $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); $arguments = $argumentsAnalyzer->getArguments($tokens, $openIndex, $closeIndex); - $argumentsCnt = count($arguments); + $argumentsCnt = \count($arguments); $argumentsReplacements = ['expectException', $this->methodMap[$tokens[$index]->getContent()], 'expectExceptionCode']; diff --git a/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php b/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php index 7fc4fed6fbc..c3981aafca5 100644 --- a/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php @@ -117,14 +117,14 @@ private function isAllowedByConfiguration(Tokens $tokens, $i) { $typeIndex = $tokens->getPrevMeaningfulToken($i); if ($tokens[$typeIndex]->isGivenKind([T_FINAL])) { - return in_array('final', $this->configuration['types'], true); + return \in_array('final', $this->configuration['types'], true); } if ($tokens[$typeIndex]->isGivenKind([T_ABSTRACT])) { - return in_array('abstract', $this->configuration['types'], true); + return \in_array('abstract', $this->configuration['types'], true); } - return in_array('normal', $this->configuration['types'], true); + return \in_array('normal', $this->configuration['types'], true); } private function createDocBlock(Tokens $tokens, $docBlockIndex) @@ -224,7 +224,7 @@ private function addInternalAnnotation(DocBlock $docBlock, Tokens $tokens, $docB private function makeDocBlockMultiLineIfNeeded(DocBlock $doc, Tokens $tokens, $docBlockIndex) { $lines = $doc->getLines(); - if (1 === count($lines) && empty($doc->getAnnotationsOfType('internal'))) { + if (1 === \count($lines) && empty($doc->getAnnotationsOfType('internal'))) { $lines = $this->splitUpDocBlock($lines, $tokens, $docBlockIndex); return new DocBlock(implode($lines)); @@ -273,7 +273,7 @@ private function getSingleLineDocBlockEntry($line) if (' ' === $line[$i]) { ++$i; } - $line = array_slice($line, $i); + $line = \array_slice($line, $i); return implode($line); } diff --git a/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php b/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php index 44e77892738..839d3168a64 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php @@ -236,7 +236,7 @@ private function isMethod(Tokens $tokens, $index) */ private function startsWith($needle, $haystack) { - $len = strlen($needle); + $len = \strlen($needle); return substr($haystack, 0, $len) === $needle; } @@ -448,7 +448,7 @@ private function getSingleLineDocBlockEntry($line) if (' ' === $line[$i]) { ++$i; } - $line = array_slice($line, $i); + $line = \array_slice($line, $i); return implode($line); } @@ -479,7 +479,7 @@ private function removeTestPrefixFromDependsAnnotation(Line $line) $line = \str_split($line->getContent()); $dependsIndex = $this->findWhereDependsFunctionNameStarts($line); - $dependsFunctionName = implode(array_slice($line, $dependsIndex)); + $dependsFunctionName = implode(\array_slice($line, $dependsIndex)); if ($this->startsWith('test', $dependsFunctionName)) { $dependsFunctionName = $this->removeTestPrefix($dependsFunctionName); @@ -498,7 +498,7 @@ private function addTestPrefixToDependsAnnotation(Line $line) { $line = \str_split($line->getContent()); $dependsIndex = $this->findWhereDependsFunctionNameStarts($line); - $dependsFunctionName = implode(array_slice($line, $dependsIndex)); + $dependsFunctionName = implode(\array_slice($line, $dependsIndex)); if (!$this->startsWith('test', $dependsFunctionName)) { $dependsFunctionName = $this->addTestPrefix($dependsFunctionName); diff --git a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php index 00421b71fee..b771fb8811f 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php @@ -310,7 +310,7 @@ protected function createConfigurationDefinition() sprintf( 'Unexpected "methods" key, expected any of "%s", got "%s".', implode('", "', array_keys($thisFixer->staticMethods)), - is_object($method) ? get_class($method) : gettype($method).'#'.$method + \is_object($method) ? \get_class($method) : \gettype($method).'#'.$method ) ); } @@ -321,7 +321,7 @@ protected function createConfigurationDefinition() 'Unexpected value for method "%s", expected any of "%s", got "%s".', $method, implode('", "', array_keys($thisFixer->allowedValues)), - is_object($value) ? get_class($value) : (null === $value ? 'null' : gettype($value).'#'.$value) + \is_object($value) ? \get_class($value) : (null === $value ? 'null' : \gettype($value).'#'.$value) ) ); } diff --git a/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php b/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php index f719eb1758b..9bf49151939 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php @@ -138,7 +138,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $lines = $doc->getLines(); array_splice( $lines, - count($lines) - 1, + \count($lines) - 1, 0, [ new Line(sprintf( diff --git a/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php b/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php index bf2174aade0..e8b3c473413 100644 --- a/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php +++ b/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php @@ -73,7 +73,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - if (!count($this->configuration['annotations'])) { + if (!\count($this->configuration['annotations'])) { return; } diff --git a/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php b/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php index 0e6bb502c4f..7c5a4a9327a 100644 --- a/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php @@ -161,7 +161,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } } - if (!count($arguments)) { + if (!\count($arguments)) { continue; } @@ -178,12 +178,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $lastParamLine = max($lastParamLine, $annotation->getEnd()); } - if (!count($arguments)) { + if (!\count($arguments)) { continue; } $lines = $doc->getLines(); - $linesCount = count($lines); + $linesCount = \count($lines); Preg::match('/^(\s*).*$/', $lines[$linesCount - 1]->getContent(), $matches); $indent = $matches[1]; diff --git a/src/Fixer/Phpdoc/PhpdocAlignFixer.php b/src/Fixer/Phpdoc/PhpdocAlignFixer.php index c37d1475ce0..66f397720e5 100644 --- a/src/Fixer/Phpdoc/PhpdocAlignFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAlignFixer.php @@ -224,7 +224,7 @@ private function fixDocBlock($content) $lineEnding = $this->whitespacesConfig->getLineEnding(); $lines = Utils::splitLines($content); - for ($i = 0, $l = count($lines); $i < $l; ++$i) { + for ($i = 0, $l = \count($lines); $i < $l; ++$i) { $items = []; $matches = $this->getMatches($lines[$i]); @@ -258,9 +258,9 @@ private function fixDocBlock($content) continue; } - $tagMax = max($tagMax, strlen($item['tag'])); - $hintMax = max($hintMax, strlen($item['hint'])); - $varMax = max($varMax, strlen($item['var'])); + $tagMax = max($tagMax, \strlen($item['tag'])); + $hintMax = max($hintMax, \strlen($item['hint'])); + $varMax = max($varMax, \strlen($item['var'])); } $currTag = null; @@ -276,7 +276,7 @@ private function fixDocBlock($content) $extraIndent = 2; - if (in_array($currTag, self::$tagsWithName, true) || in_array($currTag, self::$tagsWithMethodSignature, true)) { + if (\in_array($currTag, self::$tagsWithName, true) || \in_array($currTag, self::$tagsWithMethodSignature, true)) { $extraIndent = 3; } @@ -302,7 +302,7 @@ private function fixDocBlock($content) .' * @' .$item['tag'] .$this->getIndent( - $tagMax - strlen($item['tag']) + 1, + $tagMax - \strlen($item['tag']) + 1, $item['hint'] ? 1 : 0 ) .$item['hint'] @@ -310,16 +310,16 @@ private function fixDocBlock($content) if (!empty($item['var'])) { $line .= - $this->getIndent(($hintMax ?: -1) - strlen($item['hint']) + 1) + $this->getIndent(($hintMax ?: -1) - \strlen($item['hint']) + 1) .$item['var'] .( !empty($item['desc']) - ? $this->getIndent($varMax - strlen($item['var']) + 1).$item['desc'].$lineEnding + ? $this->getIndent($varMax - \strlen($item['var']) + 1).$item['desc'].$lineEnding : $lineEnding ) ; } elseif (!empty($item['desc'])) { - $line .= $this->getIndent($hintMax - strlen($item['hint']) + 1).$item['desc'].$lineEnding; + $line .= $this->getIndent($hintMax - \strlen($item['hint']) + 1).$item['desc'].$lineEnding; } else { $line .= $lineEnding; } @@ -427,7 +427,7 @@ private function getSentenceIndent($sentence) return 0; } - $length = strlen($sentence); + $length = \strlen($sentence); return 0 === $length ? 0 : $length + 1; } diff --git a/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php b/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php index 0db5a293a29..e7a42bacac9 100644 --- a/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php @@ -70,7 +70,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) foreach ($annotations as $annotation) { if ( - !$annotation->getTag()->valid() || !in_array($annotation->getTag()->getName(), $this->tags, true) + !$annotation->getTag()->valid() || !\in_array($annotation->getTag()->getName(), $this->tags, true) ) { continue; } diff --git a/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php b/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php index 544774b3866..f6e75f53d8f 100644 --- a/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php @@ -120,11 +120,11 @@ protected function createConfigurationDefinition() $normalizedValue = []; foreach ($value as $from => $to) { - if (!is_string($from)) { + if (!\is_string($from)) { throw new InvalidOptionsException('Tag to replace must be a string.'); } - if (!is_string($to)) { + if (!\is_string($to)) { throw new InvalidOptionsException(sprintf( 'Tag to replace to from "%s" must be a string.', $from diff --git a/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php b/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php index b46f01a10a6..78ebb4c244b 100644 --- a/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php @@ -65,7 +65,7 @@ public function isCandidate(Tokens $tokens) protected function applyFix(\SplFileInfo $file, Tokens $tokens) { // min. offset 4 as minimal candidate is @: isGivenKind([T_CLASS, T_INTERFACE])) { $index = $this->fixClassy($tokens, $index); } diff --git a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php index 6959c945b34..23ad3c3d262 100644 --- a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php +++ b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php @@ -98,7 +98,7 @@ public function test2() */ public function isCandidate(Tokens $tokens) { - return count($tokens) > 10 && $tokens->isTokenKindFound(T_DOC_COMMENT) && $tokens->isAnyTokenKindsFound([T_CLASS, T_INTERFACE]); + return \count($tokens) > 10 && $tokens->isTokenKindFound(T_DOC_COMMENT) && $tokens->isAnyTokenKindsFound([T_CLASS, T_INTERFACE]); } /** @@ -143,22 +143,22 @@ protected function createConfigurationDefinition() ->setNormalizer(static function (Options $options, $value) use ($default) { $normalizedValue = []; foreach ($value as $from => $to) { - if (is_string($from)) { + if (\is_string($from)) { $from = strtolower($from); } if (!isset($default[$from])) { throw new InvalidOptionsException(sprintf( 'Unknown key "%s", expected any of "%s".', - is_object($from) ? get_class($from) : gettype($from).(is_resource($from) ? '' : '#'.$from), + \is_object($from) ? \get_class($from) : \gettype($from).(\is_resource($from) ? '' : '#'.$from), implode('", "', array_keys($default)) )); } - if (!in_array($to, self::$toTypes, true)) { + if (!\in_array($to, self::$toTypes, true)) { throw new InvalidOptionsException(sprintf( 'Unknown value "%s", expected any of "%s".', - is_object($to) ? get_class($to) : gettype($to).(is_resource($to) ? '' : '#'.$to), + \is_object($to) ? \get_class($to) : \gettype($to).(\is_resource($to) ? '' : '#'.$to), implode('", "', self::$toTypes) )); } @@ -200,14 +200,14 @@ private function fixMethod(Tokens $tokens, $index) $docBlock = new DocBlock($tokens[$docIndex]->getContent()); $returnsBlock = $docBlock->getAnnotationsOfType('return'); - if (!count($returnsBlock)) { + if (!\count($returnsBlock)) { return; // no return annotation found } $returnsBlock = $returnsBlock[0]; $types = $returnsBlock->getTypes(); - if (!count($types)) { + if (!\count($types)) { return; // no return type(s) found } diff --git a/src/Fixer/Phpdoc/PhpdocScalarFixer.php b/src/Fixer/Phpdoc/PhpdocScalarFixer.php index aa02399b595..193952c6424 100644 --- a/src/Fixer/Phpdoc/PhpdocScalarFixer.php +++ b/src/Fixer/Phpdoc/PhpdocScalarFixer.php @@ -94,7 +94,7 @@ protected function createConfigurationDefinition() */ protected function normalize($type) { - if (in_array($type, $this->configuration['types'], true)) { + if (\in_array($type, $this->configuration['types'], true)) { return self::$types[$type]; } diff --git a/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php b/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php index 2e9d52402a7..d042ac08cfc 100644 --- a/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php +++ b/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php @@ -90,7 +90,7 @@ private function fixTokenContent($content) '#^/\*\*[ \t]*@var[ \t]+(\S+)[ \t]*(\$\S+)?[ \t]*([^\n]*)\*/$#', static function (array $matches) { $content = '/** @var'; - for ($i = 1, $m = count($matches); $i < $m; ++$i) { + for ($i = 1, $m = \count($matches); $i < $m; ++$i) { if ('' !== $matches[$i]) { $content .= ' '.$matches[$i]; } diff --git a/src/Fixer/Phpdoc/PhpdocTypesFixer.php b/src/Fixer/Phpdoc/PhpdocTypesFixer.php index d87ba839e06..ccda937cb0b 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesFixer.php @@ -94,7 +94,7 @@ protected function normalize($type) { $lower = strtolower($type); - if (in_array($lower, self::$types, true)) { + if (\in_array($lower, self::$types, true)) { return $lower; } diff --git a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php index ca92adcf2d8..f11fec8a4b1 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php @@ -119,7 +119,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $doc = new DocBlock($token->getContent()); $annotations = $doc->getAnnotationsOfType(Annotation::getTagsWithTypes()); - if (!count($annotations)) { + if (!\count($annotations)) { continue; } @@ -181,7 +181,7 @@ static function ($typeA, $typeB) { } } - if (count($nulls)) { + if (\count($nulls)) { if ('always_last' === $this->configuration['null_adjustment']) { array_push($types, ...$nulls); } else { diff --git a/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php b/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php index 0085e767321..0ce1dcc51c3 100644 --- a/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php +++ b/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php @@ -71,14 +71,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) $doc = new DocBlock($token->getContent()); // don't process single line docblocks - if (1 === count($doc->getLines())) { + if (1 === \count($doc->getLines())) { continue; } $annotations = $doc->getAnnotationsOfType(['param', 'return', 'type', 'var']); // only process docblocks where the first meaningful annotation is @type or @var - if (!isset($annotations[0]) || !in_array($annotations[0]->getTag()->getName(), ['type', 'var'], true)) { + if (!isset($annotations[0]) || !\in_array($annotations[0]->getTag()->getName(), ['type', 'var'], true)) { continue; } diff --git a/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php b/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php index f641acc5efc..8871674f9c4 100644 --- a/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php +++ b/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php @@ -58,7 +58,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - $tokenCount = count($tokens); + $tokenCount = \count($tokens); for ($index = 1; $index < $tokenCount; ++$index) { if (!$tokens[$index]->isGivenKind(T_FUNCTION)) { @@ -189,7 +189,7 @@ private function fixFunction(Tokens $tokens, $functionIndex, $functionOpenIndex, } // fix the candidates in reverse order when applicable - for ($i = count($candidates) - 1; $i >= 0; --$i) { + for ($i = \count($candidates) - 1; $i >= 0; --$i) { $index = $candidates[$i]; // Check if returning only a variable (i.e. not the result of an expression, function call etc.) diff --git a/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php b/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php index ce0fa06272e..d650819c779 100644 --- a/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php +++ b/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php @@ -134,7 +134,7 @@ private function applyNoMultiLineFix(Tokens $tokens) private function applyChainedCallsFix(Tokens $tokens) { - for ($index = count($tokens) - 1; $index >= 0; --$index) { + for ($index = \count($tokens) - 1; $index >= 0; --$index) { // continue if token is not a semicolon if (!$tokens[$index]->equals(';')) { continue; @@ -175,7 +175,7 @@ private function getNewLineIndex($index, Tokens $tokens) { $lineEnding = $this->whitespacesConfig->getLineEnding(); - for ($index, $count = count($tokens); $index < $count; ++$index) { + for ($index, $count = \count($tokens); $index < $count; ++$index) { if (false !== strstr($tokens[$index]->getContent(), $lineEnding)) { return $index; } diff --git a/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php b/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php index 619c1666135..35ee221af5c 100644 --- a/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php +++ b/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php @@ -47,7 +47,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - for ($index = count($tokens) - 1; $index > 1; --$index) { + for ($index = \count($tokens) - 1; $index > 1; --$index) { if (!$tokens[$index]->isGivenKind(T_CLOSE_TAG)) { continue; } diff --git a/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php b/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php index de9467fca0c..35ae41bf4f6 100644 --- a/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php +++ b/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php @@ -85,7 +85,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { $insideForParenthesesUntil = null; - for ($index = 0, $max = count($tokens) - 1; $index < $max; ++$index) { + for ($index = 0, $max = \count($tokens) - 1; $index < $max; ++$index) { if ($this->configuration['remove_in_empty_for_expressions']) { if ($tokens[$index]->isGivenKind(T_FOR)) { $index = $tokens->getNextMeaningfulToken($index); diff --git a/src/Fixer/Strict/DeclareStrictTypesFixer.php b/src/Fixer/Strict/DeclareStrictTypesFixer.php index 71377951361..0705b7cdd9c 100644 --- a/src/Fixer/Strict/DeclareStrictTypesFixer.php +++ b/src/Fixer/Strict/DeclareStrictTypesFixer.php @@ -139,7 +139,7 @@ private function insertSequence(Tokens $tokens) { $sequence = $this->getDeclareStrictTypeSequence(); $sequence[] = new Token(';'); - $endIndex = count($sequence); + $endIndex = \count($sequence); $tokens->insertAt(1, $sequence); @@ -149,7 +149,7 @@ private function insertSequence(Tokens $tokens) $tokens[0] = new Token([$tokens[0]->getId(), trim($tokens[0]->getContent()).' ']); } - if ($endIndex === count($tokens) - 1) { + if ($endIndex === \count($tokens) - 1) { return; // no more tokens afters sequence, single_blank_line_at_eof might add a line } diff --git a/src/Fixer/Strict/StrictParamFixer.php b/src/Fixer/Strict/StrictParamFixer.php index fcaaa0796d0..0b6a7ba441f 100644 --- a/src/Fixer/Strict/StrictParamFixer.php +++ b/src/Fixer/Strict/StrictParamFixer.php @@ -119,7 +119,7 @@ private function fixFunction(Tokens $tokens, $functionIndex, array $functionPara } } - $functionParamsQuantity = count($functionParams); + $functionParamsQuantity = \count($functionParams); $paramsQuantity = ($sawParameter ? 1 : 0) + $commaCounter; if ($paramsQuantity === $functionParamsQuantity) { @@ -136,7 +136,7 @@ private function fixFunction(Tokens $tokens, $functionIndex, array $functionPara $tokensToInsert[] = new Token(','); $tokensToInsert[] = new Token([T_WHITESPACE, ' ']); - if (!is_array($functionParams[$i])) { + if (!\is_array($functionParams[$i])) { $tokensToInsert[] = clone $functionParams[$i]; continue; diff --git a/src/Fixer/StringNotation/ExplicitStringVariableFixer.php b/src/Fixer/StringNotation/ExplicitStringVariableFixer.php index dca33542ec7..172ec7671bb 100644 --- a/src/Fixer/StringNotation/ExplicitStringVariableFixer.php +++ b/src/Fixer/StringNotation/ExplicitStringVariableFixer.php @@ -61,7 +61,7 @@ public function isCandidate(Tokens $tokens) */ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { - for ($index = count($tokens) - 1; $index > 0; --$index) { + for ($index = \count($tokens) - 1; $index > 0; --$index) { $token = $tokens[$index]; if (!$token->isGivenKind(T_VARIABLE)) { continue; @@ -85,7 +85,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) ++$nextIndex; } - if (1 === count($variableTokens)) { + if (1 === \count($variableTokens)) { $tokens->overrideRange($index, $index, [ new Token([T_DOLLAR_OPEN_CURLY_BRACES, '${']), new Token([T_STRING_VARNAME, substr($token->getContent(), 1)]), diff --git a/src/Fixer/Whitespace/ArrayIndentationFixer.php b/src/Fixer/Whitespace/ArrayIndentationFixer.php index 39087263ceb..997c511db3c 100644 --- a/src/Fixer/Whitespace/ArrayIndentationFixer.php +++ b/src/Fixer/Whitespace/ArrayIndentationFixer.php @@ -126,10 +126,10 @@ private function findArrays(Tokens $tokens) { $arrays = []; - foreach ($this->findArrayTokenRanges($tokens, 0, count($tokens) - 1) as $arrayTokenRanges) { + foreach ($this->findArrayTokenRanges($tokens, 0, \count($tokens) - 1) as $arrayTokenRanges) { $array = [ 'start' => $arrayTokenRanges[0][0], - 'end' => $arrayTokenRanges[count($arrayTokenRanges) - 1][1], + 'end' => $arrayTokenRanges[\count($arrayTokenRanges) - 1][1], 'token_ranges' => $arrayTokenRanges, ]; diff --git a/src/Fixer/Whitespace/LineEndingFixer.php b/src/Fixer/Whitespace/LineEndingFixer.php index 441a421adef..95ea037052f 100644 --- a/src/Fixer/Whitespace/LineEndingFixer.php +++ b/src/Fixer/Whitespace/LineEndingFixer.php @@ -59,7 +59,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { $ending = $this->whitespacesConfig->getLineEnding(); - for ($index = 0, $count = count($tokens); $index < $count; ++$index) { + for ($index = 0, $count = \count($tokens); $index < $count; ++$index) { $token = $tokens[$index]; if ($token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) { diff --git a/src/Fixer/Whitespace/MethodChainingIndentationFixer.php b/src/Fixer/Whitespace/MethodChainingIndentationFixer.php index 29a9c5f4cad..83d22d153d7 100644 --- a/src/Fixer/Whitespace/MethodChainingIndentationFixer.php +++ b/src/Fixer/Whitespace/MethodChainingIndentationFixer.php @@ -52,7 +52,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) { $lineEnding = $this->whitespacesConfig->getLineEnding(); - for ($index = 1, $count = count($tokens); $index < $count; ++$index) { + for ($index = 1, $count = \count($tokens); $index < $count; ++$index) { if (!$tokens[$index]->isGivenKind(T_OBJECT_OPERATOR)) { continue; } diff --git a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php index a5b483bb849..95b6127afe1 100644 --- a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php +++ b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php @@ -428,7 +428,7 @@ private function fixStructureOpenCloseIfMultiLine($index) private function removeEmptyLinesAfterLineWithTokenAt($index) { // find the line break - $tokenCount = count($this->tokens); + $tokenCount = \count($this->tokens); for ($end = $index; $end < $tokenCount; ++$end) { if ( $this->tokens[$end]->equals('}') @@ -451,7 +451,7 @@ private function removeEmptyLinesAfterLineWithTokenAt($index) } $pos = strrpos($content, "\n"); - if ($pos + 2 <= strlen($content)) { // preserve indenting where possible + if ($pos + 2 <= \strlen($content)) { // preserve indenting where possible $newContent = $ending.substr($content, $pos + 1); } else { $newContent = $ending; diff --git a/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php b/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php index c2e51402d8a..1ffc2ed6d40 100644 --- a/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php +++ b/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php @@ -60,7 +60,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) continue; } - if (in_array('inside', $this->configuration['positions'], true)) { + if (\in_array('inside', $this->configuration['positions'], true)) { if ($token->equals('[')) { $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index); } else { @@ -78,7 +78,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } } - if (in_array('outside', $this->configuration['positions'], true)) { + if (\in_array('outside', $this->configuration['positions'], true)) { $prevNonWhitespaceIndex = $tokens->getPrevNonWhitespace($index); if ($tokens[$prevNonWhitespaceIndex]->isComment()) { continue; diff --git a/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php b/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php index 2dc7acb00d9..194386eacf5 100644 --- a/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php +++ b/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php @@ -68,7 +68,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $lines = Preg::split("/([\r\n]+)/", $token->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE); - $linesSize = count($lines); + $linesSize = \count($lines); // fix only multiline whitespaces or singleline whitespaces at the end of file if ($linesSize > 1 || !isset($tokens[$index + 1])) { diff --git a/src/Fixer/Whitespace/NoWhitespaceInBlankLineFixer.php b/src/Fixer/Whitespace/NoWhitespaceInBlankLineFixer.php index b5616a0e996..297be61a65e 100644 --- a/src/Fixer/Whitespace/NoWhitespaceInBlankLineFixer.php +++ b/src/Fixer/Whitespace/NoWhitespaceInBlankLineFixer.php @@ -59,7 +59,7 @@ public function isCandidate(Tokens $tokens) protected function applyFix(\SplFileInfo $file, Tokens $tokens) { // skip first as it cannot be a white space token - for ($i = 1, $count = count($tokens); $i < $count; ++$i) { + for ($i = 1, $count = \count($tokens); $i < $count; ++$i) { if ($tokens[$i]->isWhitespace()) { $this->fixWhitespaceToken($tokens, $i); } @@ -74,7 +74,7 @@ private function fixWhitespaceToken(Tokens $tokens, $index) { $content = $tokens[$index]->getContent(); $lines = Preg::split("/(\r\n|\n)/", $content); - $lineCount = count($lines); + $lineCount = \count($lines); if ( // fix T_WHITESPACES with at least 3 lines (eg `\n \n`) diff --git a/src/FixerConfiguration/AllowedValueSubset.php b/src/FixerConfiguration/AllowedValueSubset.php index ffaa8bde5ea..bc4410b7821 100644 --- a/src/FixerConfiguration/AllowedValueSubset.php +++ b/src/FixerConfiguration/AllowedValueSubset.php @@ -33,12 +33,12 @@ public function __construct(array $allowedValues) */ public function __invoke($values) { - if (!is_array($values)) { + if (!\is_array($values)) { return false; } foreach ($values as $value) { - if (!in_array($value, $this->allowedValues, true)) { + if (!\in_array($value, $this->allowedValues, true)) { return false; } } diff --git a/src/FixerConfiguration/FixerConfigurationResolver.php b/src/FixerConfiguration/FixerConfigurationResolver.php index 99b854bac8d..d8700e6aa2c 100644 --- a/src/FixerConfiguration/FixerConfigurationResolver.php +++ b/src/FixerConfiguration/FixerConfigurationResolver.php @@ -82,7 +82,7 @@ public function resolve(array $options) $allowedValues = $option->getAllowedValues(); if (null !== $allowedValues) { foreach ($allowedValues as &$allowedValue) { - if (is_object($allowedValue) && is_callable($allowedValue)) { + if (\is_object($allowedValue) && \is_callable($allowedValue)) { $allowedValue = function ($values) use ($allowedValue) { return $allowedValue($values); }; @@ -117,7 +117,7 @@ private function addOption(FixerOptionInterface $option) { $name = $option->getName(); - if (in_array($name, $this->registeredNames, true)) { + if (\in_array($name, $this->registeredNames, true)) { throw new \LogicException(sprintf('The "%s" option is defined multiple times.', $name)); } diff --git a/src/FixerConfiguration/FixerConfigurationResolverRootless.php b/src/FixerConfiguration/FixerConfigurationResolverRootless.php index cabe8b63520..1b8b7986af1 100644 --- a/src/FixerConfiguration/FixerConfigurationResolverRootless.php +++ b/src/FixerConfiguration/FixerConfigurationResolverRootless.php @@ -51,7 +51,7 @@ static function (FixerOptionInterface $option) { $this->resolver->getOptions() ); - if (!in_array($root, $names, true)) { + if (!\in_array($root, $names, true)) { throw new \LogicException(sprintf('The "%s" option is not defined.', $root)); } diff --git a/src/FixerDefinition/FixerDefinition.php b/src/FixerDefinition/FixerDefinition.php index b0c8eb1cd0f..3a948ce979d 100644 --- a/src/FixerDefinition/FixerDefinition.php +++ b/src/FixerDefinition/FixerDefinition.php @@ -40,9 +40,9 @@ public function __construct( array $defaultConfiguration = null, $riskyDescription = null ) { - if (6 === func_num_args()) { + if (6 === \func_num_args()) { @trigger_error('Arguments #5 and #6 of FixerDefinition::__construct() are deprecated and will be removed in 3.0, use argument #4 instead.', E_USER_DEPRECATED); - } elseif (5 === func_num_args()) { + } elseif (5 === \func_num_args()) { @trigger_error('Argument #5 of FixerDefinition::__construct() is deprecated and will be removed in 3.0.', E_USER_DEPRECATED); } else { $riskyDescription = $configurationDescription; diff --git a/src/FixerDefinition/VersionSpecification.php b/src/FixerDefinition/VersionSpecification.php index 47bfd58e239..d1459d14008 100644 --- a/src/FixerDefinition/VersionSpecification.php +++ b/src/FixerDefinition/VersionSpecification.php @@ -39,12 +39,12 @@ public function __construct($minimum = null, $maximum = null) throw new \InvalidArgumentException('Minimum or maximum need to be specified.'); } - if (null !== $minimum && (!is_int($minimum) || 1 > $minimum)) { + if (null !== $minimum && (!\is_int($minimum) || 1 > $minimum)) { throw new \InvalidArgumentException('Minimum needs to be either null or an integer greater than 0.'); } if (null !== $maximum) { - if (!is_int($maximum) || 1 > $maximum) { + if (!\is_int($maximum) || 1 > $maximum) { throw new \InvalidArgumentException('Maximum needs to be either null or an integer greater than 0.'); } diff --git a/src/FixerFactory.php b/src/FixerFactory.php index 648e3bbd72a..571f8a06456 100644 --- a/src/FixerFactory.php +++ b/src/FixerFactory.php @@ -172,7 +172,7 @@ public function useRuleSet(RuleSetInterface $ruleSet) $config = $ruleSet->getRuleConfiguration($name); if (null !== $config) { if ($fixer instanceof ConfigurableFixerInterface) { - if (!is_array($config) || !count($config)) { + if (!\is_array($config) || !\count($config)) { throw new InvalidFixerConfigurationException($fixer->getName(), 'Configuration must be an array and may not be empty.'); } @@ -186,12 +186,12 @@ public function useRuleSet(RuleSetInterface $ruleSet) $fixersByName[$name] = $fixer; $conflicts = array_intersect($this->getFixersConflicts($fixer), $fixerNames); - if (count($conflicts) > 0) { + if (\count($conflicts) > 0) { $fixerConflicts[$name] = $conflicts; } } - if (count($fixerConflicts) > 0) { + if (\count($fixerConflicts) > 0) { throw new \UnexpectedValueException($this->generateConflictMessage($fixerConflicts)); } @@ -243,11 +243,11 @@ private function generateConflictMessage(array $fixerConflicts) $report[$fixer] = array_filter( $fixers, static function ($candidate) use ($report, $fixer) { - return !array_key_exists($candidate, $report) || !in_array($fixer, $report[$candidate], true); + return !array_key_exists($candidate, $report) || !\in_array($fixer, $report[$candidate], true); } ); - if (count($report[$fixer]) > 0) { + if (\count($report[$fixer]) > 0) { $message .= sprintf("\n- \"%s\" with \"%s\"", $fixer, implode('", "', $report[$fixer])); } } diff --git a/src/Linter/TokenizerLinter.php b/src/Linter/TokenizerLinter.php index d526f9243de..90d31d52ca4 100644 --- a/src/Linter/TokenizerLinter.php +++ b/src/Linter/TokenizerLinter.php @@ -27,7 +27,7 @@ final class TokenizerLinter implements LinterInterface { public function __construct() { - if (false === defined('TOKEN_PARSE')) { + if (false === \defined('TOKEN_PARSE')) { throw new UnavailableLinterException('Cannot use tokenizer as linter.'); } } diff --git a/src/Preg.php b/src/Preg.php index 9326e697c41..66e53f928e8 100644 --- a/src/Preg.php +++ b/src/Preg.php @@ -158,7 +158,7 @@ public static function split($pattern, $subject, $limit = -1, $flags = 0) */ private static function addUtf8Modifier($pattern) { - if (is_array($pattern)) { + if (\is_array($pattern)) { return array_map(__METHOD__, $pattern); } @@ -172,7 +172,7 @@ private static function addUtf8Modifier($pattern) */ private static function removeUtf8Modifier($pattern) { - if (is_array($pattern)) { + if (\is_array($pattern)) { return array_map(__METHOD__, $pattern); } diff --git a/src/Report/CheckstyleReporter.php b/src/Report/CheckstyleReporter.php index c33e98574f3..e5f506f74f9 100644 --- a/src/Report/CheckstyleReporter.php +++ b/src/Report/CheckstyleReporter.php @@ -34,7 +34,7 @@ public function getFormat() */ public function generate(ReportSummary $reportSummary) { - if (!extension_loaded('dom')) { + if (!\extension_loaded('dom')) { throw new \RuntimeException('Cannot generate report! `ext-dom` is not available!'); } diff --git a/src/Report/JunitReporter.php b/src/Report/JunitReporter.php index ac0a7f45e49..42c5ea3c2cc 100644 --- a/src/Report/JunitReporter.php +++ b/src/Report/JunitReporter.php @@ -35,7 +35,7 @@ public function getFormat() */ public function generate(ReportSummary $reportSummary) { - if (!extension_loaded('dom')) { + if (!\extension_loaded('dom')) { throw new \RuntimeException('Cannot generate report! `ext-dom` is not available!'); } @@ -45,7 +45,7 @@ public function generate(ReportSummary $reportSummary) $testsuite = $testsuites->appendChild($dom->createElement('testsuite')); $testsuite->setAttribute('name', 'PHP CS Fixer'); - if (count($reportSummary->getChanged())) { + if (\count($reportSummary->getChanged())) { $this->createFailedTestCases($dom, $testsuite, $reportSummary); } else { $this->createSuccessTestCase($dom, $testsuite); @@ -98,7 +98,7 @@ private function createFailedTestCases(\DOMDocument $dom, \DOMElement $testsuite $assertionsCount += (int) $testcase->getAttribute('assertions'); } - $testsuite->setAttribute('tests', (string) count($reportSummary->getChanged())); + $testsuite->setAttribute('tests', (string) \count($reportSummary->getChanged())); $testsuite->setAttribute('assertions', (string) $assertionsCount); $testsuite->setAttribute('failures', (string) $assertionsCount); $testsuite->setAttribute('errors', '0'); @@ -114,7 +114,7 @@ private function createFailedTestCases(\DOMDocument $dom, \DOMElement $testsuite */ private function createFailedTestCase(\DOMDocument $dom, $file, array $fixResult, $shouldAddAppliedFixers) { - $appliedFixersCount = count($fixResult['appliedFixers']); + $appliedFixersCount = \count($fixResult['appliedFixers']); $testName = str_replace('.', '_DOT_', Preg::replace('@\.'.pathinfo($file, PATHINFO_EXTENSION).'$@', '', $file)); diff --git a/src/Report/XmlReporter.php b/src/Report/XmlReporter.php index d3e072bbbd1..16352ec54fc 100644 --- a/src/Report/XmlReporter.php +++ b/src/Report/XmlReporter.php @@ -34,7 +34,7 @@ public function getFormat() */ public function generate(ReportSummary $reportSummary) { - if (!extension_loaded('dom')) { + if (!\extension_loaded('dom')) { throw new \RuntimeException('Cannot generate report! `ext-dom` is not available!'); } diff --git a/src/RuleSet.php b/src/RuleSet.php index 0ea2dbbb8f8..2c35d018c2c 100644 --- a/src/RuleSet.php +++ b/src/RuleSet.php @@ -290,7 +290,7 @@ final class RuleSet implements RuleSetInterface public function __construct(array $set = []) { foreach ($set as $key => $value) { - if (is_int($key)) { + if (\is_int($key)) { throw new \InvalidArgumentException(sprintf('Missing value for "%s" rule/set.', $value)); } } @@ -371,7 +371,7 @@ private function resolveSet() // expand sets foreach ($rules as $name => $value) { if ('@' === $name[0]) { - if (!is_bool($value)) { + if (!\is_bool($value)) { throw new \UnexpectedValueException(sprintf('Nested rule set "%s" configuration must be a boolean.', $name)); } diff --git a/src/Runner/FileFilterIterator.php b/src/Runner/FileFilterIterator.php index 21c238f1afa..54806f466d5 100644 --- a/src/Runner/FileFilterIterator.php +++ b/src/Runner/FileFilterIterator.php @@ -58,7 +58,7 @@ public function accept() throw new \RuntimeException( sprintf( 'Expected instance of "\SplFileInfo", got "%s".', - is_object($file) ? get_class($file) : gettype($file) + \is_object($file) ? \get_class($file) : \gettype($file) ) ); } diff --git a/src/Test/AccessibleObject.php b/src/Test/AccessibleObject.php index 33ce2aa15de..3a6c8d4f152 100644 --- a/src/Test/AccessibleObject.php +++ b/src/Test/AccessibleObject.php @@ -42,7 +42,7 @@ public function __construct($object) public function __call($name, array $arguments) { if (!method_exists($this->object, $name)) { - throw new \LogicException(sprintf('Cannot call non existing method %s->%s.', get_class($this->object), $name)); + throw new \LogicException(sprintf('Cannot call non existing method %s->%s.', \get_class($this->object), $name)); } $method = $this->reflection->getMethod($name); @@ -65,7 +65,7 @@ public function __isset($name) public function __get($name) { if (!property_exists($this->object, $name)) { - throw new \LogicException(sprintf('Cannot get non existing property %s->%s.', get_class($this->object), $name)); + throw new \LogicException(sprintf('Cannot get non existing property %s->%s.', \get_class($this->object), $name)); } $property = $this->reflection->getProperty($name); @@ -77,7 +77,7 @@ public function __get($name) public function __set($name, $value) { if (!property_exists($this->object, $name)) { - throw new \LogicException(sprintf('Cannot set non existing property %s->%s = %s.', get_class($this->object), $name, var_export($value, true))); + throw new \LogicException(sprintf('Cannot set non existing property %s->%s = %s.', \get_class($this->object), $name, var_export($value, true))); } $property = $this->reflection->getProperty($name); diff --git a/src/Tokenizer/AbstractTransformer.php b/src/Tokenizer/AbstractTransformer.php index c5e000c2fe6..5cca9a81d6b 100644 --- a/src/Tokenizer/AbstractTransformer.php +++ b/src/Tokenizer/AbstractTransformer.php @@ -27,7 +27,7 @@ abstract class AbstractTransformer implements TransformerInterface public function getName() { $nameParts = explode('\\', static::class); - $name = substr(end($nameParts), 0, -strlen('Transformer')); + $name = substr(end($nameParts), 0, -\strlen('Transformer')); return Utils::camelCaseToUnderscore($name); } diff --git a/src/Tokenizer/Analyzer/ArgumentsAnalyzer.php b/src/Tokenizer/Analyzer/ArgumentsAnalyzer.php index 460bfd36795..ef5c85bbc27 100644 --- a/src/Tokenizer/Analyzer/ArgumentsAnalyzer.php +++ b/src/Tokenizer/Analyzer/ArgumentsAnalyzer.php @@ -35,7 +35,7 @@ final class ArgumentsAnalyzer */ public function countArguments(Tokens $tokens, $openParenthesis, $closeParenthesis) { - return count($this->getArguments($tokens, $openParenthesis, $closeParenthesis)); + return \count($this->getArguments($tokens, $openParenthesis, $closeParenthesis)); } /** diff --git a/src/Tokenizer/Analyzer/CommentsAnalyzer.php b/src/Tokenizer/Analyzer/CommentsAnalyzer.php index bcb12b207d5..e1df3854d2f 100644 --- a/src/Tokenizer/Analyzer/CommentsAnalyzer.php +++ b/src/Tokenizer/Analyzer/CommentsAnalyzer.php @@ -115,7 +115,7 @@ public function getCommentBlockIndices(Tokens $tokens, $index) return $indices; } - $count = count($tokens); + $count = \count($tokens); ++$index; for (; $index < $count; ++$index) { diff --git a/src/Tokenizer/Analyzer/NamespacesAnalyzer.php b/src/Tokenizer/Analyzer/NamespacesAnalyzer.php index 6e2fa139828..a9de0f3a743 100644 --- a/src/Tokenizer/Analyzer/NamespacesAnalyzer.php +++ b/src/Tokenizer/Analyzer/NamespacesAnalyzer.php @@ -44,7 +44,7 @@ public function getDeclarations(Tokens $tokens) } else { $scopeEndIndex = $tokens->getNextTokenOfKind($declarationEndIndex, [[T_NAMESPACE]]); if (null === $scopeEndIndex) { - $scopeEndIndex = count($tokens); + $scopeEndIndex = \count($tokens); } --$scopeEndIndex; } @@ -59,8 +59,8 @@ public function getDeclarations(Tokens $tokens) ); } - if (0 === count($namespaces)) { - $namespaces[] = new NamespaceAnalysis('', '', 0, 0, 0, count($tokens) - 1); + if (0 === \count($namespaces)) { + $namespaces[] = new NamespaceAnalysis('', '', 0, 0, 0, \count($tokens) - 1); } return $namespaces; diff --git a/src/Tokenizer/Generator/NamespacedStringTokenGenerator.php b/src/Tokenizer/Generator/NamespacedStringTokenGenerator.php index c939cc9fa2f..aeb50c43c84 100644 --- a/src/Tokenizer/Generator/NamespacedStringTokenGenerator.php +++ b/src/Tokenizer/Generator/NamespacedStringTokenGenerator.php @@ -33,7 +33,7 @@ public function generate($input) foreach ($parts as $index => $part) { $tokens[] = new Token([T_STRING, $part]); - if ($index !== count($parts) - 1) { + if ($index !== \count($parts) - 1) { $tokens[] = new Token([T_NS_SEPARATOR, '\\']); } } diff --git a/src/Tokenizer/Resolver/TypeShortNameResolver.php b/src/Tokenizer/Resolver/TypeShortNameResolver.php index ee3ed213188..3c5a29e45c5 100644 --- a/src/Tokenizer/Resolver/TypeShortNameResolver.php +++ b/src/Tokenizer/Resolver/TypeShortNameResolver.php @@ -46,7 +46,7 @@ public function resolve(Tokens $tokens, $typeName) // Next try to match (partial) classes inside the same namespace // For now only support one namespace per file: $namespaces = $this->getNamespacesFromTokens($tokens); - if (1 === count($namespaces)) { + if (1 === \count($namespaces)) { foreach ($namespaces as $shortName => $fullName) { $matches = []; $regex = '/^\\\\?'.preg_quote($fullName, '/').'\\\\(?P.+)$/'; diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index 4d139f6afe8..33e26459ab4 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -55,18 +55,18 @@ class Token */ public function __construct($token) { - if (is_array($token)) { - if (!is_int($token[0])) { + if (\is_array($token)) { + if (!\is_int($token[0])) { throw new \InvalidArgumentException(sprintf( 'Id must be an int, got "%s".', - is_object($token[0]) ? get_class($token[0]) : gettype($token[0]) + \is_object($token[0]) ? \get_class($token[0]) : \gettype($token[0]) )); } - if (!is_string($token[1])) { + if (!\is_string($token[1])) { throw new \InvalidArgumentException(sprintf( 'Content must be a string, got "%s".', - is_object($token[1]) ? get_class($token[1]) : gettype($token[1]) + \is_object($token[1]) ? \get_class($token[1]) : \gettype($token[1]) )); } @@ -81,13 +81,13 @@ public function __construct($token) if ($token[0] && '' === $token[1]) { throw new \InvalidArgumentException('Cannot set empty content for id-based Token.'); } - } elseif (is_string($token)) { + } elseif (\is_string($token)) { $this->isArray = false; $this->content = $token; } else { throw new \InvalidArgumentException(sprintf( 'Cannot recognize input value as valid Token prototype, got "%s".', - is_object($token) ? get_class($token) : gettype($token) + \is_object($token) ? \get_class($token) : \gettype($token) )); } } @@ -158,7 +158,7 @@ public function equals($other, $caseSensitive = true) { $otherPrototype = $other instanceof self ? $other->getPrototype() : $other; - if ($this->isArray !== is_array($otherPrototype)) { + if ($this->isArray !== \is_array($otherPrototype)) { return false; } @@ -217,7 +217,7 @@ public function equalsAny(array $others, $caseSensitive = true) */ public static function isKeyCaseSensitive($caseSensitive, $key) { - if (is_array($caseSensitive)) { + if (\is_array($caseSensitive)) { return isset($caseSensitive[$key]) ? $caseSensitive[$key] : true; } @@ -430,7 +430,7 @@ public function isEmpty() */ public function isGivenKind($possibleKind) { - return $this->isArray && (is_array($possibleKind) ? in_array($this->id, $possibleKind, true) : $this->id === $possibleKind); + return $this->isArray && (\is_array($possibleKind) ? \in_array($this->id, $possibleKind, true) : $this->id === $possibleKind); } /** @@ -454,7 +454,7 @@ public function isNativeConstant() { static $nativeConstantStrings = ['true', 'false', 'null']; - return $this->isArray && in_array(strtolower($this->content), $nativeConstantStrings, true); + return $this->isArray && \in_array(strtolower($this->content), $nativeConstantStrings, true); } /** @@ -513,7 +513,7 @@ public function override($other) $this->changed = true; - if (is_array($prototype)) { + if (\is_array($prototype)) { $this->isArray = true; $this->id = $prototype[0]; $this->content = $prototype[1]; @@ -593,8 +593,8 @@ private static function getTokenKindsForNames(array $tokenNames) { $keywords = []; foreach ($tokenNames as $keywordName) { - if (defined($keywordName)) { - $keyword = constant($keywordName); + if (\defined($keywordName)) { + $keyword = \constant($keywordName); $keywords[$keyword] = $keyword; } } diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index c0f87b612ef..00a5c5f161e 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -174,7 +174,7 @@ public static function detectBlockType(Token $token) */ public static function fromArray($array, $saveIndexes = null) { - $tokens = new self(count($array)); + $tokens = new self(\count($array)); if (null === $saveIndexes || $saveIndexes) { foreach ($array as $key => $val) { @@ -388,7 +388,7 @@ public function ensureWhitespaceAtIndex($index, $indexOffset, $whitespace) if (0 === strpos($whitespace, "\r\n")) { $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent())."\r\n"]); - return strlen($whitespace) > 2 // can be removed on PHP 7; https://php.net/manual/en/function.substr.php + return \strlen($whitespace) > 2 // can be removed on PHP 7; https://php.net/manual/en/function.substr.php ? substr($whitespace, 2) : '' ; @@ -396,7 +396,7 @@ public function ensureWhitespaceAtIndex($index, $indexOffset, $whitespace) $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent()).$whitespace[0]]); - return strlen($whitespace) > 1 // can be removed on PHP 7; https://php.net/manual/en/function.substr.php + return \strlen($whitespace) > 1 // can be removed on PHP 7; https://php.net/manual/en/function.substr.php ? substr($whitespace, 1) : '' ; @@ -441,7 +441,7 @@ public function ensureWhitespaceAtIndex($index, $indexOffset, $whitespace) */ public function findBlockEnd($type, $searchIndex, $findEnd = true) { - if (3 === func_num_args()) { + if (3 === \func_num_args()) { if ($findEnd) { @trigger_error('Argument #3 of Tokens::findBlockEnd is deprecated and will be removed in 3.0, you can safely drop the argument.', E_USER_DEPRECATED); } else { @@ -490,7 +490,7 @@ public function findGivenKind($possibleKind, $start = 0, $end = null) }); } - if (count($possibleKinds)) { + if (\count($possibleKinds)) { for ($i = $start; $i < $end; ++$i) { $token = $this[$i]; if ($token->isGivenKind($possibleKinds)) { @@ -499,7 +499,7 @@ public function findGivenKind($possibleKind, $start = 0, $end = null) } } - return is_array($possibleKind) ? $elements : $elements[$possibleKind]; + return \is_array($possibleKind) ? $elements : $elements[$possibleKind]; } /** @@ -507,7 +507,7 @@ public function findGivenKind($possibleKind, $start = 0, $end = null) */ public function generateCode() { - $code = $this->generatePartialCode(0, count($this) - 1); + $code = $this->generatePartialCode(0, \count($this) - 1); $this->changeCodeHash(self::calculateCodeHash($code)); return $code; @@ -647,7 +647,7 @@ public function getTokenOfKindSibling($index, $direction, array $tokens = [], $c }); } - if (!count($tokens)) { + if (!\count($tokens)) { return null; } @@ -774,13 +774,13 @@ public function getPrevMeaningfulToken($index) */ public function findSequence(array $sequence, $start = 0, $end = null, $caseSensitive = true) { - $sequenceCount = count($sequence); + $sequenceCount = \count($sequence); if (0 === $sequenceCount) { throw new \InvalidArgumentException('Invalid sequence.'); } // $end defaults to the end of the collection - $end = null === $end ? count($this) - 1 : min($end, count($this) - 1); + $end = null === $end ? \count($this) - 1 : min($end, \count($this) - 1); if ($start + $sequenceCount - 1 > $end) { return null; @@ -790,7 +790,7 @@ public function findSequence(array $sequence, $start = 0, $end = null, $caseSens foreach ($sequence as $key => $token) { // if not a Token instance already, we convert it to verify the meaningfulness if (!$token instanceof Token) { - if (is_array($token) && !isset($token[1])) { + if (\is_array($token) && !isset($token[1])) { // fake some content as it is required by the Token constructor, // although optional for search purposes $token[1] = 'DUMMY'; @@ -854,7 +854,7 @@ public function findSequence(array $sequence, $start = 0, $end = null, $caseSens // do we have a complete match? // hint: $result is bigger than $sequence since the first token has been removed from the latter - if (count($sequence) < count($result)) { + if (\count($sequence) < \count($result)) { return $result; } } @@ -868,14 +868,14 @@ public function findSequence(array $sequence, $start = 0, $end = null, $caseSens */ public function insertAt($index, $items) { - $items = is_array($items) || $items instanceof self ? $items : [$items]; - $itemsCnt = count($items); + $items = \is_array($items) || $items instanceof self ? $items : [$items]; + $itemsCnt = \count($items); if (0 === $itemsCnt) { return; } - $oldSize = count($this); + $oldSize = \count($this); $this->changed = true; $this->setSize($oldSize + $itemsCnt); @@ -970,7 +970,7 @@ public function overrideRange($indexStart, $indexEnd, $items) } $indexToChange = $indexEnd - $indexStart + 1; - $itemsCount = count($items); + $itemsCount = \count($items); // If we want to add more items than passed range contains we need to // add placeholders for overhead items. @@ -1029,11 +1029,11 @@ public function setCode($code) // clear memory $this->setSize(0); - $tokens = defined('TOKEN_PARSE') + $tokens = \defined('TOKEN_PARSE') ? token_get_all($code, TOKEN_PARSE) : token_get_all($code); - $this->setSize(count($tokens)); + $this->setSize(\count($tokens)); foreach ($tokens as $index => $token) { $this[$index] = new Token($token); @@ -1060,7 +1060,7 @@ public function toJson() $options = Utils::calculateBitmask(['JSON_PRETTY_PRINT', 'JSON_NUMERIC_CHECK']); } - $output = new \SplFixedArray(count($this)); + $output = new \SplFixedArray(\count($this)); foreach ($this as $index => $token) { $output[$index] = $token->toArray(); @@ -1206,7 +1206,7 @@ public function isPartialCodeMultiline($start, $end) */ public function clearTokenAndMergeSurroundingWhitespace($index) { - $count = count($this); + $count = \count($this); $this->clearAt($index); if ($index === $count - 1) { @@ -1430,7 +1430,7 @@ private function extractTokenKind($token) { return $token instanceof Token ? ($token->isArray() ? $token->getId() : $token->getContent()) - : (is_array($token) ? $token[0] : $token) + : (\is_array($token) ? $token[0] : $token) ; } } diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index bf7b694335f..c2e1657403b 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -47,7 +47,7 @@ public function getClassyElements() $this->tokens->rewind(); $elements = []; - for ($index = 1, $count = count($this->tokens) - 2; $index < $count; ++$index) { + for ($index = 1, $count = \count($this->tokens) - 2; $index < $count; ++$index) { if ($this->tokens[$index]->isClassy()) { list($index, $newElements) = $this->findClassyElements($index); $elements += $newElements; @@ -469,11 +469,11 @@ public function isBinaryOperator($index) CT::T_TYPE_ALTERNATION => true, // | ]; - if (defined('T_SPACESHIP')) { + if (\defined('T_SPACESHIP')) { $arrayOperators[T_SPACESHIP] = true; // <=> } - if (defined('T_COALESCE')) { + if (\defined('T_COALESCE')) { $arrayOperators[T_COALESCE] = true; // ?? } } @@ -542,7 +542,7 @@ private function findClassyElements($index) $classIndex = $index; ++$index; // skip the classy index itself - for ($count = count($this->tokens); $index < $count; ++$index) { + for ($count = \count($this->tokens); $index < $count; ++$index) { $token = $this->tokens[$index]; if ($token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) { diff --git a/src/Tokenizer/Transformer/WhitespacyCommentTransformer.php b/src/Tokenizer/Transformer/WhitespacyCommentTransformer.php index 45b01b80299..9878ff333ad 100644 --- a/src/Tokenizer/Transformer/WhitespacyCommentTransformer.php +++ b/src/Tokenizer/Transformer/WhitespacyCommentTransformer.php @@ -58,7 +58,7 @@ public function process(Tokens $tokens, Token $token, $index) return; } - $whitespaces = substr($content, strlen($trimmedContent)); + $whitespaces = substr($content, \strlen($trimmedContent)); $tokens[$index] = new Token([$token->getId(), $trimmedContent]); diff --git a/src/ToolInfo.php b/src/ToolInfo.php index 7a67c587ca5..5e4ff462bc4 100644 --- a/src/ToolInfo.php +++ b/src/ToolInfo.php @@ -47,7 +47,7 @@ public function getComposerInstallationDetails() $composerInstalled = json_decode(file_get_contents($this->getComposerInstalledFile()), true); foreach ($composerInstalled as $package) { - if (in_array($package['name'], [self::COMPOSER_PACKAGE_NAME, self::COMPOSER_LEGACY_PACKAGE_NAME], true)) { + if (\in_array($package['name'], [self::COMPOSER_PACKAGE_NAME, self::COMPOSER_LEGACY_PACKAGE_NAME], true)) { $this->composerInstallationDetails = $package; break; diff --git a/src/Utils.php b/src/Utils.php index 1ba8b78765f..5b1016a816b 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -36,8 +36,8 @@ public static function calculateBitmask(array $options) $bitmask = 0; foreach ($options as $optionName) { - if (defined($optionName)) { - $bitmask |= constant($optionName); + if (\defined($optionName)) { + $bitmask |= \constant($optionName); } } diff --git a/src/WhitespacesFixerConfig.php b/src/WhitespacesFixerConfig.php index 68912bf5a4c..93ad5f433b6 100644 --- a/src/WhitespacesFixerConfig.php +++ b/src/WhitespacesFixerConfig.php @@ -26,11 +26,11 @@ final class WhitespacesFixerConfig */ public function __construct($indent = ' ', $lineEnding = "\n") { - if (!in_array($indent, [' ', ' ', "\t"], true)) { + if (!\in_array($indent, [' ', ' ', "\t"], true)) { throw new \InvalidArgumentException('Invalid "indent" param, expected tab or two or four spaces.'); } - if (!in_array($lineEnding, ["\n", "\r\n"], true)) { + if (!\in_array($lineEnding, ["\n", "\r\n"], true)) { throw new \InvalidArgumentException('Invalid "lineEnding" param, expected "\n" or "\r\n".'); } diff --git a/src/WordMatcher.php b/src/WordMatcher.php index 02b98450c9b..d0f529d6b08 100644 --- a/src/WordMatcher.php +++ b/src/WordMatcher.php @@ -41,7 +41,7 @@ public function __construct(array $candidates) public function match($needle) { $word = null; - $distance = ceil(strlen($needle) * 0.35); + $distance = ceil(\strlen($needle) * 0.35); foreach ($this->candidates as $candidate) { $candidateDistance = levenshtein($needle, $candidate); diff --git a/tests/AutoReview/CommandTest.php b/tests/AutoReview/CommandTest.php index 245abb7ae8d..0e748ef15ca 100644 --- a/tests/AutoReview/CommandTest.php +++ b/tests/AutoReview/CommandTest.php @@ -34,7 +34,7 @@ final class CommandTest extends TestCase */ public function testCommandHasNameConst(Command $command) { - $this->assertSame($command->getName(), constant(get_class($command).'::COMMAND_NAME')); + $this->assertSame($command->getName(), \constant(\get_class($command).'::COMMAND_NAME')); } public function provideCommandHasNameConstCases() @@ -45,9 +45,9 @@ public function provideCommandHasNameConstCases() $names = array_filter(array_keys($commands), static function ($name) use ($commands) { return // is not an alias - !in_array($name, $commands[$name]->getAliases(), true) + !\in_array($name, $commands[$name]->getAliases(), true) // and is our command - && 0 === strpos(get_class($commands[$name]), 'PhpCsFixer\\') + && 0 === strpos(\get_class($commands[$name]), 'PhpCsFixer\\') ; }); diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index fb2bc4c33ca..05ba4f8cf2d 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -35,7 +35,7 @@ public function testFixersPriorityEdgeFixers() $this->assertSame('encoding', $fixers[0]->getName(), 'Expected "encoding" fixer to have the highest priority.'); $this->assertSame('full_opening_tag', $fixers[1]->getName(), 'Expected "full_opening_tag" fixer has second highest priority.'); - $this->assertSame('single_blank_line_at_eof', $fixers[count($fixers) - 1]->getName(), 'Expected "single_blank_line_at_eof" to have the lowest priority.'); + $this->assertSame('single_blank_line_at_eof', $fixers[\count($fixers) - 1]->getName(), 'Expected "single_blank_line_at_eof" to have the lowest priority.'); } /** @@ -44,7 +44,7 @@ public function testFixersPriorityEdgeFixers() */ public function testFixersPriority(FixerInterface $first, FixerInterface $second) { - $this->assertLessThan($first->getPriority(), $second->getPriority(), sprintf('"%s" should have less priority than "%s"', get_class($second), get_class($first))); + $this->assertLessThan($first->getPriority(), $second->getPriority(), sprintf('"%s" should have less priority than "%s"', \get_class($second), \get_class($first))); } public function provideFixersPriorityCases() @@ -241,7 +241,7 @@ static function ($name) { ); foreach ($docFixerNames as $docFixerName) { - if (!in_array($docFixerName, ['comment_to_phpdoc', 'phpdoc_to_comment', 'phpdoc_indent', 'phpdoc_types', 'phpdoc_scalar'], true)) { + if (!\in_array($docFixerName, ['comment_to_phpdoc', 'phpdoc_to_comment', 'phpdoc_indent', 'phpdoc_types', 'phpdoc_scalar'], true)) { $cases[] = [$fixers['comment_to_phpdoc'], $fixers[$docFixerName]]; $cases[] = [$fixers['phpdoc_indent'], $fixers[$docFixerName]]; $cases[] = [$fixers['phpdoc_scalar'], $fixers[$docFixerName]]; @@ -285,7 +285,7 @@ public function testFixersPriorityPairsHaveIntegrationTest(FixerInterface $first $integrationTestExists = $this->doesIntegrationTestExist($first, $second); - if (in_array($this->generateIntegrationTestName($first, $second), $casesWithoutTests, true)) { + if (\in_array($this->generateIntegrationTestName($first, $second), $casesWithoutTests, true)) { $this->assertFalse($integrationTestExists, sprintf('Case "%s" already has an integration test, so it should be removed from "$casesWithoutTests".', $this->generateIntegrationTestName($first, $second))); $this->markTestIncomplete(sprintf('Case "%s" has no integration test yet, please help and add it.', $this->generateIntegrationTestName($first, $second))); } @@ -299,7 +299,7 @@ public function provideFixersPriorityPairsHaveIntegrationTestCases() $this->provideFixersPriorityCases(), // ignore speed-up only priorities set up function (array $case) { - return !in_array( + return !\in_array( $this->generateIntegrationTestName($case[0], $case[1]), [ 'function_to_constant,native_function_casing.test', @@ -352,13 +352,13 @@ public function testPriorityIntegrationTestFilesAreListedPriorityCases($fileName ksort($priorityCases); } - if (in_array($fileName, [ + if (\in_array($fileName, [ 'braces,indentation_type,no_break_comment.test', ], true)) { $this->markTestIncomplete(sprintf('Case "%s" has unexpected name, please help fixing it.', $fileName)); } - if (in_array($fileName, [ + if (\in_array($fileName, [ 'combine_consecutive_issets,no_singleline_whitespace_before_semicolons.test', ], true)) { $this->markTestIncomplete(sprintf('Case "%s" is not fully handled, please help fixing it.', $fileName)); diff --git a/tests/AutoReview/FixerTest.php b/tests/AutoReview/FixerTest.php index b46002af850..d6953e066e7 100644 --- a/tests/AutoReview/FixerTest.php +++ b/tests/AutoReview/FixerTest.php @@ -114,7 +114,7 @@ public function testFixerDefinitions(FixerInterface $fixer) $duplicatedCodeSample = array_search( $sample, - array_slice($samples, 0, $sampleCounter), + \array_slice($samples, 0, $sampleCounter), false ); @@ -136,7 +136,7 @@ public function testFixerDefinitions(FixerInterface $fixer) foreach ($options as $option) { // @TODO 2.12 adjust fixers to use new casing and deprecate old one - if (in_array($fixerName, [ + if (\in_array($fixerName, [ 'final_internal_class', 'ordered_class_elements', ], true)) { @@ -210,7 +210,7 @@ public function testDeprecatedFixersHaveCorrectSummary(FixerInterface $fixer) if ($fixer instanceof DeprecatedFixerInterface) { $this->assertContains('@deprecated', $comment); - } elseif (is_string($comment)) { + } elseif (\is_string($comment)) { $this->assertNotContains('@deprecated', $comment); } } diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 1671b02be86..cde160334ca 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -72,7 +72,7 @@ public function testThatSrcClassHaveTestClass($className) { $testClassName = str_replace('PhpCsFixer', 'PhpCsFixer\\Tests', $className).'Test'; - if (in_array($className, self::$classesWithoutTests, true)) { + if (\in_array($className, self::$classesWithoutTests, true)) { $this->assertFalse(class_exists($testClassName), sprintf('Class "%s" already has tests, so it should be removed from "%s::$classesWithoutTests".', $className, __CLASS__)); $this->markTestIncomplete(sprintf('Class "%s" has no tests yet, please help and add it.', $className)); } @@ -97,7 +97,7 @@ function (\ReflectionClass $interface) { $rc->getInterfaces() ); - if (count($allowedMethods)) { + if (\count($allowedMethods)) { $allowedMethods = array_unique(array_merge(...array_values($allowedMethods))); } @@ -319,9 +319,9 @@ static function ($item) { if ( $rc->isInterface() - || ($doc && count($doc->getAnnotationsOfType('internal'))) - || 0 === count($rc->getInterfaces()) - || in_array($className, [ + || ($doc && \count($doc->getAnnotationsOfType('internal'))) + || 0 === \count($rc->getInterfaces()) + || \in_array($className, [ \PhpCsFixer\Finder::class, \PhpCsFixer\Test\AbstractFixerTestCase::class, \PhpCsFixer\Test\AbstractIntegrationTestCase::class, @@ -365,7 +365,7 @@ static function ($item) { public function provideClassesWherePregFunctionsAreForbiddenCases() { - if ((extension_loaded('xdebug') || 'phpdbg' === PHP_SAPI) && false === getenv('CI')) { + if ((\extension_loaded('xdebug') || 'phpdbg' === PHP_SAPI) && false === getenv('CI')) { $this->markTestSkipped('Data provider too slow when Xdebug is loaded or running under phpdbg.'); } diff --git a/tests/Console/Command/DescribeCommandTest.php b/tests/Console/Command/DescribeCommandTest.php index dab8901ad19..c9e1ff2dcf5 100644 --- a/tests/Console/Command/DescribeCommandTest.php +++ b/tests/Console/Command/DescribeCommandTest.php @@ -205,7 +205,7 @@ public function testFixerClassNameIsExposedWhenVerbose() ] ); - $this->assertContains(get_class($mock), $commandTester->getDisplay(true)); + $this->assertContains(\get_class($mock), $commandTester->getDisplay(true)); } /** diff --git a/tests/Console/ConfigurationResolverTest.php b/tests/Console/ConfigurationResolverTest.php index c82d13b6f40..361628627a5 100644 --- a/tests/Console/ConfigurationResolverTest.php +++ b/tests/Console/ConfigurationResolverTest.php @@ -336,7 +336,7 @@ public function testResolvePathRelativeB() $resolver = $this->createConfigurationResolver( ['path' => [basename(__DIR__)]], null, - dirname(__DIR__) + \dirname(__DIR__) ); $this->assertSame([__DIR__], $resolver->getPath()); @@ -374,7 +374,7 @@ public function testResolvePathWithFileThatIsExcludedDirectlyIntersectionPathMod public function testResolvePathWithFileThatIsExcludedByDirOverridePathMode() { - $dir = dirname(__DIR__); + $dir = \dirname(__DIR__); $config = new Config(); $config->getFinder() ->in($dir) @@ -390,7 +390,7 @@ public function testResolvePathWithFileThatIsExcludedByDirOverridePathMode() public function testResolvePathWithFileThatIsExcludedByDirIntersectionPathMode() { - $dir = dirname(__DIR__); + $dir = \dirname(__DIR__); $config = new Config(); $config->getFinder() ->in($dir) @@ -431,7 +431,7 @@ public function testResolvePathWithFileThatIsNotExcluded() public function testResolveIntersectionOfPaths($expected, $configFinder, array $path, $pathMode, $configOption = null) { if ($expected instanceof \Exception) { - $this->expectException(get_class($expected)); + $this->expectException(\get_class($expected)); } if (null !== $configFinder) { diff --git a/tests/Console/Output/ErrorOutputTest.php b/tests/Console/Output/ErrorOutputTest.php index a3e79886c45..368a4f56cd0 100644 --- a/tests/Console/Output/ErrorOutputTest.php +++ b/tests/Console/Output/ErrorOutputTest.php @@ -65,7 +65,7 @@ public function testErrorOutput(Error $error, $verbosityLevel, $lineNumber, $exc %s (%d) '.' '.' ', - get_class($source), + \get_class($source), $source->getMessage(), $source->getCode() ); diff --git a/tests/Fixer/Basic/Psr0FixerTest.php b/tests/Fixer/Basic/Psr0FixerTest.php index 045b903b5df..3e2fa11d06d 100644 --- a/tests/Fixer/Basic/Psr0FixerTest.php +++ b/tests/Fixer/Basic/Psr0FixerTest.php @@ -243,7 +243,7 @@ public function provideIgnoredCases() 'T_TRAIT' => 'trait', 'T_TRAIT_C' => '__TRAIT__', ] as $tokenType => $tokenValue) { - if (defined($tokenType)) { + if (\defined($tokenType)) { $ignoreCases[] = [$tokenValue.'.php']; $ignoreCases[] = [strtolower($tokenValue).'.php']; } diff --git a/tests/Fixer/Basic/Psr4FixerTest.php b/tests/Fixer/Basic/Psr4FixerTest.php index a4cadcba0a9..2bc76d7d539 100644 --- a/tests/Fixer/Basic/Psr4FixerTest.php +++ b/tests/Fixer/Basic/Psr4FixerTest.php @@ -230,7 +230,7 @@ public function provideIgnoredCases() 'T_TRAIT' => 'trait', 'T_TRAIT_C' => '__TRAIT__', ] as $tokenType => $tokenValue) { - if (defined($tokenType)) { + if (\defined($tokenType)) { $ignoreCases[] = [$tokenValue.'.php']; $ignoreCases[] = [strtolower($tokenValue).'.php']; } diff --git a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php index 140547dc0eb..7030da01f15 100644 --- a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php @@ -50,7 +50,7 @@ public function testConfigureRejectsInvalidConfigurationValue($value) $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( 'expected to be of type "bool", but is of type "%s".', - is_object($value) ? get_class($value) : gettype($value) + \is_object($value) ? \get_class($value) : \gettype($value) )); $this->fixer->configure([ diff --git a/tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php index 29dbe556e1d..0e15262803a 100644 --- a/tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php @@ -93,13 +93,13 @@ public function provideFixCases() // invalid char inside line won't crash the fixer 'provideMessyWhitespacesCases(), static function ($key) { - return !is_string($key) || false === strpos($key, 'mix indentation'); + return !\is_string($key) || false === strpos($key, 'mix indentation'); }, ARRAY_FILTER_USE_KEY ); diff --git a/tests/FixerFactoryTest.php b/tests/FixerFactoryTest.php index 1c52dae9b87..cd069c2830e 100644 --- a/tests/FixerFactoryTest.php +++ b/tests/FixerFactoryTest.php @@ -71,7 +71,7 @@ public function testRegisterBuiltInFixers() $factory = new FixerFactory(); $factory->registerBuiltInFixers(); - $this->assertGreaterThan(0, count($factory->getFixers())); + $this->assertGreaterThan(0, \count($factory->getFixers())); } /** @@ -92,7 +92,7 @@ public function testThatFixersAreSorted() } // There are no rules that forces $fxs[1] to be prioritized before $fxs[3]. We should not test against that - $this->assertSame([$fxs[2], $fxs[0]], array_slice($factory->getFixers(), 0, 2)); + $this->assertSame([$fxs[2], $fxs[0]], \array_slice($factory->getFixers(), 0, 2)); } /** @@ -111,9 +111,9 @@ public function testThatCanRegisterAndGetFixers() $factory->registerFixer($f1, false); $factory->registerCustomFixers([$f2, $f3]); - $this->assertTrue(in_array($f1, $factory->getFixers(), true)); - $this->assertTrue(in_array($f2, $factory->getFixers(), true)); - $this->assertTrue(in_array($f3, $factory->getFixers(), true)); + $this->assertTrue(\in_array($f1, $factory->getFixers(), true)); + $this->assertTrue(\in_array($f2, $factory->getFixers(), true)); + $this->assertTrue(\in_array($f3, $factory->getFixers(), true)); } /** diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 56372dea29a..81ad023cc98 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -67,7 +67,7 @@ protected static function assertRevertedOrderFixing(IntegrationCase $case, $fixe if ($settings['isExplicitPriorityCheck']) { if ($fixedInputCode === $fixedInputCodeWithReversedFixers) { - if (in_array($case->getFileName(), [ + if (\in_array($case->getFileName(), [ 'priority'.DIRECTORY_SEPARATOR.'backtick_to_shell_exec,escape_implicit_backslashes.test', 'priority'.DIRECTORY_SEPARATOR.'braces,indentation_type,no_break_comment.test', 'priority'.DIRECTORY_SEPARATOR.'standardize_not_equals,binary_operator_spaces.test', diff --git a/tests/Linter/LinterTest.php b/tests/Linter/LinterTest.php index 68867136ab8..0663a04eb97 100644 --- a/tests/Linter/LinterTest.php +++ b/tests/Linter/LinterTest.php @@ -25,7 +25,7 @@ final class LinterTest extends AbstractLinterTestCase { public function testIsAsync() { - $this->assertSame(!defined('TOKEN_PARSE'), $this->createLinter()->isAsync()); + $this->assertSame(!\defined('TOKEN_PARSE'), $this->createLinter()->isAsync()); } /** diff --git a/tests/PregTest.php b/tests/PregTest.php index 70eb1ef1697..fa57c9553ef 100644 --- a/tests/PregTest.php +++ b/tests/PregTest.php @@ -138,9 +138,9 @@ public function provideCommonCases() return [ ['/u/u', 'u'], ['/u/u', 'u/u'], - ['/./', chr(224).'bc'], + ['/./', \chr(224).'bc'], ['/à/', 'àbc'], - ['/'.chr(224).'|í/', 'àbc'], + ['/'.\chr(224).'|í/', 'àbc'], ]; } @@ -148,7 +148,7 @@ public function provideArrayOfPatternsCases() { return [ [['/à/', '/í/'], 'Tàíl'], - [['/'.chr(174).'/', '/'.chr(224).'/'], 'foo'], + [['/'.\chr(174).'/', '/'.\chr(224).'/'], 'foo'], ]; } @@ -192,12 +192,12 @@ public function testCorrectnessForUtf8String() public function testCorrectnessForNonUtf8String() { $pattern = '/./u'; - $subject = chr(224).'bc'; + $subject = \chr(224).'bc'; Preg::match($pattern, $subject, $methodMatches); preg_match($pattern, $subject, $functionMatches); - $this->assertSame([chr(224)], $methodMatches); - $this->assertNotSame([chr(224)], $functionMatches); + $this->assertSame([\chr(224)], $methodMatches); + $this->assertNotSame([\chr(224)], $functionMatches); } } diff --git a/tests/RuleSetTest.php b/tests/RuleSetTest.php index ac5f851606d..7bebd8ea2d3 100644 --- a/tests/RuleSetTest.php +++ b/tests/RuleSetTest.php @@ -542,7 +542,7 @@ private function sort(array &$data) } foreach ($data as $key => $value) { - if (is_array($value)) { + if (\is_array($value)) { $this->sort($data[$key]); } } @@ -556,7 +556,7 @@ private function sort(array &$data) private function allInteger(array $values) { foreach ($values as $value) { - if (!is_int($value)) { + if (!\is_int($value)) { return false; } } diff --git a/tests/Smoke/CiIntegrationTest.php b/tests/Smoke/CiIntegrationTest.php index 4ef79689bd4..2c47dd57d50 100644 --- a/tests/Smoke/CiIntegrationTest.php +++ b/tests/Smoke/CiIntegrationTest.php @@ -141,7 +141,7 @@ public function testIntegration( preg_quote($optionalIncompatibilityWarning, '/'), preg_quote($optionalXdebugWarning, '/'), preg_quote('Loaded config default from ".php_cs.dist".', '/'), - strlen($expectedResult3Files), + \strlen($expectedResult3Files), preg_quote('Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error', '/') ); diff --git a/tests/Test/AbstractFixerTestCase.php b/tests/Test/AbstractFixerTestCase.php index eb8b8afb117..e35148effa0 100644 --- a/tests/Test/AbstractFixerTestCase.php +++ b/tests/Test/AbstractFixerTestCase.php @@ -138,8 +138,8 @@ protected function doTest($expected, $input = null, \SplFileInfo $file = null) $tokens->clearEmptyTokens(); $this->assertSame( - count($tokens), - count(array_unique(array_map(static function (Token $token) { + \count($tokens), + \count(array_unique(array_map(static function (Token $token) { return spl_object_hash($token); }, $tokens->toArray()))), 'Token items inside Tokens collection must be unique.' diff --git a/tests/Test/AbstractIntegrationCaseFactory.php b/tests/Test/AbstractIntegrationCaseFactory.php index b2cee334346..c24fe493bcd 100644 --- a/tests/Test/AbstractIntegrationCaseFactory.php +++ b/tests/Test/AbstractIntegrationCaseFactory.php @@ -91,17 +91,17 @@ protected function determineConfig(SplFileInfo $file, $config) 'lineEnding' => "\n", ]); - if (!is_string($parsed['indent'])) { + if (!\is_string($parsed['indent'])) { throw new \InvalidArgumentException(sprintf( 'Expected string value for "indent", got "%s".', - is_object($parsed['indent']) ? get_class($parsed['indent']) : gettype($parsed['indent']).'#'.$parsed['indent'] + \is_object($parsed['indent']) ? \get_class($parsed['indent']) : \gettype($parsed['indent']).'#'.$parsed['indent'] )); } - if (!is_string($parsed['lineEnding'])) { + if (!\is_string($parsed['lineEnding'])) { throw new \InvalidArgumentException(sprintf( 'Expected string value for "lineEnding", got "%s".', - is_object($parsed['lineEnding']) ? get_class($parsed['lineEnding']) : gettype($parsed['lineEnding']).'#'.$parsed['lineEnding'] + \is_object($parsed['lineEnding']) ? \get_class($parsed['lineEnding']) : \gettype($parsed['lineEnding']).'#'.$parsed['lineEnding'] )); } @@ -122,10 +122,10 @@ protected function determineRequirements(SplFileInfo $file, $config) 'php' => PHP_VERSION_ID, ]); - if (!is_int($parsed['php'])) { + if (!\is_int($parsed['php'])) { throw new \InvalidArgumentException(sprintf( 'Expected int value like 50509 for "php", got "%s".', - is_object($parsed['php']) ? get_class($parsed['php']) : gettype($parsed['php']).'#'.$parsed['php'] + \is_object($parsed['php']) ? \get_class($parsed['php']) : \gettype($parsed['php']).'#'.$parsed['php'] )); } @@ -172,10 +172,10 @@ protected function determineSettings(SplFileInfo $file, $config) 'checkPriority' => true, ]); - if (!is_bool($parsed['checkPriority'])) { + if (!\is_bool($parsed['checkPriority'])) { throw new \InvalidArgumentException(sprintf( 'Expected bool value for "checkPriority", got "%s".', - is_object($parsed['checkPriority']) ? get_class($parsed['checkPriority']) : gettype($parsed['checkPriority']).'#'.$parsed['checkPriority'] + \is_object($parsed['checkPriority']) ? \get_class($parsed['checkPriority']) : \gettype($parsed['checkPriority']).'#'.$parsed['checkPriority'] )); } diff --git a/tests/Test/AbstractIntegrationTestCase.php b/tests/Test/AbstractIntegrationTestCase.php index 51f85e663eb..45f3e02dc42 100644 --- a/tests/Test/AbstractIntegrationTestCase.php +++ b/tests/Test/AbstractIntegrationTestCase.php @@ -83,7 +83,7 @@ public static function setUpBeforeClass() self::$fileRemoval->observe($tmpFile); if (!is_file($tmpFile)) { - $dir = dirname($tmpFile); + $dir = \dirname($tmpFile); if (!is_dir($dir)) { $fs = new Filesystem(); @@ -275,7 +275,7 @@ protected function doTest(IntegrationCase $case) ) ); - if (1 < count($fixers)) { + if (1 < \count($fixers)) { $tmpFile = static::getTempFile(); if (false === @file_put_contents($tmpFile, $input)) { throw new IOException(sprintf('Failed to write to tmp. file "%s".', $tmpFile)); @@ -326,7 +326,7 @@ protected static function assertRevertedOrderFixing(IntegrationCase $case, $fixe if ($fixedInputCode !== $fixedInputCodeWithReversedFixers) { static::assertGreaterThan( 1, - count(array_unique(array_map( + \count(array_unique(array_map( static function (FixerInterface $fixer) { return $fixer->getPriority(); }, diff --git a/tests/Test/AbstractTransformerTestCase.php b/tests/Test/AbstractTransformerTestCase.php index 6c6491a9d5e..33ed581685d 100644 --- a/tests/Test/AbstractTransformerTestCase.php +++ b/tests/Test/AbstractTransformerTestCase.php @@ -46,12 +46,12 @@ protected function doTest($source, array $expectedTokens = [], array $observedKi $tokens = Tokens::fromCode($source); $this->assertSame( - count($expectedTokens), + \count($expectedTokens), $this->countTokenPrototypes( $tokens, array_map( static function ($kindOrPrototype) { - return is_int($kindOrPrototype) ? [$kindOrPrototype] : $kindOrPrototype; + return \is_int($kindOrPrototype) ? [$kindOrPrototype] : $kindOrPrototype; }, array_unique(array_merge($observedKindsOrPrototypes, $expectedTokens)) ) @@ -60,7 +60,7 @@ static function ($kindOrPrototype) { ); foreach ($expectedTokens as $index => $tokenIdOrContent) { - if (is_string($tokenIdOrContent)) { + if (\is_string($tokenIdOrContent)) { $this->assertTrue($tokens[$index]->equals($tokenIdOrContent)); continue; diff --git a/tests/Test/Assert/AssertTokensTrait.php b/tests/Test/Assert/AssertTokensTrait.php index d5769d531b8..1a6232ae059 100644 --- a/tests/Test/Assert/AssertTokensTrait.php +++ b/tests/Test/Assert/AssertTokensTrait.php @@ -40,7 +40,7 @@ private function assertTokens(Tokens $expectedTokens, Tokens $inputTokens) sprintf( 'The token kind %s (%s) must be found in tokens collection.', $expectedTokenKind, - is_string($expectedTokenKind) ? $expectedTokenKind : Token::getNameForId($expectedTokenKind) + \is_string($expectedTokenKind) ? $expectedTokenKind : Token::getNameForId($expectedTokenKind) ) ); } diff --git a/tests/Test/IntegrationCase.php b/tests/Test/IntegrationCase.php index 58abb33c8fc..a5859cc3b58 100644 --- a/tests/Test/IntegrationCase.php +++ b/tests/Test/IntegrationCase.php @@ -124,10 +124,10 @@ public function getInputCode() */ public function getRequirement($name) { - if (!is_string($name)) { + if (!\is_string($name)) { throw new \InvalidArgumentException(sprintf( 'Requirement key must be a string, got "%s".', - is_object($name) ? get_class($name) : gettype($name).'#'.$name + \is_object($name) ? \get_class($name) : \gettype($name).'#'.$name )); } diff --git a/tests/Test/InternalIntegrationCaseFactory.php b/tests/Test/InternalIntegrationCaseFactory.php index 912f98e87c6..cdd2c862260 100644 --- a/tests/Test/InternalIntegrationCaseFactory.php +++ b/tests/Test/InternalIntegrationCaseFactory.php @@ -28,7 +28,7 @@ protected function determineSettings(SplFileInfo $file, $config) { $parsed = parent::determineSettings($file, $config); - $parsed['isExplicitPriorityCheck'] = in_array('priority', explode(DIRECTORY_SEPARATOR, $file->getRelativePathname()), true); + $parsed['isExplicitPriorityCheck'] = \in_array('priority', explode(DIRECTORY_SEPARATOR, $file->getRelativePathname()), true); return $parsed; } diff --git a/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php b/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php index f167bbde681..1395c607789 100644 --- a/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php @@ -40,7 +40,7 @@ public function testArguments($code, $openIndex, $closeIndex, array $arguments) $tokens = Tokens::fromCode($code); $analyzer = new ArgumentsAnalyzer(); - $this->assertSame(count($arguments), $analyzer->countArguments($tokens, $openIndex, $closeIndex)); + $this->assertSame(\count($arguments), $analyzer->countArguments($tokens, $openIndex, $closeIndex)); $this->assertSame($arguments, $analyzer->getArguments($tokens, $openIndex, $closeIndex)); } diff --git a/tests/Tokenizer/CTTest.php b/tests/Tokenizer/CTTest.php index f76fac5c604..110c5319299 100644 --- a/tests/Tokenizer/CTTest.php +++ b/tests/Tokenizer/CTTest.php @@ -74,7 +74,7 @@ public function testGetNameNotExists() public function testConstants($name, $value) { $this->assertGreaterThan(10000, $value); - $this->assertNull(@constant($name), 'The CT name must not use native T_* name.'); + $this->assertNull(@\constant($name), 'The CT name must not use native T_* name.'); } public function provideConstantsCases() diff --git a/tests/Tokenizer/TokensAnalyzerTest.php b/tests/Tokenizer/TokensAnalyzerTest.php index 80c059f6619..53ef2e67a6d 100644 --- a/tests/Tokenizer/TokensAnalyzerTest.php +++ b/tests/Tokenizer/TokensAnalyzerTest.php @@ -896,7 +896,7 @@ public function testIsArray71($source, $tokenIndexes) $tokensAnalyzer = new TokensAnalyzer($tokens); foreach ($tokens as $index => $token) { - $expect = in_array($index, $tokenIndexes, true); + $expect = \in_array($index, $tokenIndexes, true); $this->assertSame( $expect, $tokensAnalyzer->isArray($index), diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index 3456c9183bc..f82c62dd028 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -522,7 +522,7 @@ public function bar() public function testClearTokenAndMergeSurroundingWhitespace($source, array $indexes, array $expected) { $this->doTestClearTokens($source, $indexes, $expected); - if (count($indexes) > 1) { + if (\count($indexes) > 1) { $this->doTestClearTokens($source, array_reverse($indexes), $expected); } } @@ -867,7 +867,7 @@ public function testClone() $this->assertTrue($tokens->isTokenKindFound(T_OPEN_TAG)); $this->assertTrue($tokensClone->isTokenKindFound(T_OPEN_TAG)); - $count = count($tokens); + $count = \count($tokens); $this->assertCount($count, $tokensClone); for ($i = 0; $i < $count; ++$i) { @@ -1213,11 +1213,11 @@ private function doTestClearTokens($source, array $indexes, array $expected) $tokens->clearTokenAndMergeSurroundingWhitespace($index); } - $this->assertSame(count($expected), $tokens->count()); + $this->assertSame(\count($expected), $tokens->count()); foreach ($expected as $index => $expectedToken) { $token = $tokens[$index]; $expectedPrototype = $expectedToken->getPrototype(); - if (is_array($expectedPrototype)) { + if (\is_array($expectedPrototype)) { unset($expectedPrototype[2]); // don't compare token lines as our token mutations don't deal with line numbers } diff --git a/tests/Tokenizer/Transformer/SquareBraceTransformerTest.php b/tests/Tokenizer/Transformer/SquareBraceTransformerTest.php index c62a801168a..8f1be0be792 100644 --- a/tests/Tokenizer/Transformer/SquareBraceTransformerTest.php +++ b/tests/Tokenizer/Transformer/SquareBraceTransformerTest.php @@ -49,7 +49,7 @@ public function testIsShortArray($source, $inspectIndexes, $expected) } foreach ($tokens as $index => $token) { - if (in_array($index, $inspectIndexes, true)) { + if (\in_array($index, $inspectIndexes, true)) { $this->assertSame('[', $tokens[$index]->getContent(), sprintf('Token @ index %d must have content \']\'', $index)); $exp = $expected; } elseif ('[' === $tokens[$index]->getContent()) {