Closed shanebonham closed 10 years ago
Codeception runs phpUnit tests so there is no reason to require phpUnit or even really think about phpUnit other than to realize that tests written for phpUnit will work fine in Codeception.
If we switch to Grunt could we start the process of automatic minification on assets?
Codeception runs phpUnit tests so there is no reason to require phpUnit or even really think about phpUnit other than to realize that tests written for phpUnit will work fine in Codeception.
I mentioned phpUnit only for projects that don't require everything Codeception provides, like Monk ID PHP that only requires a unit test.
If we switch to Grunt could we start the process of automatic minification on assets?
Absolutely.
Are you proposing we abandon whatever reservations we have about PSR-2 and embrace it wholeheartedly? I'm thinking primarily about how it requires 4 spaces for indenting, or opening braces on the next line.
Yes. Those two things you mentioned certainly make me cringe, but I think about it like this: Go had its code style defined from the beginning, and nobody thinks about going against it now. PHP didn't have that a few years ago, but most of the major players now agree on a code style. Why not embrace it now?
I don't disagree, I was just clarifying.
Would the updates be pushed to the formatting
branch, if so we might want to get on a more regular merge cycle for that branch?
I feel like as a matter of process, we should always merge formatting
into dev
/master
whenever we do a deploy. Maybe worth adding to the deploy script?
Something feels wrong about that, if a formatting change somehow broke functionality we probably wouldn't catch it until it hit production
That's what tests are for! :smile:
Even if we didn't auto-deploy it, I still think that is the right rhythm to get into.
I'm curious about what others think of the formatting
branch. Is it too complicated of a process?
If there's a merge conflict would the deploy script just fail? Up to the deployer to resolve conflicts?
I think it's over-complicated. If I start to work on a file that's unformatted, it's much easier to format + commit + start with my changes than deal with the formatting
branch.
I agree that is easier. Does it make reviewing harder though? Maybe we should rather just deal with it on the PR side. That is, when you do your PR, exclude those commits and wrap them in a separate PR.
Just as a note. Here is an example of what happens as you try to bring a file up to PSR-2 standards. I did this automatically using PHP_Beautifer and PHP_Code_Fixer. If anyone else is interested in setting up these tools lmk because there were some bugaboos with OSX.
Final file. Mostly passes PSR-2 except for some try-catch stuff and multiline functional calls.
See the commits to see what happens when you apply each tool. You need to apply beautifier first and then code fixer.
We may still find that we need to maintain our own 'flavor' of PSR-2 standard. For example, I was able to pretty easily clean up a file, but the class statement at the top, which looks like this:
class Module_Form_Page_Capture_Fields extends Module_Form_Page_Capture
throws these errors against PSR-2:
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
3 | ERROR | Each class must be in a namespace of at least one level (a
| | top-level vendor name)
| | (PSR1.Classes.ClassDeclaration.MissingNamespace)
3 | ERROR | Class name "Module_Form_Page_Capture_Fields" is not in camel caps
| | format (Squiz.Classes.ValidClassName.NotCamelCaps)
--------------------------------------------------------------------------------
The implication being that we'd need to rename classes, which seems dicey.
I think it's OK if specific projects ignore specific PSR-2 rules, as long as those are documented within the project. New projects, however, should follow PSR-2 completely.
@mcordell Have you tried out the alpha of PHP_CodeSniffer? Wondering if you have any thoughts on how it compares to PHP_CS_Fixer for automatic fixing.
I haven't, I was looking for their tool (phpcbf) and failed reading comprehension that it isn't released yet and must be in the alpha. I think ill try it out, no wonder Google was no help.
So here is a quick comparison using event mapper (416 errors):
Using phpcbf
(the alpha Codesniffer tool) and then re-running phpcs I was able to from 416->34 errors (382 fixed). Detailed result here
Running phpcs on my fixed version above that used beautifer
and CS_fixer
I went from 416->50 errors(366 fixed). Detailed result here
It should be noted that phpcbf/alpha phpcs is still buggy. For instance I tried to apply phpcbf
to my 50 error version above and it just wouldn't work because of some kind of bug.
A sticking point with legacy code, PSR-2 compatibility, and pull requests arose recently. Our current practice is to fix PSR-2 violations on legacy files we are working on, commit that. Then we work on the file and commit the real "work". When pull request comes around this makes it harder on the reviewer because the differences are not easily ascertained, for example the PR above.
I purpose two possible solutions, which both rely on the same initial workflow (commit violation fixes separately from "real" work). However I think one of the two following options should be performed before a PR is given to a reviewer:
Where the first part after "compare" is the hash of the first real work commit and the end is the end of the work commits.
1
is a little easier on the reviewer but requies a separate PR and might slow the review process down
I think I would vote 2
, but also this is probably more of a general Git - Workflow issue, than specific to PHP (since any codebase may need conventions updates).
Yeah. @mcordell, I think your issue is totally valid, but I don't think it's PHP-specific. I'd move it as @shanebonham suggested.
Cobblestone (and newer parts of the CMS) uses the convention of code lines no longer than 120 characters, and comment lines no longer than 80 characters.