Giter Club home page Giter Club logo

coding-standard's Introduction

Coding Standard

Downloads

Set of rules for PHP_CodeSniffer and PHP-CS-Fixer used by Symplify projects.

They run best with EasyCodingStandard.

Install

composer require symplify/coding-standard --dev
composer require symplify/easy-coding-standard --dev
  1. Run with ECS:
# ecs.php
 use Symplify\EasyCodingStandard\Config\ECSConfig;
+use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

 return static function (ECSConfig $ecsConfig): void {
+    $ecsConfig->sets([SetList::SYMPLIFY]);

Rules Overview

coding-standard's People

Contributors

actions-user avatar gnutix avatar ruudk avatar rvanvelzen avatar samsonasik avatar tomasvotruba avatar wirone avatar zonuexe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coding-standard's Issues

[PHP 8.2] Undefined constant "Symplify\CodingStandard\TokenAnalyzer\T_OPEN_CURLY_BRACKET"

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.

ParamReturnAndVarTagMalformsFixer incorrectly replaces both duplicated PHPDoc

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!

[BUG] LineLengthFixer: incorrectly takes phpdoc length into account

<?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

image

I don't know how to fix it, however

PHP7 Sniffs

Use return type when possible

/**
 * @return int
 */
public function getValue()
{
}

=>

public function getValue() : int
{
}

Use args type when possible

Same for args:

/**
 * @param int $amount
 */
public function count($amount)
{
}

=>

public function count(int $amount)
{
}

Unite return type format

// Class
public function getValue() : int

// Interface
public function getValue() : int;

Use strict_value when needed

When somewhere is some arg/return type, make this required.

<?php 

declare (strict_types = 1);

Changing from 0.1.3 to 0.1.4 breaks code sniffer.

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.

Add Utf8 support for LineLengthFixer

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

[BUG] MethodChainingNewLineFixer: incorrectly aligns parameter of chained method result

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;
    }
}

Support new PER Coding Standard

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.