Skip to content

NoArrayAccessOnObjectRule: Skip Symfony DomCrawler AbstractUriElement and child types#77

Merged
TomasVotruba merged 1 commit into
mainfrom
skip-uri-element-array-access
Jul 13, 2026
Merged

NoArrayAccessOnObjectRule: Skip Symfony DomCrawler AbstractUriElement and child types#77
TomasVotruba merged 1 commit into
mainfrom
skip-uri-element-array-access

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Array access on Symfony\Component\DomCrawler\AbstractUriElement (and its children Link, Form) is a valid, intended API — it reads the underlying node attributes. This rule wrongly flagged it.

Now skipped, same as other allowed classes.

 private const ALLOWED_CLASSES = [
     'SplFixedArray',
     'SimpleXMLElement',
     'Iterator',
     'WeakMap',
     'Aws\ResultInterface',
+    'Symfony\Component\DomCrawler\AbstractUriElement',
     'Symfony\Component\Form\FormInterface',
     'Symfony\Component\OptionsResolver\Options',
 ];

Before/after on a child type (Link extends AbstractUriElement):

public function run(\Symfony\Component\DomCrawler\Link $link)
{
    return $link['href']; // before: "Use explicit methods over array access on object"
                          // after:  allowed, no error
}

The isInstanceOf() check covers AbstractUriElement and all child types.

@TomasVotruba TomasVotruba merged commit 255b323 into main Jul 13, 2026
6 checks passed
@TomasVotruba TomasVotruba deleted the skip-uri-element-array-access branch July 13, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant