Skip to content

Upgrading to 2.0

Sean Fisher edited this page Sep 6, 2023 · 15 revisions

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:

  "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.

Sniff Renaming

Various sniffs were renamed and/or moved. Please review the following guide and CHANGELOG for more information (some sniffs are outlined below):

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.FoundAfterLastUsed" />
  </rule>
</ruleset>

PSR12.Files.FileHeader.IncorrectOrder

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:

  1. Classes
  2. Functions
  3. Constants
Clone this wiki locally