Comments (3)
@increddibelly Is this new ? I can't remember ever having come across the src/constants
folder in the Yoast plugins before.
Other than that:
-
What about the constants like
PLUGIN_DIR
and such which are normally created in the "main" file of a plugin ? -
if the constant is private (7.1) or in other words, if the constant in a class are only used in that class and its unit tests.
This seems like a contradiction in terms.
- If a constant is
private
it cannot be used in the unit tests for that class.
While this wouldn't be enforced until theprivate
modifier would be added, the principle of this is plain impossible. - Class constants ALWAYS have to be declared in the class.
Introducing global constants in favour of class constants sounds like a really bad idea.
- If a constant is
from yoastcs.
Just read the section in the docs, so we're talking class constants in a multitude of class in the /src/constants
folder if I understand this correctly ?
I still wonder about why these constants would be disconnected from where they are used. Wouldn't it be more appropriate to add them to an applicable interface
in that case ? (and yes, interfaces can have constants)
from yoastcs.
correct, the intent is to bundle constants per domain in a class in the src/constants
folder. This is still a PR but I'd love to have a code sniff (warning) for this, as it helps people migratie toward the desired situation.
The main reasoning behind this is to reduce coupling between classes. e.g. we had an integration class that used a constant from another integration, which created a hard dependency between two logic classes that are in totally different domains. Through moving the constant into a separate class, the dependency becomes a much cleaner triangle like this: integration a -> depends on -> const class, and integration b -> depends on -> const class.
we discussed keeping the constant near the logic using it, but since the rest of the code is divided into folders based on their design (repository / presenter / etc) we decided to move the constants to a constants folder, to conform to the rest of the folders.
the exception:
if a constant is only used privately, we could mark it as private constant but that's not OK for PHP 5.6. So, they need to be public. We felt it's ok to keep the constant in the class using it. As soon as another class needs that const, the const needs to move to the src\constants\
folder.
TLDR it's too bad PHP doesn't support ENUMS because that's what we're trying to do here 🙃
from yoastcs.
Related Issues (20)
- Investigate options for sniffs for catching exceptions. HOT 3
- Investigate options for forbidding throwing exceptions in specific directories. HOT 3
- Add a sniff to enforce use statements are in alphabetic order (per group)
- Add sniff to disallow import use statements for functions/constants in the global namespace HOT 1
- Add sniff to enforce importing a namespace not a namespaced function/constant HOT 1
- Add sniff to detect @deprecated tags that are older than 2 major versions. HOT 1
- Add sniff to detect `get_option`/`update_option` usage with prefix in name (`wpseo_`) HOT 1
- Output escaping sniff should take into account presenters HOT 5
- Add sniff to trigger on uncached functions HOT 1
- Task: check what PHPMD checks and if there are replacement sniffs HOT 2
- Filters should always return the first argument HOT 1
- check for correct usage of constants HOT 1
- Trait double doesn't need a trait suffix HOT 1
- Add a sniff for console.log HOT 2
- ValidHookName: verify correct handling of single vs double quotes names HOT 1
- ValidHookName: make the `NotString` warning more actionable HOT 2
- Detect potential race condition with BrainMonkey test functions HOT 1
- Forbid the usage of session functions. HOT 2
- [3.0.0] Sniff wish list HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yoastcs.