-
Notifications
You must be signed in to change notification settings - Fork 3
Upgrading to 2.0
Here are some "gotchas"/changes that are worth mentioning when upgrading to Alley Coding Standards 2.0 (which subsequently upgrades projects to WPCS/VIPCS 3.0).
To start, upgrade the dependency:
composer require alleyinteractive/alley-coding-standards:^2.0 --dev
You can also modify composer.json
to:
"require-dev": {
"alleyinteractive/alley-coding-standards": "^2.0"
}
Run composer update
and then PHP Code Beautifier (phpcbf
/vendor/bin/phpcbf
) to fix a good chunk of the issues on your project.
Various sniffs were renamed and/or moved. Please review the following guide and CHANGELOG for more information (some sniffs are outlined below):
Old Sniff Name | New Sniff Name |
---|---|
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in |
Generic.CodeAnalysis.UnusedFunctionParameter.Found
/Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
Functions with unused method parameters will now throw errors in PHPCS. These issues cannot be fixed by phpcbf
and will requiring a code change. To ignore these errors, you can exclude the rule in your PHPCS Configuration:
<?xml version="1.0"?>
<ruleset name="National Review">
<description>PHP_CodeSniffer standard for National Review.</description>
<!-- Include Alley Rules -->
<rule ref="Alley-Interactive">
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter" />
</rule>
</ruleset>
Introduced with the new version, the order of your use
statements must match PSR 12 order:
<?php
namespace Vendor\Package;
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
use Vendor\Package\SomeNamespace\ClassD as D;
use function Vendor\Package\{functionA, functionB, functionC};
use const Vendor\Package\{ConstantA, ConstantB, ConstantC};
class Foo extends Bar implements FooInterface {}
The important thing to note here the order being:
- Classes
- Functions
- Constants
The coding standards will now flag files that mix class and function definitions in the same file. As a general rule, this is a great practice and something we should follow. But alas: for old code bases, this tends to happen. You can ignore this rule globally or on a per-file basis, whatever is easier. Here is a global example:
<?xml version="1.0"?>
<ruleset name="National Review">
<description>PHP_CodeSniffer standard for National Review.</description>
<!-- Include Alley Rules -->
<rule ref="Alley-Interactive">
<exclude name="Universal.Files.SeparateFunctionsFromOO.Mixed" />
</rule>
</ruleset>