Skip to content

Commit

Permalink
Merge branch '2.17' into list-files-cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab committed Jan 14, 2021
2 parents dfd35cc + e029b62 commit 194e6fe
Show file tree
Hide file tree
Showing 57 changed files with 1,399 additions and 296 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -40,6 +40,11 @@ jobs:
calculate-code-coverage: 'yes'
phpunit-flags: '--testsuite coverage --exclude-group covers-nothing --coverage-clover build/logs/clover.xml'

- operating-system: 'ubuntu-20.04'
php-version: '7.4'
job-description: 'with deployment'
execute-deployment: 'yes'

- operating-system: 'ubuntu-20.04'
php-version: '7.4'
job-description: 'with migration rules'
Expand Down Expand Up @@ -99,8 +104,8 @@ jobs:
composer-
- name: Configure Symfony Flex
if: matrix.execute-flex-with-symfony-version
run: composer config extra.symfony.require ${{ matrix.execute-flex-with-symfony-version }}
if: "matrix.execute-flex-with-symfony-version"

- name: Install dependencies
uses: nick-invision/retry@v2
Expand All @@ -113,8 +118,12 @@ jobs:
composer info -D
- name: Execute migration rules
if: matrix.execute-migration-rules == 'yes'
run: php php-cs-fixer fix --rules @PHP73Migration,@PHP71Migration:risky,blank_line_after_opening_tag -q
if: "matrix.execute-migration-rules == 'yes'"

- name: Disable time limit for tests when collecting coverage
if: matrix.calculate-code-coverage == 'yes'
run: sed 's/enforceTimeLimit="true"/enforceTimeLimit="false"/g' phpunit.xml.dist > phpunit.xml

- name: Run tests
continue-on-error: ${{ matrix.php-version == '8.0' }}
Expand All @@ -136,3 +145,19 @@ jobs:
PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
PHP_CS_FIXER_FUTURE_MODE: 1
run: php php-cs-fixer --diff --dry-run -v fix

- name: Execute deployment checks
if: matrix.execute-deployment == 'yes'
run: |
./dev-tools/build.sh
PHP_CS_FIXER_TEST_ALLOW_SKIPPING_SMOKE_TESTS=0 vendor/bin/phpunit tests/Smoke/
- name: Execute deployment post-hook
if: matrix.execute-deployment == 'yes' && startsWith(github.ref, 'refs/tags/v')
env:
TRAVIS_TOKEN: ${{ secrets.TRAVIS_TOKEN }}
run: |
# ensure that deployment is happening only if tag matches version of PHP CS Fixer
test $(php dev-tools/info-extractor.php | jq -r .version.vnumber) == "${GITHUB_REF#refs/tags/}"
# trigger website update
./dev-tools/trigger-website.sh ${TRAVIS_TOKEN} ${GITHUB_REF#refs/tags/}
31 changes: 20 additions & 11 deletions .github/workflows/sca.yml
Expand Up @@ -62,14 +62,23 @@ jobs:
retry_wait_seconds: 30
command: ./dev-tools/install.sh

- name: Run checks
run: |
./dev-tools/check_file_permissions.sh
./dev-tools/check_trailing_spaces.sh
./dev-tools/vendor/bin/phpstan analyse
./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file .composer-require-checker.json
composer normalize --dry-run --working-dir=./dev-tools ../composer.json
./dev-tools/check_shell_scripts.sh
- name: Check - file permissions
run: ./dev-tools/check_file_permissions.sh

- name: Check - trailing spaces
run: ./dev-tools/check_trailing_spaces.sh

- name: Check - phpstan
run: ./dev-tools/vendor/bin/phpstan analyse

- name: Check - composer-require-checker
run: ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file .composer-require-checker.json

- name: Check - composer normalize
run: composer normalize --dry-run --working-dir=./dev-tools ../composer.json

- name: Check - shell scripts
run: ./dev-tools/check_shell_scripts.sh

- name: Find changed files (for pull request)
if: ${{ github.event_name == 'pull_request' }}
Expand All @@ -87,13 +96,13 @@ jobs:
git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Validate changed files
- name: Check - phpmd
if: ${{ github.env.CHANGED_PHP_FILES }}
run: ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml

- name: Check for unknown files (to be removed in 3.0)
- name: Check - ensure test files are not present in the archive
run: |
# @TODO remove at 3.0
# @TODO remove listed exceptions at 3.0
git archive -o /dev/null HEAD -v 2>&1 | grep tests | grep \.php |
grep -v tests/Test/AbstractFixerTestCase.php |
grep -v tests/Test/AbstractIntegrationCaseFactory.php |
Expand Down
45 changes: 0 additions & 45 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,17 @@ CHANGELOG for PHP CS Fixer

This file contains changelogs for stable releases only.

Changelog for v2.17.3
---------------------

* bug #5384 PsrAutoloadingFixer - do not remove directory structure from the Class name (kubawerlos, keradus)
* bug #5385 SingleLineCommentStyleFixer- run before NoUselessReturnFixer (kubawerlos)
* bug #5387 SingleSpaceAfterConstructFixer - do not touch multi line implements (SpacePossum)
* minor #5329 DX: collect coverage with Github Actions (kubawerlos)
* minor #5380 PhpdocOrderByValueFixer - Allow sorting of throws annotations by value (localheinz, keradus)
* minor #5383 DX: fail PHPUnit tests on warning (kubawerlos)
* minor #5386 DX: remove incorrect priority relations (kubawerlos)

Changelog for v2.17.2
---------------------

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2012-2020 Fabien Potencier
Copyright (c) 2012-2021 Fabien Potencier
Dariusz Rumiński

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Expand Up @@ -32,7 +32,6 @@
"symfony/stopwatch": "^3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0",
"justinrainbow/json-schema": "^5.0",
"keradus/cli-executor": "^1.4",
"mikey179/vfsstream": "^1.6",
Expand All @@ -41,11 +40,11 @@
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1",
"phpspec/prophecy-phpunit": "^1.1 || ^2.0",
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.13 || ^9.4.4 <9.5",
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.13 || ^9.5",
"phpunitgoodpractices/polyfill": "^1.5",
"phpunitgoodpractices/traits": "^1.9.1",
"sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1",
"symfony/phpunit-bridge": "^5.1",
"symfony/phpunit-bridge": "^5.2.1",
"symfony/yaml": "^3.0 || ^4.0 || ^5.0"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/build.sh
Expand Up @@ -9,7 +9,7 @@ composer require --no-update symfony/polyfill-mbstring

# install package deps without dev-deps / remove already installed dev-deps
# box can ignore dev-deps, but dev-deps, when installed, may lower version of prod-deps
composer update --no-interaction --no-progress --no-dev --prefer-stable
composer update --no-interaction --no-progress --no-dev --prefer-stable --optimize-autoloader
composer info -D | sort

composer show -d dev-tools humbug/box -q || composer update -d dev-tools --no-interaction --no-progress
Expand Down
4 changes: 2 additions & 2 deletions doc/rules/language_construct/single_space_after_construct.rst
Expand Up @@ -12,9 +12,9 @@ Configuration

List of constructs which must be followed by a single space.

Allowed values: a subset of ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'new', 'open_tag_with_echo', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']``
Allowed values: a subset of ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']``

Default value: ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'new', 'open_tag_with_echo', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']``
Default value: ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']``

Examples
--------
Expand Down
2 changes: 1 addition & 1 deletion doc/rules/phpdoc/phpdoc_order_by_value.rst
Expand Up @@ -12,7 +12,7 @@ Configuration

List of annotations to order, e.g. ``["covers"]``.

Allowed values: a subset of ``['author', 'covers', 'coversNothing', 'dataProvider', 'depends', 'group', 'internal', 'requires', 'throws', 'uses']``
Allowed values: a subset of ``['author', 'covers', 'coversNothing', 'dataProvider', 'depends', 'group', 'internal', 'method', 'property', 'property-read', 'property-write', 'requires', 'throws', 'uses']``

Default value: ``['covers']``

Expand Down
2 changes: 1 addition & 1 deletion doc/rules/phpdoc/phpdoc_scalar.rst
Expand Up @@ -11,7 +11,7 @@ Configuration
``types``
~~~~~~~~~

A map of types to fix.
A list of types to fix.

Allowed values: a subset of ``['boolean', 'callback', 'double', 'integer', 'real', 'str']``

Expand Down
16 changes: 5 additions & 11 deletions phpunit.xml.dist
Expand Up @@ -15,12 +15,15 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
defaultTimeLimit="3"
enforceTimeLimit="true"
failOnWarning="true"
processIsolation="false"
stopOnFailure="false"
timeoutForSmallTests="2"
verbose="true"
timeoutForSmallTests="3"
timeoutForMediumTests="6"
timeoutForLargeTests="9"
verbose="false"
>
<testsuites>
<testsuite name="all">
Expand All @@ -40,15 +43,6 @@
</filter>

<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
<arguments>
<array>
<element key="slowThreshold">
<integer>100</integer>
</element>
</array>
</arguments>
</listener>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>

Expand Down
2 changes: 1 addition & 1 deletion src/Console/Application.php
Expand Up @@ -35,7 +35,7 @@
*/
final class Application extends BaseApplication
{
const VERSION = '2.17.3-DEV';
const VERSION = '2.17.4-DEV';
const VERSION_CODENAME = 'Desert Beast';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Console/WarningsDetector.php
Expand Up @@ -39,7 +39,7 @@ public function __construct(ToolInfoInterface $toolInfo)

public function detectOldMajor()
{
// @TODO 3.0 to be activated with new MAJOR release
// @TODO 2.99 to be activated with new MAJOR release
// $this->warnings[] = 'You are running PHP CS Fixer v2, which is not maintained anymore. Please update to v3.';
}

Expand Down
3 changes: 2 additions & 1 deletion src/Fixer/Alias/SetTypeToCastFixer.php
Expand Up @@ -82,7 +82,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
}

$prev = $tokens->getPrevMeaningfulToken($functionNameIndex);
if (!$tokens[$prev]->isGivenKind(T_OPEN_TAG) && !$tokens[$prev]->equalsAny([';', '{'])) {

if (!$tokens[$prev]->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
continue; // return value of the function is used
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/ArrayNotation/ArraySyntaxFixer.php
Expand Up @@ -105,7 +105,7 @@ protected function createConfigurationDefinition()
return new FixerConfigurationResolver([
(new FixerOptionBuilder('syntax', 'Whether to use the `long` or `short` array syntax.'))
->setAllowedValues(['long', 'short'])
->setDefault('long')
->setDefault('long') // TODO @3.0 change to short
->getOption(),
]);
}
Expand Down
73 changes: 68 additions & 5 deletions src/Fixer/Basic/PsrAutoloadingFixer.php
Expand Up @@ -172,11 +172,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
return;
}

if (null === $namespace && null !== $this->configuration['dir']) {
$expectedClassyName = substr(str_replace('/', '_', $file->getRealPath()), -\strlen($classyName) - 4, -4);
} else {
$expectedClassyName = $file->getBasename('.php');
}
$expectedClassyName = $this->calculateClassyName($file, $namespace, $classyName);

if ($classyName !== $expectedClassyName) {
$tokens[$classyIndex] = new Token([T_STRING, $expectedClassyName]);
Expand Down Expand Up @@ -210,4 +206,71 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$tokens->insertAt($namespaceStartIndex, $newNamespace);
}
}

/**
* @param null|string $namespace
* @param string $currentName
*
* @return string
*/
private function calculateClassyName(\SplFileInfo $file, $namespace, $currentName)
{
$name = $file->getBasename('.php');

$maxNamespace = $this->calculateMaxNamespace($file, $namespace);

if (null !== $this->configuration['dir']) {
return ('' !== $maxNamespace ? (str_replace('\\', '_', $maxNamespace).'_') : '').$name;
}

$namespaceParts = array_reverse(explode('\\', $maxNamespace));

foreach ($namespaceParts as $namespacePart) {
$nameCandidate = sprintf('%s_%s', $namespacePart, $name);
if (strtolower($nameCandidate) !== strtolower(substr($currentName, -\strlen($nameCandidate)))) {
break;
}
$name = $nameCandidate;
}

return $name;
}

/**
* @param null|string $namespace
*
* @return string
*/
private function calculateMaxNamespace(\SplFileInfo $file, $namespace)
{
if (null === $this->configuration['dir']) {
$root = \dirname($file->getRealPath());
while ($root !== \dirname($root)) {
$root = \dirname($root);
}
} else {
$root = realpath($this->configuration['dir']);
}

$namespaceAccordingToFileLocation = trim(str_replace(\DIRECTORY_SEPARATOR, '\\', substr(\dirname($file->getRealPath()), \strlen($root))), '\\');

if (null === $namespace) {
return $namespaceAccordingToFileLocation;
}

$namespaceAccordingToFileLocationPartsReversed = array_reverse(explode('\\', $namespaceAccordingToFileLocation));
$namespacePartsReversed = array_reverse(explode('\\', $namespace));

foreach ($namespacePartsReversed as $key => $namespaceParte) {
if (!isset($namespaceAccordingToFileLocationPartsReversed[$key])) {
break;
}
if (strtolower($namespaceParte) !== strtolower($namespaceAccordingToFileLocationPartsReversed[$key])) {
break;
}
unset($namespaceAccordingToFileLocationPartsReversed[$key]);
}

return implode('\\', array_reverse($namespaceAccordingToFileLocationPartsReversed));
}
}

0 comments on commit 194e6fe

Please sign in to comment.