-
Notifications
You must be signed in to change notification settings - Fork 46
Suggestion for keeping an consistent, automatic code style (with php-cs-fixer) #92
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
base: master
Are you sure you want to change the base?
Changes from all commits
fca3754
2d7e432
f7c0e89
69c187a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
composer.lock | ||
tests/.phpunit.result.cache | ||
vendor | ||
/.php-cs-fixer.cache |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__.'/hamcrest') | ||
->in(__DIR__.'/generator') | ||
->in(__DIR__.'/tests') | ||
->notPath('Matchers.php') | ||
->notPath('Hamcrest.php') | ||
->name('*.php') | ||
; | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRules([ | ||
// Use PSR-12 as base but disable the cosmetic rules | ||
'@PSR12' => true, | ||
|
||
// namespace should come directly after the opening tag | ||
'blank_line_after_opening_tag' => false, | ||
'linebreak_after_opening_tag' => true, | ||
'blank_lines_before_namespace' => ['min_line_breaks' => 1, 'max_line_breaks' => 1], | ||
|
||
// add semicolons to the last lines of chained calls | ||
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'], | ||
'method_chaining_indentation' => true, | ||
|
||
// parentheses on new expressions when there are no arguments | ||
'new_with_parentheses' => ['named_class' => true, 'anonymous_class' => true], | ||
|
||
// use consistent naming for boolean, bool, integer, int, etc | ||
'phpdoc_scalar' => true, | ||
|
||
// allow a new line after the class opening | ||
'no_blank_lines_after_class_opening' => false, | ||
|
||
]) | ||
->setFinder($finder) | ||
->setRiskyAllowed(false) | ||
; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,8 +39,8 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti | |
{ | ||
//Not using appendValueList() so that keys can be shown | ||
$mismatchDescription->appendText('array was ') | ||
->appendText('[') | ||
; | ||
->appendText('[') | ||
; | ||
Comment on lines
41
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $mismatchDescription
->appendText('array was ')
->appendText('[')
; |
||
$loop = false; | ||
foreach ($array as $key => $value) { | ||
if ($loop) { | ||
|
@@ -55,9 +55,9 @@ protected function describeMismatchSafely($array, Description $mismatchDescripti | |
public function describeTo(Description $description) | ||
{ | ||
$description | ||
->appendText('array with key ') | ||
->appendDescriptionOf($this->_keyMatcher) | ||
; | ||
->appendText('array with key ') | ||
->appendDescriptionOf($this->_keyMatcher) | ||
; | ||
Comment on lines
57
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks more concise to me! |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,23 +28,23 @@ interface Matcher extends SelfDescribing | |
* | ||
* @param mixed $item the object against which the matcher is evaluated. | ||
* | ||
* @return boolean <code>true</code> if <var>$item</var> matches, | ||
* @return bool <code>true</code> if <var>$item</var> matches, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up for discussion of course, i like it more if its concise (but dont care if its boolean or bool) |
||
* otherwise <code>false</code>. | ||
* | ||
* @see Hamcrest\BaseMatcher | ||
*/ | ||
public function matches($item); | ||
|
||
/** | ||
* Generate a description of why the matcher has not accepted the item. | ||
* The description will be part of a larger description of why a matching | ||
* failed, so it should be concise. | ||
* This method assumes that <code>matches($item)</code> is false, but | ||
* will not check this. | ||
* | ||
* @param mixed $item The item that the Matcher has rejected. | ||
* @param Description $description | ||
* @return | ||
*/ | ||
/** | ||
* Generate a description of why the matcher has not accepted the item. | ||
* The description will be part of a larger description of why a matching | ||
* failed, so it should be concise. | ||
* This method assumes that <code>matches($item)</code> is false, but | ||
* will not check this. | ||
* | ||
* @param mixed $item The item that the Matcher has rejected. | ||
* @param Description $description | ||
* @return | ||
*/ | ||
public function describeMismatch($item, Description $description); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably write it more like: