Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade slevomat/coding-standard to v6 #144

Merged
merged 8 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"require": {
"php": "^7.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"slevomat/coding-standard": "dev-master#469368cc6d8fe83aceba259ef65f1c0a2f63055b",
"squizlabs/php_codesniffer": "^3.5.0"
"slevomat/coding-standard": "^6.0",
"squizlabs/php_codesniffer": "^3.5.3"
},
"config": {
"sort-packages": true
Expand Down
46 changes: 42 additions & 4 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@
<!-- Forbid assignments in conditions -->
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
<!-- Require consistent spacing for block structures -->
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing"/>
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing">
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeControlStructure" />
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeFirstControlStructure" />
</rule>
<!-- Forbid fancy yoda conditions -->
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
<!-- Require usage of early exit -->
Expand Down Expand Up @@ -334,17 +337,52 @@
<!-- Require types to be written as natively if possible;
require iterable types to specify phpDoc with their content;
forbid useless/duplicated information in phpDoc -->
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<properties>
<property name="traversableTypeHints" type="array">
<element value="Traversable"/>
<element value="Iterator"/>
<element value="IteratorAggregate"/>
<element value="Doctrine\Common\Collections\Collection"/>
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<property name="allAnnotationsAreUseful" value="true"/>
<property name="enableEachParameterAndReturnInspection" value="true"/>
<property name="enableNativeTypeHint" value="false"/>
<property name="traversableTypeHints" type="array">
<element value="Traversable"/>
<element value="Iterator"/>
<element value="IteratorAggregate"/>
<element value="Doctrine\Common\Collections\Collection"/>
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<properties>
<property name="traversableTypeHints" type="array">
<element value="Traversable"/>
<element value="Iterator"/>
<element value="IteratorAggregate"/>
<element value="Doctrine\Common\Collections\Collection"/>
</property>
</properties>
</rule>
<!-- Forbid useless @var for constants -->
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
<!-- Forbid useless phpDocs for functions -->
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment">
<properties>
<property name="traversableTypeHints" type="array">
<element value="Traversable"/>
<element value="Iterator"/>
<element value="IteratorAggregate"/>
<element value="Doctrine\Common\Collections\Collection"/>
</property>
</properties>
</rule>
<!-- Forbid useless inherit doc comment -->
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>
<!-- Forbid duplicated variables assignments -->
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
<!-- Forbid useless variables -->
Expand Down
7 changes: 4 additions & 3 deletions tests/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tests/input/constants-var.php 4 0
tests/input/doc-comment-spacing.php 10 0
tests/input/duplicate-assignment-variable.php 1 0
tests/input/EarlyReturn.php 6 0
tests/input/example-class.php 48 0
tests/input/example-class.php 45 0
tests/input/forbidden-comments.php 8 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 7 0
Expand All @@ -32,14 +32,15 @@ tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
tests/input/trailing_comma_on_array.php 1 0
tests/input/traits-uses.php 11 0
tests/input/type-hints.php 4 0
tests/input/UnusedVariables.php 1 0
tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
A TOTAL OF 289 ERRORS AND 0 WARNINGS WERE FOUND IN 33 FILES
A TOTAL OF 290 ERRORS AND 0 WARNINGS WERE FOUND IN 34 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 232 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 229 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


1 change: 1 addition & 0 deletions tests/fixed/example-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function throwWhenInvalid() : void
public function trySwitchSpace() : void
{
try {
$var = 1;
switch (self::VERSION) {
default:
}
Expand Down
24 changes: 24 additions & 0 deletions tests/fixed/type-hints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace TypeHints;

use Iterator;
use Traversable;

class TraversableTypeHints
{
/** @var Traversable */
private $parameter;

/**
* @param Iterator $iterator
*
* @return Traversable
alcaeus marked this conversation as resolved.
Show resolved Hide resolved
*/
public function get(Iterator $iterator) : Traversable
{
return $this->parameter;
}
}
1 change: 1 addition & 0 deletions tests/input/example-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function throwWhenInvalid() : void
public function trySwitchSpace() : void
{
try {
$var = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kinda snuck in: not a problem for me as long as it doesn't remove newlines before control structures, but seems unrelated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ensured the settings for space before block control structures is not modified from current behaviour. The test for it was missing.

switch (self::VERSION) {
default:
}
Expand Down
24 changes: 24 additions & 0 deletions tests/input/type-hints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace TypeHints;

use Iterator;
use Traversable;

class TraversableTypeHints
{
/** @var Traversable */
private $parameter;

/**
* @param Iterator $iterator
*
* @return Traversable
*/
public function get(Iterator $iterator) : Traversable
{
return $this->parameter;
}
}