Skip to content

0.6.10

Latest

Choose a tag to compare

@dereuromark dereuromark released this 25 Oct 20:41
d421bfd

Fixes

  • phpcbf no longer loops on four constructs (#90). Files containing them ended in "FAILED TO FIX", in one case with a mangled comment:

    • PhpCollective.Commenting.InlineDocBlock treated the description of an inline var annotation as part of the variable name, so on a comment like bool $flag Expand type for psalm the fixer moved one word to the end on every pass. Only a reversed $var Type pair is swapped now, and the description stays in place.

    • The same sniff added a space before */ on every pass when the comment ended in a character other than a letter or digit, such as a description ending in ..

    • PhpCollective.WhiteSpace.ConsistentIndent dedented the second and third expression of a multi-line for (...) header, and PSR12 indented them back.

    • SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing now has allowOnSameLine enabled. Without it, an inline parameter attribute was split onto its own line and the trailing-comma sniffs kept adding and removing a comma:

      public function auth(Request $request, #[SensitiveParameter] array $credentials): Request

      Attributes on the same line as their target are now allowed.

  • PhpCollective.Classes.Psr4 no longer aborts the run when there is no composer.json (#89). Running phpcs from a directory without one threw a fatal error. A missing or unreadable composer.json now disables only this sniff. Invalid JSON in an existing file still throws.

  • Multi-catch type separators are written without spaces (#92), the same as union types:

    } catch (ValueError | TypeError $e) {  // now reported, auto-fixable
    } catch (ValueError|TypeError $e) {    // now accepted

    New sniff PhpCollective.WhiteSpace.CatchTypeSeparatorSpacing. PSR12.Operators.OperatorSpacing is replaced by PhpCollective.Operators.OperatorSpacing, which reports the same things except catch separators.

    Behavior change: if your ruleset silences PSR12.Operators.OperatorSpacing or one of its codes, rename it to PhpCollective.Operators.OperatorSpacing. Code written as catch (A | B $e) gets a new, auto-fixable error.

Improvements

  • New sniff PhpCollective.Operators.OperatorPosition (#91). Universal.Operators.ConcatPosition already moves a wrapped . to the start of the next line. The new sniff does the same for &&, ||, and, or, xor, ??, the ternary ? and :, and binary arithmetic operators:

    // before
    $valid = $hasName &&
        $hasEmail;
    
    // after
    $valid = $hasName
        && $hasEmail;

    Unary +/-, return-type and case colons, and nullable ? are not touched. If a comment sits between the operator and the next token, the error is reported but not fixed.

    Behavior change: code with these operators at the end of a line gets new errors. All of them are auto-fixable with phpcbf.

Full Changelog: 0.6.9...0.6.10