Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] duplicated array indexes rule #322

Closed
wandersonwhcr opened this issue Oct 29, 2015 · 4 comments
Closed

[Proposal] duplicated array indexes rule #322

wandersonwhcr opened this issue Oct 29, 2015 · 4 comments
Labels
Milestone

Comments

@wandersonwhcr
Copy link

Hello!

Yesterday I was developing my application and I had some problems with a git merge in an array definition. Example:

array configuration before git merge:

<?php
return array(
    // ...
    'default' => array(),
    // ...
);

array configuration after git merge --no-ff issue-1:

<?php
return array(
    'config' => array(
        'a' => true,
    ),
    // ...
    'default' => array(),
   // ...
);

array configuration after git merge --no-ff issue-2:

<?php
return array(
    'config' => array(
        'a' => true,
    ),
    // ...
    'default' => array(),
    // ...
    'config' => array(
        'b' => true,
    ),
);

Capturing configuration, PHP defined an array with this structure:

$config = array(
    'config' => array(
        'b' => true,
    ),
    'default' => array(),
);

Boom. Configuration for $config['config']['a'] was undefined. So, after 1 hour, I found the problem (hehe), duplication of indexes in array definition.

Can you create a rule for this problem, verifying duplicate indexes?

<?php
return array(
    'config' => array(
        'a' => true,
        'b' => true,
    ),
    // ...
    'default' => array(),
    // ...
);

PS: If we have duplicated subindexes, verify too?

PS2: I did the same question at php-cs-fixer project PHP-CS-Fixer/PHP-CS-Fixer#1469.

@wandersonwhcr wandersonwhcr changed the title [Proposal] duplicate array indexes rule [Proposal] duplicated array indexes rule Oct 29, 2015
@ravage84 ravage84 added this to the 2.4.0 milestone Oct 29, 2015
@ravage84
Copy link
Member

Didn't you review the changes/merge?
Also a good IDE, such as PhpSotrm, warns you about this built-in.

Nontheless, if you would create a PR with a rule covering this issue, I would consider it merging it.

And, yes this rule should warn about any duplicated array keys in any sub-level.

@wandersonwhcr
Copy link
Author

Yes, I did a review, but array had some 50+ indexes with 200+ lines and I'm human being 😄

Thank you!

@ravage84 ravage84 modified the milestones: 2.4.0, 2.5.0 Mar 8, 2016
@ravage84 ravage84 modified the milestones: 2.5.0, 2.6.0 Jun 28, 2016
@ravage84 ravage84 modified the milestones: 2.6.0, 2.7.0 Jan 30, 2017
@eeree
Copy link
Contributor

eeree commented Jun 14, 2017

@ravage84 @wandersonwhcr
It's already implemented in #484

@ravage84
Copy link
Member

Oh thanks. Forgot to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants