Skip to content

PHP array sniff does not detect some values in nested arrays #13

@svenmuennich

Description

@svenmuennich

I ran into a strange case where our array sniff for PHP CodeSniffer does not detect a value that's part of a nested array and hence does not enforce a missing trailing comma. Here's a code snippet for reproducing this:

<?php

$a = [
    'bla' => [
        'blubb' // <-- This line is missing a trailing comma! 
    ],
];

I wasn't able to come up with an quick easy fix, because the code that collects the array values is mixed with the code that validates key/value pairs (which IMHO is not necessary at all, since php -l validates keyed arrays):

https://github.com/VIISON/style-guide/blob/6ae0a65a3fb21bb5e80f5276c4fa7b81681a695d/php/php-codesniffer-standard/VIISON/Sniffs/Arrays/ArrayDeclarationSniff.php#L348-L501

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues that describe an unexpected behaviour in an existing functionality.minor"bug" issues that are neither "critical" nor "major".

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions