Skip to content
Permalink
Browse files

Add PSR12 ruleset

  • Loading branch information...
KorvinSzanto committed Feb 18, 2018
1 parent c7bd6cc commit c0b642c186d8f666a64937c2d37442dc77f6f393
@@ -1,3 +1,4 @@
/.idea

This comment has been minimized.

Copy link
@damianopetrungaro

damianopetrungaro Jun 19, 2018

Add this into your .git/info/exclude and avoid committing it here 😄

/.php_cs
/composer.lock
/phpunit.xml
@@ -12,6 +12,8 @@
namespace PhpCsFixer;
use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
/**
@@ -55,6 +57,44 @@ final class RuleSet implements RuleSetInterface
'switch_case_space' => true,
'visibility_required' => true,
],
'@PSR12' => [

This comment has been minimized.

Copy link
@keradus

keradus Mar 29, 2018

hi, what would you say for raising PR for official repo @KorvinSzanto ? :)

This comment has been minimized.

Copy link
@KorvinSzanto

KorvinSzanto Apr 8, 2018

Author Owner

We have a bunch of issues to clear out before we can get this merged IMO. See https://github.com/KorvinSzanto/PHP-CS-Fixer/milestones

This comment has been minimized.

Copy link
@keradus

keradus Apr 11, 2018

well, they dont need to go all at once, could be done step by step ;)
what would you say ?

'@PSR2' => true,
'single_import_per_statement' => false,
'lowercase_cast' => true,
'short_scalar_cast' => true,
'blank_line_after_opening_tag' => true,
'no_leading_import_slash' => true,
'ordered_imports' => [
'importsOrder' => [
OrderedImportsFixer::IMPORT_TYPE_CLASS,
OrderedImportsFixer::IMPORT_TYPE_FUNCTION,
OrderedImportsFixer::IMPORT_TYPE_CONST,
]
],
'declare_equal_normalize' => [
'space' => 'none'
],
'new_with_braces' => true,
'braces' => [
'allow_single_line_closure' => false,
'position_after_functions_and_oop_constructs' => BracesFixer::LINE_NEXT,
'position_after_control_structures' => BracesFixer::LINE_SAME,
'position_after_anonymous_constructs' => BracesFixer::LINE_SAME
],
'no_blank_lines_after_class_opening' => true,
'no_extra_blank_lines' => false,
'ordered_class_elements' => [
'order' => ['use_trait']
],
'visibility_required' => [
'elements' => ['const', 'method', 'property']
],
'binary_operator_spaces' => true,
'ternary_operator_spaces' => true,
'unary_operator_spaces' => true,
'return_type_declaration' => true,
'no_trailing_whitespace' => true,
],
'@Symfony' => [
'@PSR2' => true,
'binary_operator_spaces' => true,
@@ -0,0 +1,4 @@
--TEST--
Integration of @PSR12.
--RULESET--
{"@PSR12": true}
@@ -0,0 +1,147 @@
<?php declare( strict_types = 1 );
namespace Vendor\Package;
use const \Vendor\Package\{ConstantA, ConstantB, ConstantC};
use \Vendor\Package\{ClassA as A, ClassB, ClassC as C};
use function Vendor\Package\{functionA, functionB, functionC};
use Vendor\Package\SomeNamespace\ClassD as D;
class Foo extends Bar implements FooInterface {
public function sampleFunction(int $a, int $b = null): array
{
if ($someLine === 'Longer Than 120 characters' && $respected->getVersion() === 'PSR12' && $respected->lineLengthRecommendeations() === false) {
bar();
}
$moreThan = 1;
$statement = 'per line';
if ($a === $b) {
bar();
} elseif ($a > $b) {
$foo->bar($arg1);
} else {
BazClass::bar($arg2, $arg3);
}
}
final public static function bar()
{
// method body
}
CONST LOWER_CONSTANTS = 1;
ABSTRACT STATIC PUBLIC FUNCTION lowercaseReservedKeywords(CALLABLE $a)
{
GLOBAL $test;
RETURN PRINT CLONE ARRAY() AND NEW stdClass OR $g INSTANCEOF stdClass XOR 4;
LIST($test) = EVAL('');
UNSET($test);
TRUE AND FALSE;
(STRING) 1;
(BOOLEAN) 1;
(INTEGER) 1;
ECHO FUNCTION () USE ($array) {
};
FOR ($i = 1; $i++; $i > 100) {
WHILE (0) {
SWITCH ($test) {
CASE 1:
BREAK;
}
}
}
}
}
class Foo
extends SomeRediculouslySuperfluouslyLongClassNameThatShouldNeverExistInTheRealWorldMeantToTestOverflow
implements SomeInterface, SomeOtherInterface, YetAnotherInterface {
public function someBody()
{
}
use SomeTrait, SomeOtherTrait;
const SomeConst = 1;
use A, B, C {
B::smallTalk insteadof A;
A::bigTalk insteadof C;
C::mediumTalk as FooBar;
}
protected$doo=4;
private $derp;
protected $doo;
public $derpity;
var $noVisibility;
static $staticNoVisibility;
}
class Foo {
use SomeTrait;
}
class Foo extends ExtendedClass implements
SomeInterface, SomeOtherInterface,
YetAnotherInterface {
public function someMethod () { }
public function fooBarBaz ($arg1,& $arg2 ,$arg3=[])
{
// method body
}
public function lottaArguments($arg1,
$arg2, $arg3) {
}
public final function finalMethod()
{
}
public static function staticMethod()
{
}
public static final function staticMethod()
{
}
public abstract function abstractMethod();
}
declare( ticks = 1 )
{
echo 1;
}
function fooBarBaz($arg1,& $arg2 ,$arg3=[]){
// function body
}
function lottaArguments($arg1,& $arg2 ,
$arg3=[]) :?string
{
// function body
}
factoryFunction ( $arg1 , $arg2 )->method ($arg1,$arg2);
factoryFunction( $arg1,
$arg2, $arg3);
factoryFunction($arg1, $arg2, [
1,
2,
3
], $arg4);
?>
@@ -0,0 +1,155 @@
<?php
declare(strict_types=1);
namespace Vendor\Package;
use Vendor\Package\SomeNamespace\ClassD as D;
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
use function Vendor\Package\{functionA, functionB, functionC};
use const Vendor\Package\{ConstantA, ConstantB, ConstantC};
class Foo extends Bar implements FooInterface
{
public function sampleFunction(int $a, int $b = null): array
{
if ($someLine === 'Longer Than 120 characters' && $respected->getVersion() === 'PSR12' && $respected->lineLengthRecommendeations() === false) {
bar();
}
$moreThan = 1;
$statement = 'per line';
if ($a === $b) {
bar();
} elseif ($a > $b) {
$foo->bar($arg1);
} else {
BazClass::bar($arg2, $arg3);
}
}
final public static function bar()
{
// method body
}
public const LOWER_CONSTANTS = 1;
abstract public static function lowercaseReservedKeywords(callable $a)
{
global $test;
return print clone array() and new stdClass() or $g instanceof stdClass xor 4;
list($test) = eval('');
unset($test);
true and false;
(string) 1;
(bool) 1;
(int) 1;
echo function () use ($array) {
};
for ($i = 1; $i++; $i > 100) {
while (0) {
switch ($test) {
case 1:
break;
}
}
}
}
}
class Foo extends SomeRediculouslySuperfluouslyLongClassNameThatShouldNeverExistInTheRealWorldMeantToTestOverflow implements SomeInterface, SomeOtherInterface, YetAnotherInterface
{
use SomeTrait, SomeOtherTrait;
use A, B, C {
B::smallTalk insteadof A;
A::bigTalk insteadof C;
C::mediumTalk as FooBar;
}
public function someBody()
{
}
public const SomeConst = 1;
protected $doo = 4;
private $derp;
protected $doo;
public $derpity;
public $noVisibility;
public static $staticNoVisibility;
}
class Foo
{
use SomeTrait;
}
class Foo extends ExtendedClass implements
SomeInterface,
SomeOtherInterface,
YetAnotherInterface
{
public function someMethod()
{
}
public function fooBarBaz($arg1, &$arg2, $arg3 = [])
{
// method body
}
public function lottaArguments(
$arg1,
$arg2,
$arg3
) {
}
final public function finalMethod()
{
}
public static function staticMethod()
{
}
final public static function staticMethod()
{
}
abstract public function abstractMethod();
}
declare(ticks=1) {
echo 1;
}
function fooBarBaz($arg1, &$arg2, $arg3 = [])
{
// function body
}
function lottaArguments(
$arg1,
&$arg2,
$arg3 = []
): ?string {
// function body
}
factoryFunction($arg1, $arg2)->method($arg1, $arg2);
factoryFunction(
$arg1,
$arg2,
$arg3
);
factoryFunction($arg1, $arg2, [
1,
2,
3
], $arg4);

5 comments on commit c0b642c

@TomasVotruba

This comment has been minimized.

Copy link

replied Mar 22, 2018

Hey, I'm trying to simulate same ruleset on ECS:
Symplify/Symplify#706

But it keeps failing on new line items indentation:
https://travis-ci.org/Symplify/Symplify/jobs/356820074#L562

image

All other items work perfectly 👍

Is there any Travis for this commit/PR?

@TomasVotruba

This comment has been minimized.

Copy link

replied Mar 22, 2018

Ok, it probably works while running from CLI:

git clone  https://github.com/KorvinSzanto/PHP-CS-Fixer.git
git checkout feature/psr12
composer update
vendor/bin/phpunit tests/IntegrationTest.php  

image

Got any clue which fixer is responsible for that error of mine?

@TomasVotruba

This comment has been minimized.

Copy link

replied Mar 22, 2018

But when I run PHP CS Fixer on this change (/trial is directory with the broken code provided here):

php php-cs-fixer fix --dry-run trial --rules=@PSR12 -v --diff

It ends up failing:

image

@KorvinSzanto

This comment has been minimized.

Copy link
Owner Author

replied Apr 8, 2018

See #9

@TomasVotruba

This comment has been minimized.

Copy link

replied Apr 8, 2018

I'll keep my eyes on it, thanks!

In the meantime the set is available in packages for testing:

composer require symplify/easy-coding-standard --dev
vendor/bin/ecs check /src --level psr12 

# for fixing all fixable found changes
vendor/bin/ecs check /src --level psr12 --fix
Please sign in to comment.
You can’t perform that action at this time.