arrays.md

February 1, 2025 ยท View on GitHub

Arrays

SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys ๐Ÿ”ง

Arrays should be defined with keys in alphabetical order. It defines where new entries should be inserted. It reduces merge conflicts and duplicate entries.

This sniff enforces natural sorting of array definitions by key in multi-line arrays.

SlevomatCodingStandard.Arrays.ArrayAccess ๐Ÿ”ง

Disallow whitespace between array access operator and the variable, or between array access operators.

SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation

Disallows implicit array creation.

SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed ๐Ÿšง

Array must have keys specified for either all or none of the values.

SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement ๐Ÿ”ง

Enforces reasonable end bracket placement for multi-line arrays.

SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace ๐Ÿ”ง

Checks whitespace in single line array declarations (whitespace between brackets, around commas, ...).

Sniff provides the following settings:

  • spacesAroundBrackets: number of spaces you require to have around array brackets
  • enableEmptyArrayCheck (default: false): enables check for empty arrays

SlevomatCodingStandard.Arrays.TrailingArrayComma ๐Ÿ”ง

Commas after last element in an array make adding a new element easier and result in a cleaner versioning diff.

This sniff enforces trailing commas in multi-line arrays.

Sniff provides the following settings:

  • enableAfterHeredoc: enables/disables trailing commas after HEREDOC/NOWDOC, default based on PHP version.