This repository has been archived by the owner on Nov 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Start using PSR-2 #2
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6a6ada2
Start using PSR-2
thewilkybarkid bfab27b
Don't ignore blank lines
thewilkybarkid 255feba
Merge branch 'master' into psr-2
thewilkybarkid c9ec707
Line endings
thewilkybarkid 9bdfb17
Method modifiers
thewilkybarkid 08bccd0
Whitespace
thewilkybarkid ba04806
Requires 3.3.1
thewilkybarkid e7f500c
Wrong way round
thewilkybarkid c8bf0b5
Interface extends
thewilkybarkid f1c1af4
Function declaration
thewilkybarkid 5110dbd
Consistency
thewilkybarkid 9a8c45b
Closures
thewilkybarkid 8645d6c
Default arguments
thewilkybarkid cc8c279
No break in switch
thewilkybarkid af5f675
Braces
thewilkybarkid 9505dda
One use statement per declaration
thewilkybarkid c5d9ab4
Methods must not have unnecessary whitespace
thewilkybarkid e230398
Use declarations must go after the namespace declaration
thewilkybarkid 0e89391
Closure defaults
thewilkybarkid 6f86693
No spaces between use declarations
thewilkybarkid 8e270cb
No spaces between use declarations
thewilkybarkid 5941c0c
Use groups must not be used
thewilkybarkid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,9 @@ | |
use function ini_get; | ||
use function mb_convert_encoding; | ||
use function preg_match_all; | ||
use function preg_replace; | ||
use function sort; | ||
use function str_replace; | ||
use function strpos; | ||
use function token_get_all; | ||
use const TOKEN_PARSE; | ||
|
@@ -73,13 +75,16 @@ public function cases() : iterable | |
|
||
$parts = array_combine(array_map('strtolower', $matches[1]), $matches[2]); | ||
|
||
$parts['filename'] = $parts['filename'] ?? 'test.php'; | ||
|
||
if (isset($parts['messages'])) { | ||
$parts['messages'] = array_filter(explode("\n", $parts['messages'])); | ||
} | ||
|
||
$keys = ['fixed', 'fixed-encoding', 'fixed-line-endings', 'messages']; | ||
if (empty($parts['contents'])) { | ||
throw new LogicException("Couldn't find contents in {$file->getRelativePathname()}"); | ||
} elseif (empty(select_keys($parts, $keys = ['fixed', 'fixed-encoding', 'messages']))) { | ||
} elseif (empty(select_keys($parts, $keys))) { | ||
throw new LogicException("Expected one of ".implode(', ', $keys)." in {$file->getRelativePathname()}"); | ||
} | ||
|
||
|
@@ -90,6 +95,11 @@ public function cases() : iterable | |
throw new LogicException($message, 0, $exception); | ||
} | ||
|
||
if (!empty($parts['line-endings'])) { | ||
$parts['line-endings'] = str_replace(['\n', '\r'], ["\n", "\r"], $parts['line-endings']); | ||
$parts['contents'] = preg_replace('~\R~', $parts['line-endings'], $parts['contents']); | ||
} | ||
|
||
if (!empty($parts['fixed'])) { | ||
try { | ||
token_get_all($parts['fixed'], TOKEN_PARSE); | ||
|
@@ -109,10 +119,17 @@ public function cases() : iterable | |
$parts['contents'] = mb_convert_encoding($parts['contents'], $parts['encoding']); | ||
} | ||
|
||
$parts['fixed'] = $parts['fixed'] ?? $parts['contents']; | ||
|
||
if (!empty($parts['fixed-line-endings'])) { | ||
$parts['fixed-line-endings'] = str_replace(['\n', '\r'], ["\n", "\r"], $parts['fixed-line-endings']); | ||
$parts['fixed'] = preg_replace('~\R~', $parts['fixed-line-endings'], $parts['fixed']); | ||
} | ||
|
||
yield $file->getRelativePathname() => [ | ||
$parts['filename'] ?? 'test.php', | ||
"{$file->getRelativePathname()}/{$parts['filename']}", | ||
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. There's some caching inside Slevomat Coding Standard so we need to make sure these are all considered unique. |
||
$parts['contents'], | ||
$parts['fixed'] ?? $parts['contents'], | ||
$parts['fixed'], | ||
$parts['messages'] ?? [], | ||
$parts['description'] ?? null, | ||
$parts['fixed-encoding'] ?? null, | ||
|
@@ -127,7 +144,7 @@ private function createFile(string $filename, string $content) : File | |
} | ||
|
||
$file = new DummyFile( | ||
"phpcs_input_file:${filename}\n{$content}", | ||
"phpcs_input_file:before/${filename}\n{$content}", | ||
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. See #2 (comment). |
||
self::$codeSniffer->ruleset, | ||
self::$codeSniffer->config | ||
); | ||
|
@@ -137,7 +154,7 @@ private function createFile(string $filename, string $content) : File | |
$file->fixer->fixFile(); | ||
|
||
$file = new DummyFile( | ||
"phpcs_input_file:${filename}\n{$file->fixer->getContents()}", | ||
"phpcs_input_file:after/${filename}\n{$file->fixer->getContents()}", | ||
self::$codeSniffer->ruleset, | ||
self::$codeSniffer->config | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
---DESCRIPTION--- | ||
Extends keyword must be on the same line as the class name | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
extends Bar | ||
{ | ||
} | ||
|
||
---FIXED--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo extends Bar | ||
{ | ||
} | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
---DESCRIPTION--- | ||
Implements keyword must be on the same line as the class name | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
implements Bar | ||
{ | ||
} | ||
|
||
---FIXED--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo implements Bar | ||
{ | ||
} | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
---DESCRIPTION--- | ||
Method braces must be on separate lines. | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
public function bar() : void { $baz = 'qux'; } | ||
} | ||
|
||
---FIXED--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
public function bar() : void | ||
{ | ||
$baz = 'qux'; | ||
} | ||
} | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
---DESCRIPTION--- | ||
Methods must not have unnecessary whitespace | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
public function bar ( $baz ,&$qux, bool$quux, ? string $quuz =null , string...$corge ): | ||
void | ||
{ | ||
} | ||
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. Can't include an |
||
} | ||
|
||
---FIXED--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
public function bar($baz, &$qux, bool $quux, ?string $quuz = null, string ...$corge) : void | ||
{ | ||
} | ||
} | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
---DESCRIPTION--- | ||
Default values must go at the end | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
public function bar($baz = [], $qux) : void | ||
{ | ||
} | ||
} | ||
|
||
---MESSAGES--- | ||
7:36 PEAR.Functions.ValidDefaultValue.NotAtEnd | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
---DESCRIPTION--- | ||
Method modifiers must come in the order: final/abstract, visibility, static. | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
abstract class Foo | ||
{ | ||
protected abstract function bar() : void; | ||
|
||
static public final function baz() : void | ||
{ | ||
} | ||
} | ||
|
||
---FIXED--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
abstract class Foo | ||
{ | ||
abstract protected function bar() : void; | ||
|
||
final public static function baz() : void | ||
{ | ||
} | ||
} | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
---DESCRIPTION--- | ||
Method names must not begin with an underscore to indicate visibility | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
private function _bar() : void | ||
{ | ||
} | ||
} | ||
|
||
---MESSAGES--- | ||
7:13 PSR2.Methods.MethodDeclaration.Underscore | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
---DESCRIPTION--- | ||
Methods must have visibility declared | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
function bar() : void | ||
{ | ||
} | ||
} | ||
|
||
---MESSAGES--- | ||
7:5 Squiz.Scope.MethodScope.Missing | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
---DESCRIPTION--- | ||
One property per declaration | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
public $bar, $baz; | ||
} | ||
|
||
---MESSAGES--- | ||
7:12 PSR2.Classes.PropertyDeclaration.Multiple | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
---DESCRIPTION--- | ||
Property names must not begin with an underscore to indicate visibility | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
private $_bar; | ||
} | ||
|
||
---MESSAGES--- | ||
7:13 PSR2.Classes.PropertyDeclaration.Underscore | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
---DESCRIPTION--- | ||
Class properties must have visibility declared | ||
---FILENAME--- | ||
Foo.php | ||
---CONTENTS--- | ||
<?php | ||
|
||
namespace Vendor; | ||
|
||
class Foo | ||
{ | ||
var $bar; | ||
} | ||
|
||
---MESSAGES--- | ||
7:9 PSR2.Classes.PropertyDeclaration.ScopeMissing | ||
7:9 PSR2.Classes.PropertyDeclaration.VarUsed | ||
--- |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
No example for
trait
s yet, waiting for squizlabs/PHP_CodeSniffer#2140 to the merged/released.