Skip to content

Import advanced PHP 7.1 sniffs #9

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

Merged
merged 1 commit into from
Dec 26, 2017
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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
},
"require": {
"php": "^7.1",
"squizlabs/php_codesniffer": "~3.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.2"
"squizlabs/php_codesniffer": "^3.0.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.2",
"slevomat/coding-standard": "^4.0"
},
"extra": {
"branch-alias": {
Expand Down
57 changes: 0 additions & 57 deletions lib/Doctrine/Sniffs/Spacing/EnsureSpaces.php

This file was deleted.

40 changes: 0 additions & 40 deletions lib/Doctrine/Sniffs/Spacing/SpaceOnReturnTypeSniff.php

This file was deleted.

122 changes: 122 additions & 0 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,128 @@
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
<type>error</type>
</rule>
<!-- Require comma after last element in multi-line array -->
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<!-- Require presence of constant visibility -->
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
<!-- Forbid dead code -->
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements"/>
<!-- Forbid useless annotations - Git and LICENCE file provide more accurate information -->
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<properties>
<property
name="forbiddenAnnotations"
type="array"
value="
@author,
@copyright,
@created,
@license,
@package,
@since,
@version
"
/>
</properties>
</rule>
<!-- report invalid format of inline phpDocs with @var -->
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
<!-- Forbid assignments in conditions -->
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
<!-- Forbid fancy yoda conditions -->
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
<!-- Forbid weak comparisons -->
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>
<!-- Require language constructs without parentheses -->
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
<!-- Forbid useless unreachable catch blocks -->
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
<!-- Require using Throwable instead of Exception -->
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
<!-- Require use statements to be alphabetically sorted -->
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<!-- Forbid fancy group uses -->
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
<!-- Forbid multiple use statements on same line -->
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
<!-- Forbid using absolute class name references (except global ones) -->
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="allowFullyQualifiedGlobalClasses" type="boolean" value="true"/>
<property name="allowFullyQualifiedGlobalFunctions" type="boolean" value="true"/>
<property name="allowFullyQualifiedGlobalConstants" type="boolean" value="true"/>
<property name="allowFullyQualifiedNameForCollidingClasses" type="boolean" value="true"/>
</properties>
</rule>
<!-- Forbid unused use statements -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" type="boolean" value="true"/>
</properties>
</rule>
<!-- Forbid superfluous leading backslash in use statements -->
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
<!-- Forbid useless uses of the same namespace -->
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>
<!-- Require presence of declare(strict_types=1) -->
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property
name="newlinesCountBetweenOpenTagAndDeclare"
value="2"
/>
<property
name="spacesCountAroundEqualsSign"
value="0"
/>
</properties>
</rule>
<!-- Require use of short versions of scalar types (i.e. int instead of integer) -->
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
<!-- Require ? when default value is null -->
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
<!-- Require one space between typehint and variable, require no space between nullability sign and typehint -->
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
<!-- Require space around colon in return types -->
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
<properties>
<property name="spacesCountBeforeColon" value="1"/>
</properties>
</rule>
<!-- 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">
<properties>
<property name="enableEachParameterAndReturnInspection" value="true"/>
<property name="traversableTypeHints" type="array" value="Doctrine\Common\Collections\Collection"/>
<property
name="usefulAnnotations"
type="array"
value="
@dataProvider,
@deprecated,
@expectedException,
@expectedExceptionMessage,
@expectedExceptionMessageRegExp,
@expectedExceptionCode,
@expectedDeprecation,
@group,
@internal,
@link,
@see,
@throws
"
/>
</properties>
</rule>
<!-- Forbid empty lines around type declarations -->
<rule ref="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces">
<properties>
<property name="linesCountAfterOpeningBrace" value="0"/>
<property name="linesCountBeforeClosingBrace" value="0"/>
</properties>
</rule>
<!-- Forbid spaces around square brackets -->
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<!-- Force array declaration structure -->
Expand Down
5 changes: 3 additions & 2 deletions tests/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ PHP CODE SNIFFER REPORT SUMMARY
FILE ERRORS WARNINGS
----------------------------------------------------------------------
tests/input/concatenation_spacing.php 24 0
tests/input/example-class.php 13 0
tests/input/not_spacing.php 7 0
tests/input/return_type_on_closures.php 21 0
tests/input/return_type_on_methods.php 17 0
----------------------------------------------------------------------
A TOTAL OF 69 ERRORS AND 0 WARNINGS WERE FOUND IN 4 FILES
A TOTAL OF 82 ERRORS AND 0 WARNINGS WERE FOUND IN 5 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 63 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 72 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


2 changes: 2 additions & 0 deletions tests/fixed/concatenation_spacing.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$string = 'Doctrine' . 'rulez';
$string = 'Doctrine' . 'rulez';
$string = 'Doctrine' . 'rulez';
Expand Down
66 changes: 66 additions & 0 deletions tests/fixed/example-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Example;

use Doctrine\Sniffs\Spacing\ControlStructureSniff;
use function strlen;
use function substr;

/**
* Description
*/
class Example implements \IteratorAggregate
{
/** @var int|null */
private $foo;

/** @var string[] */
private $bar;

/** @var bool */
private $baz;

/** @var ControlStructureSniff|int|string|null */
private $baxBax;

public function __construct(?int $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
{
$this->foo = $foo;
$this->bar = $bar;
$this->baz = $baz;
$this->baxBax = $baxBax;
}

/**
* Description
*/
public function getFoo() : ?int
{
return $this->foo;
}

/**
* @return iterable
*/
public function getIterator() : array
{
assert($this->bar !== null);
return new \ArrayIterator($this->bar);
}

public function isBaz() : bool
{
return $this->baz;
}

public function mangleBar(int $length) : void
{
if (! $this->baz) {
throw new \InvalidArgumentException();
}

$this->bar = (string) $this->baxBax ?? substr($this->bar, strlen($this->bar - $length));
}
}
2 changes: 2 additions & 0 deletions tests/fixed/not_spacing.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$test = 1;

if (! $test > 0) {
Expand Down
Loading