zubr icon indicating copy to clipboard operation
zubr copied to clipboard

Style guide?

Open radmen opened this issue 6 years ago • 13 comments

We should use a consistent coding style. I think that we should stick to PSR-2 style guides.

It can be validated using composer run-script phpcs

$ composer run-script phpcs
> ./vendor/bin/phpcs --standard=PSR2 src

FILE: zubr/src/array_column.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------
 10 | WARNING | Line exceeds 120 characters; contains 292 characters
 11 | WARNING | Line exceeds 120 characters; contains 187 characters
----------------------------------------------------------------------

The second thing is the format of PHPDocs. I've used simplified doc blocks however, I see that @ddziaduch literally copied docs blocks from PHP source (or IDE stub :)). Which format should we use?

radmen avatar Aug 07 '17 09:08 radmen

Ah, and one more thing - should we use camel case or snake case for function parameters?

radmen avatar Aug 07 '17 09:08 radmen

@radmen yeap I have copied PHPDocs from PhpStorm stubs

ddziaduch avatar Aug 07 '17 09:08 ddziaduch

For me it's fine - I can do the same for other functions. It would be good to use the same format.

Should we use PhpStorm stubs?

radmen avatar Aug 07 '17 09:08 radmen

Ah, and one more thing - should we use camel case or snake case for function parameters?

I vote always snake case for parameters, as it seems to be more common.

nkkollaw avatar Aug 07 '17 09:08 nkkollaw

We should use a consistent coding style. I think that we should stick to PSR-2 style guides.

I will add more stuff to CONTRIBUTING.md, including a style guide and more detailed instructions.

nkkollaw avatar Aug 07 '17 11:08 nkkollaw

What about new PSR coding standard? It is not "official" yet but it will be soon

ddziaduch avatar Aug 07 '17 17:08 ddziaduch

https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md

ddziaduch avatar Aug 07 '17 17:08 ddziaduch

Very nice. I vote yes.

Also, of course we would need to change some code, but even if the spec changed we would still be consistent in that we're using the same standard.

Do you know how final the code is? Will there be pretty much no changes before the official release?

nkkollaw avatar Aug 07 '17 18:08 nkkollaw

@ddziaduch looks nice. Is this supported by phpcs? We could automate code style validation.

radmen avatar Aug 07 '17 19:08 radmen

@nkkollaw @radmen don't know :<

ddziaduch avatar Aug 08 '17 17:08 ddziaduch

I looked today somewhat briefly, they don't seem to even mention it.

What are the new specs called, do you know? Perhaps PSR-9? That would ease searching...

nkkollaw avatar Aug 08 '17 19:08 nkkollaw

It does not have number yet. Seems that it is still a draft http://www.php-fig.org/psr/

ddziaduch avatar Aug 09 '17 14:08 ddziaduch

Damn.

The only solution would be to configure phpcs manually, so that we used its configuration for PSR-2 and configured everything else found in the draft manually.

I don't know.

nkkollaw avatar Aug 09 '17 16:08 nkkollaw