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

More than enough freedom #13

Open
szepeviktor opened this issue Sep 19, 2020 · 6 comments
Open

More than enough freedom #13

szepeviktor opened this issue Sep 19, 2020 · 6 comments

Comments

@szepeviktor
Copy link
Contributor

szepeviktor commented Sep 19, 2020

Hello!
Does this project encourage developers to write custom - meaning abnormally structured - code?

I think when you write code for WordPress and you have class autoloading on mind you use PHP >= 5.3.0 namespaces and follow WPCS or PSR-4.
e.g. https://github.com/szepeviktor/debian-server-tools/blob/master/webserver/wp-install/wordpress-autoloader.php
e.g. simply use Composer's generated autoloader (vendor/composer/*.php) for PSR-4

How do you see this?

@BrianHenryIE
Copy link
Contributor

You should give an example of what you're suggesting. I don't think it encourages abnormally structured code.

When I use this I also run PHPCS with WPCS.

From Updating the Coding standards for modern PHP:

Trait file names should be based on the trait name with trait- prepended and the underscores in the trait name replaced with hyphens.
The same goes for interface file names where the name should be based on the interface name with interface- prepended and the underscores in the interface name replaced with hyphens

This library doesn't handle traits yet. One of the reasons I was looking at it again yesterday was to see how to better handle interface-, trait- and abstract classes (I'm not sure what the Core perspective is on abstract class names).

e.g. I use it here: https://github.com/BrianHenryIE/bh-wp-autologin-urls/

@szepeviktor
Copy link
Contributor Author

I'm not sure what the Core perspective is on abstract class names

Core says everything should begin with class-: trait, interfaces ...

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Sep 19, 2020

Core says everything should begin with class-: trait, interfaces ...

Core was saying.

After taking a look at that linked announcement: I'm out. This is insanely complex. I'm not up to it. My brains could only process PSR-4 simplicity: filesystem equals namespaces.

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Sep 19, 2020

You should give an example of what you're suggesting.

wp-namespace-autoloader has several options: you could violate both PSR-4 and WPCS at the same time. That is abnormally structured code.

My suggestion

Have no option for standard: always WPCS.

  • classes_dir = "includes"
  • lowercase = everything
  • underscore_to_hyphen = everywhere
  • prepend_class = yes

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Sep 19, 2020

I know, I know: this would exclude Billlions of WPCS violators :)

https://twitter.com/szepeviktor/status/1307365158264680453

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Sep 19, 2020

@BrianHenryIE BTW having different prefixes (class- trait- interface-) makes autoloading slow by design as you cannot get the reflection of the unloaded class!
So you have to try to load it with every prefix.

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

2 participants