Giter VIP home page Giter VIP logo

Comments (3)

jrfnl avatar jrfnl commented on June 20, 2024

@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 the private 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.

from yoastcs.

jrfnl avatar jrfnl commented on June 20, 2024

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.

increddibelly avatar increddibelly commented on June 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.