Skip to content

Commit 69af948

Browse files
committed
Import advanced PHP 7.1 sniffs
1 parent 166df1e commit 69af948

15 files changed

+381
-201
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
},
1717
"require": {
1818
"php": "^7.1",
19-
"squizlabs/php_codesniffer": "~3.0",
20-
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.2"
19+
"squizlabs/php_codesniffer": "^3.0.1",
20+
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.2",
21+
"slevomat/coding-standard": "^4.0"
2122
},
2223
"extra": {
2324
"branch-alias": {

lib/Doctrine/Sniffs/Spacing/EnsureSpaces.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/Doctrine/Sniffs/Spacing/SpaceOnReturnTypeSniff.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

lib/Doctrine/ruleset.xml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,128 @@
6969
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
7070
<type>error</type>
7171
</rule>
72+
<!-- Require comma after last element in multi-line array -->
73+
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
74+
<!-- Require presence of constant visibility -->
75+
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
76+
<!-- Forbid dead code -->
77+
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements"/>
78+
<!-- Forbid useless annotations - Git and LICENCE file provide more accurate information -->
79+
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
80+
<properties>
81+
<property
82+
name="forbiddenAnnotations"
83+
type="array"
84+
value="
85+
@author,
86+
@copyright,
87+
@created,
88+
@license,
89+
@package,
90+
@since,
91+
@version
92+
"
93+
/>
94+
</properties>
95+
</rule>
96+
<!-- report invalid format of inline phpDocs with @var -->
97+
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
98+
<!-- Forbid assignments in conditions -->
99+
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
100+
<!-- Forbid fancy yoda conditions -->
101+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
102+
<!-- Forbid weak comparisons -->
103+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>
104+
<!-- Require language constructs without parentheses -->
105+
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
106+
<!-- Forbid useless unreachable catch blocks -->
107+
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
108+
<!-- Require using Throwable instead of Exception -->
109+
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
110+
<!-- Require use statements to be alphabetically sorted -->
111+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
112+
<!-- Forbid fancy group uses -->
113+
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
114+
<!-- Forbid multiple use statements on same line -->
115+
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
116+
<!-- Forbid using absolute class name references (except global ones) -->
117+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
118+
<properties>
119+
<property name="allowFullyQualifiedGlobalClasses" type="boolean" value="true"/>
120+
<property name="allowFullyQualifiedGlobalFunctions" type="boolean" value="true"/>
121+
<property name="allowFullyQualifiedGlobalConstants" type="boolean" value="true"/>
122+
<property name="allowFullyQualifiedNameForCollidingClasses" type="boolean" value="true"/>
123+
</properties>
124+
</rule>
125+
<!-- Forbid unused use statements -->
126+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
127+
<properties>
128+
<property name="searchAnnotations" type="boolean" value="true"/>
129+
</properties>
130+
</rule>
131+
<!-- Forbid superfluous leading backslash in use statements -->
132+
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
133+
<!-- Forbid useless uses of the same namespace -->
134+
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>
135+
<!-- Require presence of declare(strict_types=1) -->
136+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
137+
<properties>
138+
<property
139+
name="newlinesCountBetweenOpenTagAndDeclare"
140+
value="2"
141+
/>
142+
<property
143+
name="spacesCountAroundEqualsSign"
144+
value="0"
145+
/>
146+
</properties>
147+
</rule>
148+
<!-- Require use of short versions of scalar types (i.e. int instead of integer) -->
149+
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
150+
<!-- Require ? when default value is null -->
151+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
152+
<!-- Require one space between typehint and variable, require no space between nullability sign and typehint -->
153+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
154+
<!-- Require space around colon in return types -->
155+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
156+
<properties>
157+
<property name="spacesCountBeforeColon" value="1"/>
158+
</properties>
159+
</rule>
160+
<!-- Require types to be written as natively if possible;
161+
require iterable types to specify phpDoc with their content;
162+
forbid useless/duplicated information in phpDoc -->
163+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
164+
<properties>
165+
<property name="enableEachParameterAndReturnInspection" value="true"/>
166+
<property name="traversableTypeHints" type="array" value="Doctrine\Common\Collections\Collection"/>
167+
<property
168+
name="usefulAnnotations"
169+
type="array"
170+
value="
171+
@dataProvider,
172+
@deprecated,
173+
@expectedException,
174+
@expectedExceptionMessage,
175+
@expectedExceptionMessageRegExp,
176+
@expectedExceptionCode,
177+
@expectedDeprecation,
178+
@group,
179+
@internal,
180+
@link,
181+
@see,
182+
@throws
183+
"
184+
/>
185+
</properties>
186+
</rule>
187+
<!-- Forbid empty lines around type declarations -->
188+
<rule ref="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces">
189+
<properties>
190+
<property name="linesCountAfterOpeningBrace" value="0"/>
191+
<property name="linesCountBeforeClosingBrace" value="0"/>
192+
</properties>
193+
</rule>
72194
<!-- Forbid spaces around square brackets -->
73195
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
74196
<!-- Force array declaration structure -->

tests/expected_report.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ PHP CODE SNIFFER REPORT SUMMARY
44
FILE ERRORS WARNINGS
55
----------------------------------------------------------------------
66
tests/input/concatenation_spacing.php 24 0
7+
tests/input/example-class.php 13 0
78
tests/input/not_spacing.php 7 0
89
tests/input/return_type_on_closures.php 21 0
910
tests/input/return_type_on_methods.php 17 0
1011
----------------------------------------------------------------------
11-
A TOTAL OF 69 ERRORS AND 0 WARNINGS WERE FOUND IN 4 FILES
12+
A TOTAL OF 82 ERRORS AND 0 WARNINGS WERE FOUND IN 5 FILES
1213
----------------------------------------------------------------------
13-
PHPCBF CAN FIX 63 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
14+
PHPCBF CAN FIX 72 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
1415
----------------------------------------------------------------------
1516

1617

tests/fixed/concatenation_spacing.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
$string = 'Doctrine' . 'rulez';
46
$string = 'Doctrine' . 'rulez';
57
$string = 'Doctrine' . 'rulez';

tests/fixed/example-class.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Example;
6+
7+
use Doctrine\Sniffs\Spacing\ControlStructureSniff;
8+
use function strlen;
9+
use function substr;
10+
11+
/**
12+
* Description
13+
*/
14+
class Example implements \IteratorAggregate
15+
{
16+
/** @var int|null */
17+
private $foo;
18+
19+
/** @var string[] */
20+
private $bar;
21+
22+
/** @var bool */
23+
private $baz;
24+
25+
/** @var ControlStructureSniff|int|string|null */
26+
private $baxBax;
27+
28+
public function __construct(?int $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
29+
{
30+
$this->foo = $foo;
31+
$this->bar = $bar;
32+
$this->baz = $baz;
33+
$this->baxBax = $baxBax;
34+
}
35+
36+
/**
37+
* Description
38+
*/
39+
public function getFoo() : ?int
40+
{
41+
return $this->foo;
42+
}
43+
44+
/**
45+
* @return iterable
46+
*/
47+
public function getIterator() : array
48+
{
49+
assert($this->bar !== null);
50+
return new \ArrayIterator($this->bar);
51+
}
52+
53+
public function isBaz() : bool
54+
{
55+
return $this->baz;
56+
}
57+
58+
public function mangleBar(int $length) : void
59+
{
60+
if (! $this->baz) {
61+
throw new \InvalidArgumentException();
62+
}
63+
64+
$this->bar = (string) $this->baxBax ?? substr($this->bar, strlen($this->bar - $length));
65+
}
66+
}

tests/fixed/not_spacing.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
$test = 1;
46

57
if (! $test > 0) {

0 commit comments

Comments
 (0)