XF 2.3 Code intelligence vs. entity_structure and resource standards rule #20

Kirby

Well-known member
Resource standards rule #20 implies that a code event listener on entity_structure should be used if an entity stucture is modified but not other extensions to the entity class (changeed or new methods, etc.) are required.

Unless I am missing smth, changes to an entity stucture via that code event are basically "invisible" to static analyzers / IDEs so usage of this code event somewhat undermines the efforts taken to improve code intelligence.

So I wonder if the rules should be changed / relaxed in regards to entity_structure or if if makes sense to generally deprecate usage of this code event?
 
To be honest, I'm not sure I've ever preferred using entity_structure to a regular class extension (granted I only develop private add-ons). Most of the time I'm going to wind up needing to add or modify methods to support the new structural elements anyways. The changes are still invisible to static analysis without PHPDoc, but I'm not personally in favor of enforcing this too stringently for entity_structure.
 
And yeah generally we haven’t been too strict here.

I’m not sure if we’ve pointed this out before but the wording used in these rules was very deliberate.

Some rules say “must” others say “should”. Must being something we expect you to do every time. Should being something you should aim to do but ultimately if you don’t then there’s probably a good reason.

One of the main reasons it was/is a preference was because it’s more difficult to make a mistake using a code event listener rather than a class extension. More so for the other code events here but we still see people now overwriting life cycle methods without calling the parent.

But long story short: there’s reasons to consider the code event approach first, but if it is more practical to extend the class, just do that.
 
Top Bottom