I have some time already in languages, but whenever I come across other codes or I'm in a different job, each one has a different way of standardizing.
Is there any recognized standard, type W3C, or any tool that validates the code?
I have some time already in languages, but whenever I come across other codes or I'm in a different job, each one has a different way of standardizing.
Is there any recognized standard, type W3C, or any tool that validates the code?
Yes, it does. There are several standards, including online tools that "embellish" your code according to some existing pattern.
There's also the PHP_CodeSniffer, Pear's built-in package, which you can embed into your favorite IDE.
In my case, I use it to validate the PHP code of collaborators before accepting a pull request in the versioning tools. Whenever a PHP file is saved, my IDE (komodo edit) automatically invokes the command:
/usr/lib/php/pear/phpcs %F --standard=phpcs
Example of part of a result without validation:
FILE: phpexample.php
102 | ERROR | The variable names for parameters $ get (3) and $ main (4) of | | not align
102 | ERROR | The comments for parameters $ get (3) and $ main (4) do not | | align
199 | ERROR | Spaces must be used to indent lines; tabs are not allowed
199 | ERROR | Line indented incorrectly; found at least 4 spaces, found | | 1
And you choose from several formats.
For php there are some suggested recommendations that are:
PSR-0 , Regulates the definition of namespaces , so that the way to load (autoload) classes is a standard independent of the framework / lib used, because today some frameworks use their own mechanisms, that is to say if it requires only one component it is almost obligatory to use the entire framework because of dependencies or autoload proprio.
PSR-1 , Qugere a standardization, what kind of code some files should have and a bit of codestand.
PSR-2 , Basically suggests codestand
There are some tools like the codesniffer that serves to show deficiencies in the code eg duplicate code or wrong tab, this is made of through rules defined by the user, here is a article for more information.