Skip to content

Commit

Permalink
Merge branch 'master' into new-with-braces-anonymous
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/Fixer/Operator/NewWithBracesFixerTest.php
  • Loading branch information
jrmajor committed Sep 9, 2021
2 parents 9e25d8e + 5e6bd99 commit 24371e0
Show file tree
Hide file tree
Showing 734 changed files with 11,487 additions and 6,428 deletions.
4 changes: 3 additions & 1 deletion .composer-require-checker.json
Expand Up @@ -14,7 +14,9 @@
"T_NAME_FULLY_QUALIFIED",
"T_NAME_QUALIFIED",
"T_NAME_RELATIVE",
"T_NULLSAFE_OBJECT_OPERATOR"
"T_NULLSAFE_OBJECT_OPERATOR",
"T_READONLY",
"T_ENUM"
],
"php-core-extensions" : [
"dom", "mbstring", "Phar",
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/ci.yml
Expand Up @@ -17,16 +17,11 @@ jobs:

- operating-system: 'ubuntu-20.04'
php-version: '7.2'
job-description: 'with Sf ^3'
execute-flex-with-symfony-version: '^3' # Explicit check for Sf 3.x compatibility

- operating-system: 'ubuntu-20.04'
php-version: '7.3'
job-description: 'with Sf ^4'
execute-flex-with-symfony-version: '^4' # Explicit check for Sf 4.x compatibility

- operating-system: 'ubuntu-20.04'
php-version: '7.4'
php-version: '7.3'
job-description: 'with Sf ^5'
execute-flex-with-symfony-version: '^5' # Explicit check for Sf 5.x compatibility

Expand Down Expand Up @@ -109,9 +104,9 @@ jobs:
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
composer info -D
- name: Execute migration rules
- name: Execute migration rules # we want to execute migration rules BEFORE we gonna run tests and self-fixing, so we know that our codebase is future-ready
if: matrix.execute-migration-rules == 'yes'
run: php php-cs-fixer fix --rules @PHP80Migration,@PHP80Migration:risky -q
run: php php-cs-fixer fix --config .php-cs-fixer.php-highest.php -q

- name: Disable time limit for tests when collecting coverage
if: matrix.calculate-code-coverage == 'yes'
Expand All @@ -129,9 +124,9 @@ jobs:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: php vendor/bin/php-coveralls --verbose

- name: Run PHP CS Fixer for PHP 7.0 types
if: matrix.php-version == '7.1' # we run on lowest supported version, we running it on higher would falsy expect more changes, eg `mixed` type on PHP 8
run: php php-cs-fixer fix --diff --dry-run -v --config .php-cs-fixer.php70types.php
- name: Run PHP CS Fixer for PHP 7.1 types
if: matrix.php-version == '7.1' # we run on lowest supported version, running it on higher would falsy expect more changes, eg `mixed` type on PHP 8
run: php php-cs-fixer fix --diff --dry-run -v --config .php-cs-fixer.php-lowest.php

- name: Run PHP CS Fixer
env:
Expand Down
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Expand Up @@ -36,12 +36,14 @@
$config
->setRiskyAllowed(true)
->setRules([
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']], // one should use PHPUnit built-in method instead
'header_comment' => ['header' => $header],
'modernize_strpos' => true, // needs PHP 8+ or polyfill
])
->setFinder($finder)
;
Expand Down
27 changes: 27 additions & 0 deletions .php-cs-fixer.php-highest.php
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

if (PHP_VERSION_ID <= 80001 || PHP_VERSION_ID >= 80100) {
fwrite(STDERR, "PHP CS Fixer's config for PHP-HIGHEST can be executed only on highest supported PHP version - 8.0.*.\n");
fwrite(STDERR, "Running it on lower PHP version would prevent calling migration rules.\n");
exit(1);
}

$config = require '.php-cs-fixer.dist.php';

$config->setRules(array_merge($config->getRules(), [
'@PHP80Migration' => true,
'@PHP80Migration:risky' => true,
'heredoc_indentation' => false,
]));

return $config;
6 changes: 6 additions & 0 deletions .php-cs-fixer.php70types.php → .php-cs-fixer.php-lowest.php
Expand Up @@ -10,6 +10,12 @@
* with this source code in the file LICENSE.
*/

if (PHP_VERSION_ID <= 70103 || PHP_VERSION_ID >= 70200) {
fwrite(STDERR, "PHP CS Fixer's config for PHP-LOWEST can be executed only on lowest supported PHP version - 7.1.*.\n");
fwrite(STDERR, "Running it on higher PHP version would falsy expect more changes, eg `mixed` type on PHP 8.\n");
exit(1);
}

$config = require '.php-cs-fixer.dist.php';

$config->getFinder()->notPath([
Expand Down
42 changes: 42 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,48 @@ CHANGELOG for PHP CS Fixer

This file contains changelogs for stable releases only.

Changelog for v3.1.0
--------------------

* feature #5572 PhpdocToCommentFixer - Add `ignored_tags` option (VincentLanglet)
* feature #5588 NoAliasFunctionsFixer - Add more function aliases (danog)
* feature #5704 ClassAttributesSeparationFixer - Introduce `only_if_meta` spacing option (paulbalandan)
* feature #5734 TypesSpacesFixer - Introduction (kubawerlos)
* feature #5745 EmptyLoopBodyFixer - introduction (SpacePossum, keradus)
* feature #5751 Extract DeclareParenthesesFixer from BracesFixer (julienfalque, keradus)
* feature #5877 ClassDefinitionFixer - PSR12 for anonymous class (SpacePossum)
* minor #5875 EmptyLoopBodyFixer - NoTrailingWhitespaceFixer - priority test (SpacePossum)
* minor #5914 Deprecate ClassKeywordRemoveFixer (kubawerlos)

Changelog for v3.0.3
--------------------

* bug #4927 PhpdocAlignFixer - fix for whitespace in type (kubawerlos)
* bug #5720 NoUnusedImportsFixer - Fix undetected unused imports when type mismatch (julienfalque, SpacePossum)
* bug #5806 DoctrineAnnotationFixer - Add template to ignored_tags (akalineskou)
* bug #5849 PhpdocTagTypeFixer - must not remove inlined tags within other tags (boesing)
* bug #5853 BracesFixer - handle alternative short foreach with if (SpacePossum)
* bug #5855 GlobalNamespaceImportFixer - fix for attributes imported as constants (kubawerlos)
* bug #5881 SelfUpdateCommand - fix link to UPGRADE docs (keradus)
* bug #5884 CurlyBraceTransformer - fix handling dynamic property with string with variable (kubawerlos, keradus)
* bug #5912 TypeAlternationTransformer - fix for "callable" type (kubawerlos)
* bug #5913 SingleSpaceAfterConstructFixer - improve comma handling (keradus)
* minor #5829 DX: Fix SCA with PHPMD (paulbalandan)
* minor #5838 PHP7 - use spaceship (SpacePossum, keradus)
* minor #5848 Docs: update PhpStorm integration link (keradus)
* minor #5856 Add AttributeAnalyzer (kubawerlos)
* minor #5857 DX: PHPMD - exclude fixtures (keradus)
* minor #5859 Various fixes (kubawerlos)
* minor #5864 DX: update dev tools (kubawerlos)
* minor #5876 AttributeTransformerTest - add more tests (SpacePossum)
* minor #5879 Update UPGRADE-v3.md adding relative links (shakaran, keradus)
* minor #5882 Docs: don't use v2 for installation example (keradus)
* minor #5883 Docs: typo (brianteeman, keradus)
* minor #5890 DX: use PHP 8.1 polyfill (keradus)
* minor #5902 Remove references to PHP 7.0 in tests (only removing lines) (kubawerlos)
* minor #5905 DX: Use "yield from" in tests (kubawerlos, keradus)
* minor #5917 Use `@PHP71Migration` rules (kubawerlos, keradus)

Changelog for v3.0.2
--------------------

Expand Down
4 changes: 2 additions & 2 deletions UPGRADE-v3.md
Expand Up @@ -157,8 +157,8 @@ Code BC changes

- class `Token` is now `final`
- class `Tokens` is now `final`
- method `create` of class `Config` has been removed, use the constructor
- method `create` of class `RuleSet` has been removed, use the constructor
- method `create` of class `Config` has been removed, [use the constructor](./doc/config.rst)
- method `create` of class `RuleSet` has been removed, [use the constructor](./doc/custom_rules.rst)

### BC breaks; common internal classes

Expand Down
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -26,13 +26,15 @@
"symfony/filesystem": "^4.4.20 || ^5.0",
"symfony/finder": "^4.4.20 || ^5.0",
"symfony/options-resolver": "^4.4.20 || ^5.0",
"symfony/polyfill-php72": "^1.22",
"symfony/polyfill-php72": "^1.23",
"symfony/polyfill-php80": "^1.23",
"symfony/polyfill-php81": "^1.23",
"symfony/process": "^4.4.20 || ^5.0",
"symfony/stopwatch": "^4.4.20 || ^5.0"
},
"require-dev": {
"justinrainbow/json-schema": "^5.2",
"keradus/cli-executor": "^1.4",
"keradus/cli-executor": "^1.5",
"mikey179/vfsstream": "^1.6.8",
"php-coveralls/php-coveralls": "^2.4.3",
"php-cs-fixer/accessible-object": "^1.1",
Expand Down
1 change: 1 addition & 0 deletions dev-tools/.gitignore
@@ -1,3 +1,4 @@
/composer.lock
/bin/
/phpstan/cache/
/vendor/
2 changes: 1 addition & 1 deletion dev-tools/composer.json
Expand Up @@ -9,7 +9,7 @@
"maglnet/composer-require-checker": "2.0.0",
"mi-schi/phpmd-extension": "^4.3",
"phpmd/phpmd": "^2.10.2",
"phpstan/phpstan": "0.12.92",
"phpstan/phpstan": "0.12.96",
"phpstan/phpstan-phpunit": "0.12.21"
},
"config": {
Expand Down
1 change: 1 addition & 0 deletions doc/ruleSets/PHP80MigrationRisky.rst
Expand Up @@ -8,6 +8,7 @@ Rules
-----

- `@PHP74Migration:risky <./PHP74MigrationRisky.rst>`_
- `modernize_strpos <./../rules/alias/modernize_strpos.rst>`_
- `no_alias_functions <./../rules/alias/no_alias_functions.rst>`_
config:
``['sets' => ['@all']]``
Expand Down
11 changes: 11 additions & 0 deletions doc/ruleSets/PHP81Migration.rst
@@ -0,0 +1,11 @@
============================
Rule set ``@PHP81Migration``
============================

Rules to improve code for PHP 8.1 compatibility.

Rules
-----

- `@PHP80Migration <./PHP80Migration.rst>`_
- `octal_notation <./../rules/basic/octal_notation.rst>`_
3 changes: 3 additions & 0 deletions doc/ruleSets/PSR12.rst
Expand Up @@ -12,6 +12,9 @@ Rules
- `braces <./../rules/basic/braces.rst>`_
config:
``['allow_single_line_anonymous_class_with_empty_body' => true]``
- `class_definition <./../rules/class_notation/class_definition.rst>`_
config:
``['space_before_parenthesis' => true]``
- `compact_nullable_typehint <./../rules/whitespace/compact_nullable_typehint.rst>`_
- `declare_equal_normalize <./../rules/language_construct/declare_equal_normalize.rst>`_
- `lowercase_cast <./../rules/cast_notation/lowercase_cast.rst>`_
Expand Down
2 changes: 1 addition & 1 deletion doc/ruleSets/PhpCsFixer.rst
Expand Up @@ -30,7 +30,7 @@ Rules
``['strategy' => 'new_line_for_chained_calls']``
- `no_extra_blank_lines <./../rules/whitespace/no_extra_blank_lines.rst>`_
config:
``['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']]``
``['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use']]``
- `no_null_property_initialization <./../rules/class_notation/no_null_property_initialization.rst>`_
- `no_superfluous_elseif <./../rules/control_structure/no_superfluous_elseif.rst>`_
- `no_useless_else <./../rules/control_structure/no_useless_else.rst>`_
Expand Down
8 changes: 7 additions & 1 deletion doc/ruleSets/Symfony.rst
Expand Up @@ -27,13 +27,18 @@ Rules
- `clean_namespace <./../rules/namespace_notation/clean_namespace.rst>`_
- `concat_space <./../rules/operator/concat_space.rst>`_
- `echo_tag_syntax <./../rules/php_tag/echo_tag_syntax.rst>`_
- `empty_loop_body <./../rules/control_structure/empty_loop_body.rst>`_
config:
``['style' => 'braces']``
- `empty_loop_condition <./../rules/control_structure/empty_loop_condition.rst>`_
- `fully_qualified_strict_types <./../rules/import/fully_qualified_strict_types.rst>`_
- `function_typehint_space <./../rules/function_notation/function_typehint_space.rst>`_
- `general_phpdoc_tag_rename <./../rules/phpdoc/general_phpdoc_tag_rename.rst>`_
config:
``['replacements' => ['inheritDocs' => 'inheritDoc']]``
- `include <./../rules/control_structure/include.rst>`_
- `increment_style <./../rules/operator/increment_style.rst>`_
- `integer_literal_case <./../rules/casing/integer_literal_case.rst>`_
- `lambda_not_used_import <./../rules/function_notation/lambda_not_used_import.rst>`_
- `linebreak_after_opening_tag <./../rules/php_tag/linebreak_after_opening_tag.rst>`_
- `magic_constant_casing <./../rules/casing/magic_constant_casing.rst>`_
Expand All @@ -52,7 +57,7 @@ Rules
- `no_empty_statement <./../rules/semicolon/no_empty_statement.rst>`_
- `no_extra_blank_lines <./../rules/whitespace/no_extra_blank_lines.rst>`_
config:
``['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']]``
``['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use']]``
- `no_leading_namespace_whitespace <./../rules/namespace_notation/no_leading_namespace_whitespace.rst>`_
- `no_mixed_echo_print <./../rules/alias/no_mixed_echo_print.rst>`_
- `no_multiline_whitespace_around_double_arrow <./../rules/array_notation/no_multiline_whitespace_around_double_arrow.rst>`_
Expand Down Expand Up @@ -119,6 +124,7 @@ Rules
- `switch_continue_to_break <./../rules/control_structure/switch_continue_to_break.rst>`_
- `trailing_comma_in_multiline <./../rules/control_structure/trailing_comma_in_multiline.rst>`_
- `trim_array_spaces <./../rules/array_notation/trim_array_spaces.rst>`_
- `types_spaces <./../rules/whitespace/types_spaces.rst>`_
- `unary_operator_spaces <./../rules/operator/unary_operator_spaces.rst>`_
- `whitespace_after_comma_in_array <./../rules/array_notation/whitespace_after_comma_in_array.rst>`_
- `yoda_style <./../rules/control_structure/yoda_style.rst>`_
1 change: 1 addition & 0 deletions doc/ruleSets/index.rst
Expand Up @@ -13,6 +13,7 @@ List of Available Rule sets
- `@PHP74Migration:risky <./PHP74MigrationRisky.rst>`_
- `@PHP80Migration <./PHP80Migration.rst>`_
- `@PHP80Migration:risky <./PHP80MigrationRisky.rst>`_
- `@PHP81Migration <./PHP81Migration.rst>`_
- `@PHPUnit30Migration:risky <./PHPUnit30MigrationRisky.rst>`_
- `@PHPUnit32Migration:risky <./PHPUnit32MigrationRisky.rst>`_
- `@PHPUnit35Migration:risky <./PHPUnit35MigrationRisky.rst>`_
Expand Down
39 changes: 39 additions & 0 deletions doc/rules/alias/modernize_strpos.rst
@@ -0,0 +1,39 @@
=========================
Rule ``modernize_strpos``
=========================

Replace ``strpos()`` calls with ``str_starts_with()`` or ``str_contains()`` if
possible.

.. warning:: Using this rule is risky.

Risky if ``strpos``, ``str_starts_with`` or ``str_contains`` functions are
overridden.

Examples
--------

Example #1
~~~~~~~~~~

.. code-block:: diff
--- Original
+++ New
<?php
-if (strpos($haystack, $needle) === 0) {}
-if (strpos($haystack, $needle) !== 0) {}
-if (strpos($haystack, $needle) !== false) {}
-if (strpos($haystack, $needle) === false) {}
+if (str_starts_with($haystack, $needle) ) {}
+if (!str_starts_with($haystack, $needle) ) {}
+if (str_contains($haystack, $needle) ) {}
+if (!str_contains($haystack, $needle) ) {}
Rule sets
---------

The rule is part of the following rule set:

@PHP80Migration:risky
Using the `@PHP80Migration:risky <./../../ruleSets/PHP80MigrationRisky.rst>`_ rule set will enable the ``modernize_strpos`` rule.
3 changes: 3 additions & 0 deletions doc/rules/array_notation/array_syntax.rst
Expand Up @@ -68,6 +68,9 @@ The rule is part of the following rule sets:
@PHP80Migration
Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.

@PHP81Migration
Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.

@PhpCsFixer
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.

Expand Down
Expand Up @@ -68,6 +68,11 @@ The rule is part of the following rule sets:

``['after_heredoc' => true]``

@PHP81Migration
Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``no_whitespace_before_comma_in_array`` rule with the config below:

``['after_heredoc' => true]``

@PhpCsFixer
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_whitespace_before_comma_in_array`` rule with the default config.

Expand Down
3 changes: 3 additions & 0 deletions doc/rules/array_notation/normalize_index_brace.rst
Expand Up @@ -29,6 +29,9 @@ The rule is part of the following rule sets:
@PHP80Migration
Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``normalize_index_brace`` rule.

@PHP81Migration
Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``normalize_index_brace`` rule.

@PhpCsFixer
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``normalize_index_brace`` rule.

Expand Down
26 changes: 26 additions & 0 deletions doc/rules/basic/octal_notation.rst
@@ -0,0 +1,26 @@
=======================
Rule ``octal_notation``
=======================

Literal octal must be in ``0o`` notation.

Examples
--------

Example #1
~~~~~~~~~~

.. code-block:: diff
--- Original
+++ New
-<?php $foo = 0123;
+<?php $foo = 0o123;
Rule sets
---------

The rule is part of the following rule set:

@PHP81Migration
Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``octal_notation`` rule.

0 comments on commit 24371e0

Please sign in to comment.