Skip to content

Commit

Permalink
Merge branch 'master' into 3.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	.appveyor.yml
#	src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php
#	src/Fixer/Operator/BinaryOperatorSpacesFixer.php
#	src/FixerConfiguration/FixerConfigurationResolverRootless.php
  • Loading branch information
keradus committed Feb 17, 2019
2 parents 166478d + 51209a6 commit 70f291d
Show file tree
Hide file tree
Showing 29 changed files with 137 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ clone_folder: C:\projects\php-cs-fixer

environment:
matrix:
- php_ver: 7.1.2
- php_ver: 5.6.30
- php_ver: 7.3.1
- php_ver: 5.6.40

cache:
- '%APPDATA%\Composer'
Expand Down
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@ CHANGELOG for PHP CS Fixer

This file contains changelogs for stable releases only.

Changelog for v2.14.2
---------------------

* minor #4306 DX: Drop HHVM conflict on Composer level to help Composer with HHVM compatibility, we still prevent HHVM on runtime (keradus)

Changelog for v2.14.1
---------------------

* bug #4240 ModernizeTypesCastingFixer - fix for operators with higher precedence (kubawerlos)
* bug #4254 PhpUnitDedicateAssertFixer - fix for count with additional operations (kubawerlos)
* bug #4260 Psr0Fixer and Psr4Fixer - fix for multiple classes in file with anonymous class (kubawerlos)
* bug #4262 FixCommand - fix help (keradus)
* bug #4276 MethodChainingIndentationFixer, ArrayIndentationFixer - Fix priority issue (dmvdbrugge)
* bug #4280 MethodArgumentSpaceFixer - Fix method argument alignment (Billz95)
* bug #4286 IncrementStyleFixer - fix for static statement (kubawerlos)
* bug #4291 ArrayIndentationFixer - Fix indentation after trailing spaces (julienfalque, keradus)
* bug #4292 NoSuperfluousPhpdocTagsFixer - Make null only type not considered superfluous (julienfalque)
* minor #4204 DX: Tokens - do not unregister/register found tokens when collection is not changing (kubawerlos)
* minor #4235 DX: more specific @param types (kubawerlos)
* minor #4263 DX: AppVeyor - bump PHP version (keradus)
* minor #4293 Add official support for PHP 7.3 (keradus)
* minor #4295 DX: MethodArgumentSpaceFixerTest - fix edge case for handling different line ending when only expected code is provided (keradus)
* minor #4296 DX: cleanup testing with fixer config (keradus)
* minor #4299 NativeFunctionInvocationFixer - add array_key_exists (deguif, keradus)
* minor #4300 DX: cleanup testing with fixer config (keradus)

Changelog for v2.14.0
---------------------

Expand Down Expand Up @@ -154,6 +180,31 @@ Changelog for v2.13.0
* minor #3873 Add the native_function_invocation fixer in the Symfony:risky ruleset (stof)
* minor #3979 DX: enable php_unit_method_casing (keradus)

Changelog for v2.12.8
---------------------

* minor #4306 DX: Drop HHVM conflict on Composer level to help Composer with HHVM compatibility, we still prevent HHVM on runtime (keradus)

Changelog for v2.12.7
---------------------

* bug #4240 ModernizeTypesCastingFixer - fix for operators with higher precedence (kubawerlos)
* bug #4254 PhpUnitDedicateAssertFixer - fix for count with additional operations (kubawerlos)
* bug #4260 Psr0Fixer and Psr4Fixer - fix for multiple classes in file with anonymous class (kubawerlos)
* bug #4262 FixCommand - fix help (keradus)
* bug #4276 MethodChainingIndentationFixer, ArrayIndentationFixer - Fix priority issue (dmvdbrugge)
* bug #4280 MethodArgumentSpaceFixer - Fix method argument alignment (Billz95)
* bug #4286 IncrementStyleFixer - fix for static statement (kubawerlos)
* bug #4291 ArrayIndentationFixer - Fix indentation after trailing spaces (julienfalque, keradus)
* bug #4292 NoSuperfluousPhpdocTagsFixer - Make null only type not considered superfluous (julienfalque)
* minor #4204 DX: Tokens - do not unregister/register found tokens when collection is not changing (kubawerlos)
* minor #4235 DX: more specific @param types (kubawerlos)
* minor #4263 DX: AppVeyor - bump PHP version (keradus)
* minor #4293 Add official support for PHP 7.3 (keradus)
* minor #4295 DX: MethodArgumentSpaceFixerTest - fix edge case for handling different line ending when only expected code is provided (keradus)
* minor #4296 DX: cleanup testing with fixer config (keradus)
* minor #4299 NativeFunctionInvocationFixer - add array_key_exists (deguif, keradus)

Changelog for v2.12.6
---------------------

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ or with specified version:

.. code-block:: bash
$ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.14.0/php-cs-fixer.phar -O php-cs-fixer
$ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.14.2/php-cs-fixer.phar -O php-cs-fixer
or with curl:

Expand Down Expand Up @@ -1760,7 +1760,7 @@ Config file

Instead of using command line options to customize the rule, you can save the
project configuration in a ``.php_cs.dist`` file in the root directory of your project.
The file must return an instance of `PhpCsFixer\\ConfigInterface <https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.14.0/src/ConfigInterface.php>`_
The file must return an instance of `PhpCsFixer\\ConfigInterface <https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.14.2/src/ConfigInterface.php>`_
which lets you configure the rules, the files and directories that
need to be analyzed. You may also create ``.php_cs`` file, which is
the local configuration that will be used instead of the project configuration. It
Expand Down
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
"symfony/process": "^3.0 || ^4.0",
"symfony/stopwatch": "^3.0 || ^4.0"
},
"conflict": {
"hhvm": "*"
},
"require-dev": {
"johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0",
"justinrainbow/json-schema": "^5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function configure(array $configuration)
}

$name = $option->getName();
if (array_key_exists($name, $configuration)) {
if (\array_key_exists($name, $configuration)) {
$message = sprintf(
'Option "%s" for rule "%s" is deprecated and will be removed in version %d.0. %s',
$name,
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getSignature()

public function has($file)
{
return array_key_exists($file, $this->hashes);
return \array_key_exists($file, $this->hashes);
}

public function get($file)
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ static function (\SplFileInfo $current) use ($pathsByType) {
*/
private function setOption($name, $value)
{
if (!array_key_exists($name, $this->options)) {
if (!\array_key_exists($name, $this->options)) {
throw new InvalidConfigurationException(sprintf('Unknown option name: "%s".', $name));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Alias/RandomApiMigrationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function createConfigurationDefinition()
->setAllowedTypes(['array'])
->setAllowedValues([static function ($value) {
foreach ($value as $functionName => $replacement) {
if (!array_key_exists($functionName, self::$argumentCounts)) {
if (!\array_key_exists($functionName, self::$argumentCounts)) {
throw new InvalidOptionsException(sprintf(
'Function "%s" is not handled by the fixer.',
$functionName
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Basic/Psr0Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
} elseif ($token->isClassy()) {
$prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
if ($prevToken->isGivenKind(T_NEW)) {
break;
continue;
}

if (null !== $classyName) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Basic/Psr4Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
} elseif ($token->isClassy()) {
$prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
if ($prevToken->isGivenKind(T_NEW)) {
break;
continue;
}

if (null !== $classyName) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Casing/NativeFunctionCasingFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)

// test if the function call is to a native PHP function
$lower = strtolower($tokens[$index]->getContent());
if (!array_key_exists($lower, $nativeFunctionNames)) {
if (!\array_key_exists($lower, $nativeFunctionNames)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/CastNotation/ShortScalarCastFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$castFrom = trim(substr($tokens[$index]->getContent(), 1, -1));
$castFromLowered = strtolower($castFrom);

if (!array_key_exists($castFromLowered, $castMap)) {
if (!\array_key_exists($castFromLowered, $castMap)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/ClassNotation/OrderedClassElementsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ private function sortElements(array $elements)
foreach ($elements as &$element) {
$type = $element['type'];

if (array_key_exists($type, self::$specialTypes)) {
if (\array_key_exists($type, self::$specialTypes)) {
if (isset($this->typePosition[$type])) {
$element['position'] = $this->typePosition[$type];
if ('phpunit' === $type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
continue;
}

if (array_key_exists('forbiddenContents', $loop)) {
if (\array_key_exists('forbiddenContents', $loop)) {
$forbiddenTokenIndex = $tokens->getNextTokenOfKind($blockStartIndex, $loop['forbiddenContents']);
// A forbidden token is found and is inside the parenthesis.
if (null !== $forbiddenTokenIndex && $forbiddenTokenIndex < $blockEndIndex) {
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/ControlStructure/YodaStyleFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ private function fixTokensCompare(
) {
$type = $tokens[$compareOperatorIndex]->getId();
$content = $tokens[$compareOperatorIndex]->getContent();
if (array_key_exists($type, $this->candidatesMap)) {
if (\array_key_exists($type, $this->candidatesMap)) {
$tokens[$compareOperatorIndex] = clone $this->candidatesMap[$type];
} elseif (array_key_exists($content, $this->candidatesMap)) {
} elseif (\array_key_exists($content, $this->candidatesMap)) {
$tokens[$compareOperatorIndex] = clone $this->candidatesMap[$content];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ private function getFunctionFilter()
private function getAllCompilerOptimizedFunctionsNormalized()
{
return $this->normalizeFunctionNames([
// @see https://github.com/php/php-src/blob/php-7.2.6/Zend/zend_compile.c "zend_try_compile_special_func"
// @see https://github.com/php/php-src/blob/PHP-7.4/Zend/zend_compile.c "zend_try_compile_special_func"
'array_key_exists',
'array_slice',
'assert',
'boolval',
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/LanguageConstruct/FunctionToConstantFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private function getReplaceCandidate(Tokens $tokens, $index)

// test if the function call is to a native PHP function
$lowerContent = strtolower($tokens[$index]->getContent());
if (!array_key_exists($lowerContent, $this->functionsFixMap)) {
if (!\array_key_exists($lowerContent, $this->functionsFixMap)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private function fixWhiteSpaceAroundOperator(Tokens $tokens, $index)
{
$tokenContent = strtolower($tokens[$index]->getContent());

if (!array_key_exists($tokenContent, $this->operators)) {
if (!\array_key_exists($tokenContent, $this->operators)) {
return; // not configured to be changed
}

Expand Down
4 changes: 4 additions & 0 deletions src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ private function annotationIsSuperfluous(Annotation $annotation, array $info, ar

$annotationTypes = $this->toComparableNames($annotation->getTypes(), $symbolShortNames);

if (['null'] === $annotationTypes) {
return false;
}

if (['mixed'] === $annotationTypes && null === $info['type']) {
return !$this->configuration['allow_mixed'];
}
Expand Down
4 changes: 2 additions & 2 deletions src/FixerConfiguration/FixerConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function resolve(array $options)
if ($option instanceof AliasedFixerOption) {
$alias = $option->getAlias();

if (array_key_exists($alias, $options)) {
if (\array_key_exists($alias, $options)) {
// @TODO 2.12 Trigger a deprecation notice and add a test for it
if (array_key_exists($name, $options)) {
if (\array_key_exists($name, $options)) {
throw new InvalidOptionsException(sprintf('Aliased option %s/%s is passed multiple times.', $name, $alias));
}

Expand Down
6 changes: 3 additions & 3 deletions src/FixerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function useRuleSet(RuleSetInterface $ruleSet)

$fixerNames = array_keys($ruleSet->getRules());
foreach ($fixerNames as $name) {
if (!array_key_exists($name, $this->fixersByName)) {
if (!\array_key_exists($name, $this->fixersByName)) {
throw new \UnexpectedValueException(sprintf('Rule "%s" does not exist.', $name));
}

Expand Down Expand Up @@ -226,7 +226,7 @@ private function getFixersConflicts(FixerInterface $fixer)

$fixerName = $fixer->getName();

return array_key_exists($fixerName, $conflictMap) ? $conflictMap[$fixerName] : [];
return \array_key_exists($fixerName, $conflictMap) ? $conflictMap[$fixerName] : [];
}

/**
Expand All @@ -243,7 +243,7 @@ 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);
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public static function create(array $set = [])
*/
public function hasRule($rule)
{
return array_key_exists($rule, $this->rules);
return \array_key_exists($rule, $this->rules);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/Tokenizer/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,14 @@ public function offsetSet($index, $newval)

if (!$this[$index] || !$this[$index]->equals($newval)) {
$this->changed = true;
}

if (isset($this[$index])) {
$this->unregisterFoundToken($this[$index]);
if (isset($this[$index])) {
$this->unregisterFoundToken($this[$index]);
}

$this->registerFoundToken($newval);
}

$this->registerFoundToken($newval);
parent::offsetSet($index, $newval);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Fixer/Basic/Psr0FixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,24 @@ public function testIgnoreAnonymousClass()
$this->doTest($expected, null, $file);
}

/**
* @requires PHP 7.0
*/
public function testIgnoreMultipleClassWithAnonymousClass()
{
$file = $this->getTestFile(__FILE__);

$expected = <<<'EOF'
<?php
namespace PhpCsFixer\Tests\Fixer\Basic;
class ClassOne {};
new class extends stdClass {};
class ClassTwo {};
EOF;

$this->doTest($expected, null, $file);
}

/**
* @param string $filename
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Fixer/Basic/Psr4FixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,24 @@ public function testIgnoreAnonymousClass()
$this->doTest($expected, null, $file);
}

/**
* @requires PHP 7.0
*/
public function testIgnoreMultipleClassWithAnonymousClass()
{
$file = $this->getTestFile(__FILE__);

$expected = <<<'EOF'
<?php
namespace PhpCsFixer\Tests\Fixer\Basic;
class ClassOne {};
new class extends stdClass {};
class ClassTwo {};
EOF;

$this->doTest($expected, null, $file);
}

/**
* @param string $filename
*
Expand Down
7 changes: 3 additions & 4 deletions tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class PhpdocToReturnTypeFixerTest extends AbstractFixerTestCase
*
* @dataProvider provideFixCases
*/
public function testFix($expected, $input = null, $versionSpecificFix = null, $config = null)
public function testFix($expected, $input = null, $versionSpecificFix = null, array $config = [])
{
if (
(null !== $input && \PHP_VERSION_ID < 70000)
Expand All @@ -40,9 +40,8 @@ public function testFix($expected, $input = null, $versionSpecificFix = null, $c
$expected = $input;
$input = null;
}
if (null !== $config) {
$this->fixer->configure($config);
}

$this->fixer->configure($config);

$this->doTest($expected, $input);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ class Foo {
* @param $foo Some description that includes a $variable
*/
public function doFoo($foo) {}
}',
],
'with_null' => [
'<?php
class Foo {
/**
* @param null $foo
* @return null
*/
public function doFoo($foo) {}
}',
],
];
Expand Down
Loading

0 comments on commit 70f291d

Please sign in to comment.