symplify / coding-standard Goto Github PK
View Code? Open in Web Editor NEWCoding Standard rules for PHP projects with focus on Clean Architecture
License: MIT License
Coding Standard rules for PHP projects with focus on Clean Architecture
License: MIT License
Example code:
<?php
declare(strict_types=1);
class A
{
public function art(): mixed
{
$a = $aq->withRow($q)->name;
$b = $aq->withRow($q)->getName($s);
$c = $aq->withRow($q)->withOtherRow($s)->name;
return $a + $b - $c;
}
}
Expected result after running MethodChainingNewLineFixer:
<?php
declare(strict_types=1);
class A
{
public function art(): mixed
{
$a = $aq->withRow($q)
->name;
$b = $aq->withRow($q)
->getName($s);
$c = $aq->withRow($q)
->withOtherRow($s)
->name;
return $a + $b - $c;
}
}
Reality:
<?php
declare(strict_types=1);
class A
{
public function art(): mixed
{
$a = $aq->withRow($q)
->name;
$b = $aq->withRow($q)
->getName($s);
$c = $aq->withRow($q)
->withOtherRow($s)
->name;
return $a + $b - $c;
}
}
Running with php 7.4 and
After updating symplify/coding-standard version CS stopped working.
MethodCommentReturnTagSniff
was renamed to MethodReturnTypeSniff
.
When using custom ruleset, CS starts throwing error. Within one major version sniffs shouldn't be renamed as it causes bc break.
Suppose you have code like this:
<?php
/**
* @param string $one
* @param string $one
*/
function someFunction($one, $two): void
{
}
The author's intention is to write a param for $one
and $two
, but it mistakenly duplicates $one
.
I use SetList::CLEAN_CODE
from ECS, but it seems to be replaced as follows:
<?php
/**
- * @param string $one
- * @param string $one
+ * @param string $two
+ * @param string $two
*/
function someFunction($one, $two): void
{
}
ParamNameTypoMalformWorker::fixTypos()
certainly seems to have that problem.
We don't want a quick fix as we can fix these manually, but will report them as issues. Thank you for your work!
Hi!
I noticed that the Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer
tries to 'fix' correct multi-line doc-blocks.
The following code:
/**
* @param array<string, array{
* foo: string
* }> $foo
*/
public function test($foo, $bar): void {}
Produces the following diff:
---------- begin diff ----------
/**
- * @param array<string, array{
+ * @param array<string, $bar array{
* foo: string
* }> $foo
*/
----------- end diff -----------
Applied checkers:
* Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer
This doesn't happen when the missing argument ($bar
) is also defined in the doc-block.
/**
* @return int
*/
public function getValue()
{
}
=>
public function getValue() : int
{
}
Same for args:
/**
* @param int $amount
*/
public function count($amount)
{
}
=>
public function count(int $amount)
{
}
// Class
public function getValue() : int
// Interface
public function getValue() : int;
When somewhere is some arg/return type, make this required.
<?php
declare (strict_types = 1);
I get this error when using the ChainMethodCallAnalyzer
.
[Error]
Undefined constant "Symplify\CodingStandard\TokenAnalyzer\T_OPEN_CURLY_BRACKET"
Symplify\CodingStandard\TokenAnalyzer\NewlineAnalyzer->doesContentBeforeBracketRequireNewline()
in vendor/symplify/coding-standard/src/TokenAnalyzer/ChainMethodCallAnalyzer.php at line 36
Symplify\CodingStandard\TokenAnalyzer\ChainMethodCallAnalyzer->isPreceededByFuncCall()
in vendor/symplify/coding-standard/src/Fixer/Spacing/MethodChainingNewlineFixer.php at line 164
Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer->shouldBracketPrefix()
in vendor/symplify/coding-standard/src/Fixer/Spacing/MethodChainingNewlineFixer.php at line 108
Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer->shouldPrefixNewline()
in vendor/symplify/coding-standard/src/Fixer/Spacing/MethodChainingNewlineFixer.php at line 73
Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer->fix()
in .php-cs-fixer.php at line 73
NameWrapper->fix()
in vendor/friendsofphp/php-cs-fixer/src/Runner/Runner.php at line 173
PhpCsFixer\Runner\Runner->fixFile()
in vendor/friendsofphp/php-cs-fixer/src/Runner/Runner.php at line 114
PhpCsFixer\Runner\Runner->fix()
in vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php at line 300
PhpCsFixer\Console\Command\FixCommand->execute()
in vendor/symfony/console/Command/Command.php at line 326
Not sure what causes this and what the best approach to solve this is.
Hello there,
I've noticed that StandaloneLinePromotedPropertyFixer only applies if there are at least two properties in the constructor. I'm unsure if it's a conscious choice or a bug.
Should it be fixed ? Should it be an option to configure the behavior ?
I'm curious to hear your thoughts.
gnutix
Hello,
It would be nice a simple doc to explain how to use this packages with php-cs-fixer without ECS.
Thanks
Hello, I'm not sure where to post this issue.
This repository has a dependency on symplify/rule-doc-generator-contracts, but that repository is a readonly subset of the archived Symplify monorepo.
There is a pending change on main branch allowing nette/utils 4.0.
Could you tag that repository to enable nette/utils upgrade on symplify/coding-standard ?
Thanks for your work!
<?php
declare(strict_types=1);
class TestClass
{
/**
* This is just standard doc comment for method which declaration's length is actually < LineLengthFixer max length
* but it computes this php doc to the method declaration itself
*/
private function testMethod($arg)
{
}
}
?>
when LineLengthFixer is called on this file, it breaks the line and outputs this
I don't know how to fix it, however
No
$array = [1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four'];
Yes!
$array = [
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four'
];
No utf8 support for LineLengthFixer.
The length of the strings is not correctly calculated, because of this, an extra line break is set, where it is not necessary.
The solution would be \Symplify\CodingStandard\TokenRunner\Transformer\FixerTransformer\FirstLineLengthResolver class to use the mb_strlen function instead of strlen, or be able to configure this behavior
Hi. I found this previous issue #52 but it seems to involve modifying vendor files to get it working. I was wondering if you had a different approach to use this with cs fixer. You mentioned you used Laravel, however the project that I'd be using this with does not utilize Laravel. Any direction, thoughts, links on how to pull these fixers into cs fixer would be helpful - Thank you
This may not be immediately actionable, however you may have this as a goal anyway.
Can we get support for the new PHP Evolving Recommendations Coding Standard https://www.php-fig.org/per/coding-style/? Version 1.0 is a copy of PSR12 and is implemented in PHPCS-Fixer. A 1.1 version was expected, however this was recently released as 2.0 and a PR is open to upgrade this in PHPCS-Fixer.
I haven't looked too far into PHPCS, however there is an open issue regarding PERCS 2.0.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.