Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Attribute classes. #2486

Closed
hovotbf opened this issue Sep 16, 2024 · 4 comments
Closed

Support Attribute classes. #2486

hovotbf opened this issue Sep 16, 2024 · 4 comments

Comments

@hovotbf
Copy link

hovotbf commented Sep 16, 2024

$expected = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . $extension;

Files name, with classes that are attributes, should start with attribute- instead of class-.
Or at least it shouldn't register an error when a file contains an attribute class, but the name doesn't start with class-.

@jrfnl
Copy link
Member

jrfnl commented Sep 16, 2024

Attribute classes are classes, so there is no reason to differentiate these.

@hovotbf
Copy link
Author

hovotbf commented Sep 16, 2024

@jrfnl
If attributes, that have different usage than the standard classes, shouldn't be differentiated from classes, then what about enums and interfaces.
I don't understand why it doesn't force the enum and interface file names to start with enum- and interface- appropriately,
but it forces the class file names to start with class-.
Maybe there's another reason behind that, that I don't understand.

Thanks anyways, I guess you know better.

@dingo-d
Copy link
Member

dingo-d commented Sep 16, 2024

@jrfnl If attributes, that have different usage than the standard classes, shouldn't be differentiated from classes, then what about enums and interfaces. I don't understand why it doesn't force the enum and interface file names to start with enum- and interface- appropriately, but it forces the class file names to start with class-. Maybe there's another reason behind that, that I don't understand.

Thanks anyways, I guess you know better.

Please check the WordPress PHP Coding Standards documentation about naming.

@GaryJones
Copy link
Member

I don't understand why it doesn't force the enum and interface file names to start with enum- and interface- appropriately,
but it forces the class file names to start with class-.

Essentially, it's history. When the naming decision was made for WordPress, classes were used, but interfaces (added in PHP 5.0) were not. Likewise, since PHP supported (and supports) PHP < 8.1.0, then Enum's can't be used, so there's been no decision on file naming for them either.

There have been some posts that attempt to modernise the documented standards so that, for those who have a higher level of minimum support PHP and can use new items, they know what the convention would be, but file naming of enums, interfaces, traits, etc. have not been agreed upon, so we can implement anything in WordPressCS for them.

If your application does make heavy use of attribute classes, enums, interfaces, etc. then feel free to go ahead and ignore the WordPressCS in this area. Indeed, many use PSR-4 (which then gets away from the application logic being coupled to/ reflected in the file-naming structure), even if they follow the rest of WordPress Coding Standards.

@GaryJones GaryJones closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants