Skip to content

Commit

Permalink
DX: enable native_function_invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Aug 19, 2018
1 parent c67d872 commit 2f48a42
Show file tree
Hide file tree
Showing 162 changed files with 433 additions and 431 deletions.
2 changes: 2 additions & 0 deletions .php_cs.dist
Expand Up @@ -43,6 +43,8 @@ $config = PhpCsFixer\Config::create()
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'method_chaining_indentation' => true,
'multiline_comment_opening_closing' => true,
// TODO: remove at 2.13, as it's part of @Symfony ruleset since 2.13
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
'no_alternative_syntax' => true,
'no_binary_string' => true,
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractAlignFixerHelper.php
Expand Up @@ -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);
Expand Down Expand Up @@ -96,7 +96,7 @@ protected function replacePlaceholder(Tokens $tokens)
}

foreach ($linesWithPlaceholder as $group) {
if (count($group) < 1) {
if (\count($group) < 1) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/AbstractDoctrineAnnotationFixer.php
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractFixer.php
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractProxyFixer.php
Expand Up @@ -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.');
}

Expand Down
8 changes: 4 additions & 4 deletions src/Cache/Cache.php
Expand Up @@ -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)
));
}

Expand Down Expand Up @@ -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()
));
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Directory.php
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/Signature.php
Expand Up @@ -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);
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/Config.php
Expand Up @@ -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)
));
}

Expand All @@ -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)
));
}

Expand Down
10 changes: 5 additions & 5 deletions src/Console/Command/DescribeCommand.php
Expand Up @@ -161,7 +161,7 @@ private function describeRule(OutputInterface $output, $name)

$output->writeln(sprintf('<info>Description of</info> %s <info>rule</info>.', $name));
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln(sprintf('Fixer class: <comment>%s</comment>.', get_class($fixer)));
$output->writeln(sprintf('Fixer class: <comment>%s</comment>.', \get_class($fixer)));
}

$output->writeln($description);
Expand All @@ -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 = '* <info>'.OutputFormatter::escape($option->getName()).'</info>';
Expand Down Expand Up @@ -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.',
'',
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -400,7 +400,7 @@ private function describeList(OutputInterface $output, $type)
foreach ($describe as $list => $items) {
$output->writeln(sprintf('<comment>Defined %s:</comment>', $list));
foreach ($items as $name => $item) {
$output->writeln(sprintf('* <info>%s</info>', is_string($name) ? $name : $item));
$output->writeln(sprintf('* <info>%s</info>', \is_string($name) ? $name : $item));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Console/Command/FixCommand.php
Expand Up @@ -199,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$stdErr,
$this->eventDispatcher,
'estimating' !== $progressType ? (new Terminal())->getWidth() : null,
count($finder)
\count($finder)
);
}

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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
);
}
}
12 changes: 6 additions & 6 deletions src/Console/Command/HelpCommand.php
Expand Up @@ -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(),
]);
Expand All @@ -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
Expand Down Expand Up @@ -362,7 +362,7 @@ public static function getDisplayableAllowedValues(FixerOptionInterface $option)
);
});

if (0 === count($allowed)) {
if (0 === \count($allowed)) {
$allowed = null;
}
}
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -601,7 +601,7 @@ private static function wordwrap($string, $width)
$currentLine = 0;
$lineLength = 0;
foreach (explode(' ', $string) as $word) {
$wordLength = strlen(Preg::replace('~</?(\w+)>~', '', $word));
$wordLength = \strlen(Preg::replace('~</?(\w+)>~', '', $word));
if (0 !== $lineLength) {
++$wordLength; // space before word
}
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/SelfUpdateCommand.php
Expand Up @@ -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)) {
Expand Down

0 comments on commit 2f48a42

Please sign in to comment.