Skip to content

Commit

Permalink
Add coding style checker
Browse files Browse the repository at this point in the history
Travis will check for coding style violations.

Symfony Coding Style mostly works for selfoss. It is essentially
PSR-2 sprinkled with some more rules for cases when PSR-2 is silent.
When the code base was not consistent, I choose the most common
format.

These are the deviations from Symfony CS:

* Opening braces after functions, methods, classes, interfaces,
traits, etc. go on the same line. (Unlike PSR-2)
* Lambdas do not have a space after function keyword. (Unlike PSR-2)
* Concatenation operator `.` requires spaces from both sides.
The codebase was actually fairly tied on this issue: 170 vs 167
lines had to be changed. The spaced variant was, however, more
widely spread 52 vs 34 affected files. (Unlike Symfony)
* We also do not require adding a comma after last item
of multi-line array. (Unlike Symfony)
* Finally, there are some minor differences from Symfony
with regards to docstring handling.
  • Loading branch information
jtojnar committed Feb 28, 2017
1 parent 1105a4f commit 085d386
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ node_modules
_wiki
.env
vendor/
.php_cs.cache
28 changes: 28 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('libs')
->exclude('utils')
->in(__DIR__)
->name('*.phtml');

$rules = [
'@Symfony' => true,
// why would anyone put braces on different line
'braces' => ['position_after_functions_and_oop_constructs' => 'same'],
'function_declaration' => ['closure_function_spacing' => 'none'],
// overwrite some Symfony rules
'concat_space' => ['spacing' => 'one'],
'phpdoc_align' => false,
'phpdoc_no_empty_return' => false,
'phpdoc_summary' => false,
'trailing_comma_in_multiline_array' => false,
// additional rules
'array_syntax' => ['syntax' => 'short'],
'opening_tag_plus_echo_to_short_echo_tag' => true,
'phpdoc_order' => true,
];

return PhpCsFixer\Config::create()
->setRules($rules)
->setFinder($finder);
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ matrix:
include:
- php: 7.1
- php: 7.0
env: CS_FIXER=true
- php: 5.6
- php: 5.5
- php: 5.4
Expand All @@ -26,6 +27,9 @@ cache:
before_install:
- nvm install 6
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi
# We need to use our modified version until the fixers are merged upstream.
- "export FIXER_REPO=--repository='{\"type\": \"vcs\", \"url\": \"https://github.com/jtojnar/php-cs-fixer\"}'"
- if [ "$CS_FIXER" = true ]; then composer create-project --no-dev --no-interaction "$FIXER_REPO" friendsofphp/php-cs-fixer utils/php-cs-fixer dev-selfoss; fi
- composer create-project --no-dev --no-interaction jakub-onderka/php-parallel-lint utils/php-parallel-lint

install:
Expand All @@ -36,6 +40,7 @@ before_script:

script:
- utils/php-parallel-lint/parallel-lint controllers daos helpers spouts templates
- if [ "$CS_FIXER" = true ]; then utils/php-cs-fixer/php-cs-fixer fix --verbose --dry-run; fi

before_deploy:
- source utils/package.sh
Expand All @@ -55,4 +60,3 @@ deploy:
on:
tags: true
condition: $DEPLOY = true

0 comments on commit 085d386

Please sign in to comment.