Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

[CS] Improving README #2079

Merged
merged 4 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/coding-standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ includes:

## Rules Overview

- [PHP_CodeSniffer Sniffs](/docs/php_code_sniffer_sniffs.md)
- [PHP CS Fixer Fixers](/docs/phpcs_fixer_fixers.md)
- [PHP_CodeSniffer sniffs](/docs/php_code_sniffer_sniffs.md)
- [PHP CS Fixer fixers](/docs/phpcs_fixer_fixers.md)
- [PHPStan rules](/docs/phpstan_rules.md)
- [Object Calisthenics rules](/docs/phpstan_rules.md#object-calisthenics-rules)
- [Cognitive Complexity rules](/docs/phpstan_rules.md#cognitive-complexity)
Expand Down
2 changes: 1 addition & 1 deletion packages/coding-standard/docs/php_code_sniffer_sniffs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## There should not be comments with valid code

- class: [`Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff`](src/Sniffs/Debug/CommentedOutCodeSniff.php)
- class: [`Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff`](../src/Sniffs/Debug/CommentedOutCodeSniff.php)

```php
<?php
Expand Down
12 changes: 6 additions & 6 deletions packages/coding-standard/docs/phpcs_fixer_fixers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Strict Types Declaration has to be Followed by Empty Line

- class: [`BlankLineAfterStrictTypesFixer`](src/Fixer/Strict/BlankLineAfterStrictTypesFixer.php)
- class: [`BlankLineAfterStrictTypesFixer`](../src/Fixer/Strict/BlankLineAfterStrictTypesFixer.php)

```php
<?php
Expand All @@ -22,7 +22,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
```diff
<?php

declare(strict_types=1);
declare(strict_types=1);
+
namespace SomeNamespace;
```
Expand All @@ -31,7 +31,7 @@ declare(strict_types=1);

## Parameters, Arguments and Array items should be on the same/standalone line to fit Line Length

- class: [`LineLengthFixer`](src/Fixer/LineLength/LineLengthFixer.php)
- class: [`LineLengthFixer`](../src/Fixer/LineLength/LineLengthFixer.php)

```php
<?php
Expand Down Expand Up @@ -79,7 +79,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {

## Block comment should not have 2 empty lines in a row

- class: [`RemoveSuperfluousDocBlockWhitespaceFixer`](src/Fixer/Commenting/RemoveSuperfluousDocBlockWhitespaceFixer.php)
- class: [`RemoveSuperfluousDocBlockWhitespaceFixer`](../src/Fixer/Commenting/RemoveSuperfluousDocBlockWhitespaceFixer.php)

```php
<?php
Expand Down Expand Up @@ -113,7 +113,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {

## Indexed PHP arrays should have 1 item per line

- class: [`StandaloneLineInMultilineArrayFixer`](src/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer.php)
- class: [`StandaloneLineInMultilineArrayFixer`](../src/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer.php)

```php
<?php
Expand Down Expand Up @@ -142,7 +142,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {

## Make `@param`, `@return` and `@var` Format United

- class: [`ParamReturnAndVarTagMalformsFixer`](src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php)
- class: [`ParamReturnAndVarTagMalformsFixer`](../src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php)

```php
<?php
Expand Down
44 changes: 22 additions & 22 deletions packages/coding-standard/docs/phpstan_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Inspired by [Null Hell](https://afilina.com/null-hell) by @afilina

- class: [`NoNullableParameterRule`](src/Rules/NoNullableParameterRule.php)
- class: [`NoNullableParameterRule`](../src/Rules/NoNullableParameterRule.php)

```yaml
# phpstan.neon
Expand All @@ -25,7 +25,7 @@ class SomeClass

## No Parameter can Have Default Value

- class: [`NoDefaultParameterValueRule`](src/Rules/NoDefaultParameterValueRule.php)
- class: [`NoDefaultParameterValueRule`](../src/Rules/NoDefaultParameterValueRule.php)

```yaml
# phpstan.neon
Expand All @@ -48,7 +48,7 @@ class SomeClass

Covers `Interface` suffix as well, e.g `EventSubscriber` checks for `EventSubscriberInterface` as well.

- class: [`ClassNameRespectsParentSuffixRule`](src/Rules/ClassNameRespectsParentSuffixRule.php)
- class: [`ClassNameRespectsParentSuffixRule`](../src/Rules/ClassNameRespectsParentSuffixRule.php)

```yaml
# phpstan.neon
Expand All @@ -74,7 +74,7 @@ class Some extends Command // should be "SomeCommand"

## Debug functions Cannot Be left in the Code

- class: [`NoDebugFuncCallRule`](src/Rules/NoDebugFuncCallRule.php)
- class: [`NoDebugFuncCallRule`](../src/Rules/NoDebugFuncCallRule.php)

```yaml
# phpstan.neon
Expand All @@ -95,7 +95,7 @@ var_dump($value);

## Use explicit comparison over `empty()`

- class: [`NoEmptyRule`](src/Rules/NoEmptyRule.php)
- class: [`NoEmptyRule`](../src/Rules/NoEmptyRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -130,7 +130,7 @@ final class SomeClass

## Prevent Override of Parent Method Visbility

- class: [`PreventParentMethodVisibilityOverrideRule`](src/Rules/PreventParentMethodVisibilityOverrideRule.php)
- class: [`PreventParentMethodVisibilityOverrideRule`](../src/Rules/PreventParentMethodVisibilityOverrideRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -160,7 +160,7 @@ final class PublicOverride extends ProtectedVisibility

## Use explicit Property Fetch Names over Dynamic

- class: [`NoDynamicPropertyFetchNameRule`](src/Rules/NoDynamicPropertyFetchNameRule.php)
- class: [`NoDynamicPropertyFetchNameRule`](../src/Rules/NoDynamicPropertyFetchNameRule.php)

```yaml
# phpstan.neon
Expand All @@ -184,7 +184,7 @@ final class DynamicPropertyFetchName

## No Function Call on Method Call

- class: [`NoFunctionCallInMethodCallRule`](src/Rules/NoFunctionCallInMethodCallRule.php)
- class: [`NoFunctionCallInMethodCallRule`](../src/Rules/NoFunctionCallInMethodCallRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -231,7 +231,7 @@ final class SomeClass

## No Array Access on Object

- class: [`NoArrayAccessOnObjectRule`](src/Rules/NoArrayAccessOnObjectRule.php)
- class: [`NoArrayAccessOnObjectRule`](../src/Rules/NoArrayAccessOnObjectRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -286,7 +286,7 @@ final class SomeClass

## No isset on objects

- class: [`NoIssetOnObjectRule`](src/Rules/NoIssetOnObjectRule.php)
- class: [`NoIssetOnObjectRule`](../src/Rules/NoIssetOnObjectRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -335,7 +335,7 @@ final class IssetOnObject

## Use explicit Method Names over Dynamic

- class: [`NoDynamicMethodNameRule`](src/Rules/NoDynamicMethodNameRule.php)
- class: [`NoDynamicMethodNameRule`](../src/Rules/NoDynamicMethodNameRule.php)

```yaml
# phpstan.neon
Expand All @@ -358,7 +358,7 @@ final class DynamicMethodCallName

## Use explicit return values over magic "&$variable" reference

- class: [`NoReferenceRule`](src/Rules/NoReferenceRule.php)
- class: [`NoReferenceRule`](../src/Rules/NoReferenceRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -389,7 +389,7 @@ function someFunction($var)

## Class "%s" inherits from forbidden parent class "%s". Use Composition over Inheritance instead

- class: [`ForbiddenParentClassRule`](src/Rules/ForbiddenParentClassRule.php)
- class: [`ForbiddenParentClassRule`](../src/Rules/ForbiddenParentClassRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -437,7 +437,7 @@ final class ProductRepository

## Use custom exceptions instead of Native Ones

- class: [`NoDefaultExceptionRule`](src/Rules/NoDefaultExceptionRule.php)
- class: [`NoDefaultExceptionRule`](../src/Rules/NoDefaultExceptionRule.php)

```yaml
# phpstan.neon
Expand All @@ -463,7 +463,7 @@ throw new FileNotFoundExceptoin('...');

## Forbidden return of `require_once()`/`incude_once()`

- class: [`ForbidReturnValueOfIncludeOnceRule`](src/Rules/ForbidReturnValueOfIncludeOnceRule.php)
- class: [`ForbidReturnValueOfIncludeOnceRule`](../src/Rules/ForbidReturnValueOfIncludeOnceRule.php)

```php
// ecs.php
Expand Down Expand Up @@ -495,7 +495,7 @@ class SomeClass

## Boolish Methods has to have is/has/was Name

- class: [`BoolishClassMethodPrefixRule`](src/Rules/BoolishClassMethodPrefixRule.php)
- class: [`BoolishClassMethodPrefixRule`](../src/Rules/BoolishClassMethodPrefixRule.php)

```php
// ecs.php
Expand Down Expand Up @@ -540,7 +540,7 @@ class SomeClass

## Constant type Must Match its Value

- class: [`MatchingTypeConstantRule`](src/Rules/MatchingTypeConstantRule.php)
- class: [`MatchingTypeConstantRule`](../src/Rules/MatchingTypeConstantRule.php)

```php
// ecs.php
Expand Down Expand Up @@ -583,7 +583,7 @@ class SomeClass

## Defined Method Argument should be Always Constant Value

- class: [`ForceMethodCallArgumentConstantRule`](src/Rules/ForceMethodCallArgumentConstantRule.php)
- class: [`ForceMethodCallArgumentConstantRule`](../src/Rules/ForceMethodCallArgumentConstantRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -616,7 +616,7 @@ class SomeClass

## Require @see annotation to class Test case by Type

- class: [`SeeAnnotationToTestRule`](src/Rules/SeeAnnotationToTestRule.php)
- class: [`SeeAnnotationToTestRule`](../src/Rules/SeeAnnotationToTestRule.php)

```yaml
# phpstan.neon
Expand Down Expand Up @@ -656,7 +656,7 @@ class SomeRule implements Rule

## Prefer Another Class

- class: [`PreferredClassRule`](src/Rules/PreferredClassRule.php)
- class: [`PreferredClassRule`](../src/Rules/PreferredClassRule.php)

```yaml
# phpstan.neon
Expand All @@ -679,7 +679,7 @@ $dateTime = new DateTime('now'); // should be "Nette\Utils\DateTime"

## Classes with Static Methods must have "Static" in the Name

- class: [`Symplify\CodingStandard\Rules\NoClassWithStaticMethodWithoutStaticNameRule`](src/Rules/NoClassWithStaticMethodWithoutStaticNameRule.php)
- class: [`Symplify\CodingStandard\Rules\NoClassWithStaticMethodWithoutStaticNameRule`](../src/Rules/NoClassWithStaticMethodWithoutStaticNameRule.php)

Be honest about static. [Why is static bad?](https://tomasvotruba.com/blog/2019/04/01/removing-static-there-and-back-again/)

Expand Down Expand Up @@ -707,7 +707,7 @@ class FormatConverter // should be: "StaticFormatConverter"

## Use Unique Class Short Names

- class: [`Symplify\CodingStandard\Rules\NoDuplicatedShortClassNameRule`](src/Rules/NoDuplicatedShortClassNameRule.php)
- class: [`Symplify\CodingStandard\Rules\NoDuplicatedShortClassNameRule`](../src/Rules/NoDuplicatedShortClassNameRule.php)

```yaml
# phpstan.neon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
*/
final class NewlineInNestedAnnotationFixer extends AbstractDoctrineAnnotationFixer
{
/**
* @var int
*/
private $indentCounter = 0;

/**
* @var DoctrineBlockFinder
*/
Expand All @@ -35,20 +30,27 @@ public function __construct(DoctrineBlockFinder $doctrineBlockFinder)
parent::__construct();
}

public function getPriority(): int
{
// must run before \PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationIndentationFixer
return 100;
}

public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition('Nested annotation should start on standalone line', []);
}

/**
* @note indent is covered by
* @see \PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationIndentationFixer
*
* @param iterable<\PhpCsFixer\Doctrine\Annotation\Token>&Tokens $tokens
*/
protected function fixAnnotations(Tokens $tokens): void
{
$tokenCount = $tokens->count();

$this->indentCounter = 0;

// what about foreach?
for ($index = 0; $index < $tokenCount; ++$index) {
/** @var Token $currentToken */
Expand All @@ -64,8 +66,6 @@ protected function fixAnnotations(Tokens $tokens): void
continue;
}

++$this->indentCounter;

// docblock opener → skip it
if ($previousToken->isType(DocLexer::T_NONE)) {
continue;
Expand All @@ -75,9 +75,6 @@ protected function fixAnnotations(Tokens $tokens): void
throw new NotImplementedYetException();
}

// add a newline with indent - @todo resolve indent and removing of spaces
$indentWhitespace = str_repeat(' ', ($this->indentCounter - 1) * 4);
$tokens->insertAt($index, new Token(DocLexer::T_NONE, $indentWhitespace));
$tokens->insertAt($index, new Token(DocLexer::T_NONE, ' * '));
$tokens->insertAt($index, new Token(DocLexer::T_NONE, "\n"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="user", indexes={
* @ORM\Index(name="user_id", columns={"another_id"})
* @ORM\Index(name="user_id", columns={"another_id"})
* })
*/
class SomeEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->set(NewlineInNestedAnnotationFixer::class);

$services->set(DoctrineAnnotationIndentationFixer::class)
->call('configure', [[
'indent_mixed_lines' => true,
Expand All @@ -25,5 +27,4 @@
]]);

$services->set(DoctrineAnnotationArrayAssignmentFixer::class);
$services->set(NewlineInNestedAnnotationFixer::class);
};
7 changes: 1 addition & 6 deletions packages/set-config-resolver/src/SetResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@

final class SetResolver
{
/**
* @var string[]
*/
private const OPTION_NAMES = OptionName::SET;

/**
* @var OptionValueResolver
*/
Expand All @@ -36,7 +31,7 @@ public function __construct(SetProviderInterface $setProvider)

public function detectFromInput(InputInterface $input): ?SmartFileInfo
{
$setName = $this->optionValueResolver->getOptionValue($input, self::OPTION_NAMES);
$setName = $this->optionValueResolver->getOptionValue($input, OptionName::SET);
if ($setName === null) {
return null;
}
Expand Down