magento / magento/magento-coding-standard

Do not recommend using static:: for private constants

Open
#197 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Progress: ready for dev proposal
Dominant language
PHP
Stars
375
Forks
165
PR merge metrics
No merged PRs in 30d

Description

### Rule
Using `static::` for private constants and methods discouraged.

### Reason
In case if someone will extend the class OR create plugin for it - he will get the `Undefined class constant` error.
In past we had few issues related to this - https://github.com/magento/magento2/pull/28797 https://github.com/magento/magento2/pull/29925.

We had it only with constants, but potentially the same issue could appear with static method calls.

### Implementation
Detect all private constants in the class and all `static::` calls to them and add warning if such case detected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files or tests are named. Start by reviewing the repository's existing coding-standard rules for how private constants and static calls are detected, then trace their related tests. Done means the standard warns when static:: accesses a private constant or calls a private static method, with coverage for both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.