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

fix: unused imports and generics #44

Merged
merged 1 commit into from Oct 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 30 additions & 13 deletions src/LaminasCodingStandard/ruleset.xml
Expand Up @@ -264,13 +264,17 @@
<!-- There MAY NOT be a space around a namespace separator. -->
<rule ref="WebimpressCodingStandard.WhiteSpace.NamespaceSeparator"/>
<!-- Import statements MUST be alphabetically sorted. -->
<rule ref="WebimpressCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<!-- Functions and const keywords MUST be lowercase in import statements. -->
<rule ref="WebimpressCodingStandard.Namespaces.ConstAndFunctionKeywords"/>
<!-- Unused import statements MUST be removed.-->
<rule ref="WebimpressCodingStandard.Namespaces.UnusedUseStatement"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<!-- Superfluous leading backslash in import statements MUST be removed. -->
<rule ref="WebimpressCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
<!-- Fancy group import statements MUST NOT be used. -->
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
<!-- Each import statement MUST be on its own line. -->
Expand All @@ -280,13 +284,23 @@
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
<!-- Import statements aliases for classes, traits, functions and constants
MUST be useful. -->
<rule ref="WebimpressCodingStandard.Namespaces.RedundantAlias"/>
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
<!-- Classes, traits, interfaces, constants and functions MUST be imported. -->
<rule ref="WebimpressCodingStandard.PHP.DisallowFqn"/>
<!-- Internal functions MUST be imported. -->
<rule ref="WebimpressCodingStandard.PHP.ImportInternalFunction"/>
<!-- Internal constants MUST be imported. -->
<rule ref="WebimpressCodingStandard.PHP.ImportInternalConstant"/>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="allowFullyQualifiedGlobalClasses" value="false"/>
<!-- Internal functions MUST be imported. -->
<property name="allowFallbackGlobalFunctions" value="false"/>
<property name="allowFullyQualifiedGlobalFunctions" value="false"/>
<!-- Internal constants MUST be imported. -->
<property name="allowFallbackGlobalConstants" value="false"/>
<property name="allowFullyQualifiedGlobalConstants" value="false"/>
<property name="allowFullyQualifiedNameForCollidingClasses" value="true"/>
<property name="allowFullyQualifiedNameForCollidingConstants" value="true"/>
<property name="allowFullyQualifiedNameForCollidingFunctions" value="true"/>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>

<!-- 4. Classes, Properties, and Methods -->

Expand Down Expand Up @@ -787,11 +801,14 @@

<!-- DocBlocks and comments SHOULD NOT be used for already typehinted arguments,
except arrays. -->
<rule ref="WebimpressCodingStandard.Functions.Param"/>
<rule ref="WebimpressCodingStandard.Functions.ReturnType"/>
<rule ref="WebimpressCodingStandard.Commenting.TagWithType">
<exclude name="WebimpressCodingStandard.Commenting.TagWithType.InvalidOrder"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<property name="enableNativeTypeHint" value="false"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>

<!-- The asterisks in a DocBlock should align, and there should be one
space between the asterisk and tag. -->
Expand Down
27 changes: 14 additions & 13 deletions test/expected-report.txt
Expand Up @@ -7,36 +7,37 @@ test/fixable/2.1.BasicCodingStandard.php 48 1
test/fixable/2.2.Files.php 6 0
test/fixable/2.3.Lines.php 35 0
test/fixable/2.4.IndentingAndSpacing.php 46 0
test/fixable/2.5.KeywordsAndTypes.php 13 0
test/fixable/2.5.KeywordsAndTypes.php 8 0
test/fixable/2.6.Variables.php 3 0
test/fixable/2.7.Arrays.php 9 0
test/fixable/3.DeclareNamespaceAndImport.php 11 0
test/fixable/3.DeclareNamespaceAndImport.php 12 0
test/fixable/4.1.ExtendsAndImplements.php 5 0
test/fixable/4.2.UsingTraits.php 4 0
test/fixable/4.3.PropertiesAndConstants.php 5 0
test/fixable/4.4.MethodsAndFunctions.php 26 0
test/fixable/4.2.UsingTraits.php 5 0
test/fixable/4.3.PropertiesAndConstants.php 7 0
test/fixable/4.4.MethodsAndFunctions.php 27 0
test/fixable/4.5.MethodAndFunctionArguments.php 66 0
test/fixable/4.6.AbstractFinalAndStatic.php 4 0
test/fixable/4.6.AbstractFinalAndStatic.php 5 0
test/fixable/4.7.MethodAndFunctionCalls.php 11 0
test/fixable/4.ClassesPropertiesAndMethods.php 32 0
test/fixable/5.1.IfElseifElse.php 15 1
test/fixable/4.ClassesPropertiesAndMethods.php 34 0
test/fixable/5.1.IfElseifElse.php 13 1
test/fixable/5.2.SwitchCase.php 11 0
test/fixable/5.3.WhileAndDoWhile.php 12 0
test/fixable/5.4.ForStructure.php 7 0
test/fixable/5.4.ForStructure.php 5 0
test/fixable/5.5.ForEachStructure.php 10 0
test/fixable/5.6.TryCatchFinally.php 9 0
test/fixable/5.ControlStructures.php 4 0
test/fixable/6.1.UnaryOperators.php 6 0
test/fixable/6.2.BinaryOperators.php 35 0
test/fixable/6.3.TernaryOperators.php 13 0
test/fixable/6.Operators.php 97 0
test/fixable/7.Closures.php 2 0
test/fixable/7.Closures.php 4 0
test/fixable/8.AnonymousClasses.php 1 0
test/fixable/9.CommentingAndDocBlocks.php 21 0
test/fixable/9.CommentingAndDocBlocks.php 17 0
test/fixable/9.GenericTypeHintSyntax.php 4 0
----------------------------------------------------------------------
A TOTAL OF 567 ERRORS AND 2 WARNINGS WERE FOUND IN 30 FILES
A TOTAL OF 568 ERRORS AND 2 WARNINGS WERE FOUND IN 31 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 487 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 484 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


4 changes: 2 additions & 2 deletions test/fixable/2.3.Lines.php
Expand Up @@ -60,13 +60,13 @@ public function testThereMayNotBeAnyBlankLineFfterOpeningBracesAndBeforeClosingB
// There MAY NOT be any blank line after opening braces and before
// closing braces.

$noBlankLine = function () use ($noBlankLine) {
$noBlankLine = function () use ($noBlankLine): void {

$noBlankLine = 1;

};

$closure = function () {
$closure = function (): void {

$noBlankLine = 1;

Expand Down
2 changes: 1 addition & 1 deletion test/fixable/2.7.Arrays.php
Expand Up @@ -27,7 +27,7 @@ public function testArrayFormatting(): void
];

$array2 = [
'one' => function () {
'one' => function (): void {
$foo = [1, 2, 3];
$barBar = [
1,
Expand Down
2 changes: 1 addition & 1 deletion test/fixable/4.1.ExtendsAndImplements.php
Expand Up @@ -16,7 +16,7 @@ class ExtendsAndImplements
ArrayAccess,
Countable,
Serializable {
public function testClassDeclaration()
public function testClassDeclaration(): void
{
// The extends and implements keywords MUST be declared on the same line
// as the class name.
Expand Down
4 changes: 2 additions & 2 deletions test/fixable/4.4.MethodsAndFunctions.php
Expand Up @@ -19,15 +19,15 @@ public function testMethodsAndFunctions ($arg1, &$arg2, $arg3 = []) {
// NOT be a space after the opening parenthesis, and there MUST NOT be a
// space before the closing parenthesis.

function fooBar ( $arg1, &$arg2, $arg3 = [] ) {
function fooBar ( $arg1, &$arg2, $arg3 = [] ): void {
// function body
}

}



public function testOneSingleLineBetweenMethods()
public function testOneSingleLineBetweenMethods(): void
{
// There MUST be a single empty line between methods in a class.
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixable/4.5.MethodAndFunctionArguments.php
Expand Up @@ -74,7 +74,7 @@ public function testVariadicThreeDotOperator(string $foo, & ... $baz): void
// When combining both the reference operator and the variadic three dot
// operator, there MUST NOT be any space between the two of them.

function method($a, $b, ... $c) {
function method($a, $b, ... $c): void {
if ($a < $b) {
method(... func_get_args());
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixable/6.Operators.php
Expand Up @@ -65,7 +65,7 @@ public function testOperatorSpacing(): void
$result*=4;
}

public function testObjectOperatorSpacing()
public function testObjectOperatorSpacing(): void
{
// There MAY NOT be any white space around the object operator unless
// multilines are used.
Expand Down
4 changes: 2 additions & 2 deletions test/fixable/7.Closures.php
Expand Up @@ -37,11 +37,11 @@ public function testClosures(): void
// MUST follow the use list closing parentheses with no spaces between
// the two characters.

$closureWithArgs = function ($arg1, $arg2) {
$closureWithArgs = function ($arg1, $arg2): void {
echo "$arg1, $arg2";
};

$closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2) {
$closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2): void {
echo "$arg1, $arg2, $var1, $var2";
};

Expand Down
36 changes: 36 additions & 0 deletions test/fixable/9.GenericTypeHintSyntax.php
@@ -0,0 +1,36 @@
<?php

/**
* @see https://github.com/laminas/laminas-coding-standard for the canonical source repository
* @copyright https://github.com/laminas/laminas-coding-standard/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-coding-standard/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);

use IteratorAggregate;

class GenericTypeHintSyntax
{
/** @psalm-var IteratorAggregate */
private $config;

/** @var IteratorAggregate<string,string> */
private $bar;

/**
* @param IteratorAggregate<string,string> $bar
*/
public function __construct(ArrayObject $bar)
{
$this->bar = $bar;
}

/**
* @param array<string, mixed> $config
*/
public function doSomethingWithArray(array $config): void
{
$this->config = $config;
}
}
4 changes: 2 additions & 2 deletions test/fixed/2.3.Lines.php
Expand Up @@ -50,11 +50,11 @@ public function testThereMayNotBeAnyBlankLineFfterOpeningBracesAndBeforeClosingB
// There MAY NOT be any blank line after opening braces and before
// closing braces.

$noBlankLine = function () use ($noBlankLine) {
$noBlankLine = function () use ($noBlankLine): void {
$noBlankLine = 1;
};

$closure = function () {
$closure = function (): void {
$noBlankLine = 1;
};

Expand Down
2 changes: 1 addition & 1 deletion test/fixed/2.7.Arrays.php
Expand Up @@ -27,7 +27,7 @@ public function testArrayFormatting(): void
];

$array2 = [
'one' => function () {
'one' => function (): void {
$foo = [1, 2, 3];
$barBar = [
1,
Expand Down
2 changes: 1 addition & 1 deletion test/fixed/4.1.ExtendsAndImplements.php
Expand Up @@ -14,7 +14,7 @@ class ExtendsAndImplements extends ParentClass implements
Countable,
Serializable
{
public function testClassDeclaration()
public function testClassDeclaration(): void
{
// The extends and implements keywords MUST be declared on the same line
// as the class name.
Expand Down
6 changes: 3 additions & 3 deletions test/fixed/4.4.MethodsAndFunctions.php
Expand Up @@ -6,7 +6,7 @@

class MethodsAndFunctions
{
public function testMethodsAndFunctions($arg1, &$arg2, $arg3 = [])
public function testMethodsAndFunctions($arg1, &$arg2, $arg3 = []): void
{
// Visibility MUST be declared on all methods.
//
Expand All @@ -20,13 +20,13 @@ public function testMethodsAndFunctions($arg1, &$arg2, $arg3 = [])
// NOT be a space after the opening parenthesis, and there MUST NOT be a
// space before the closing parenthesis.

function fooBar($arg1, &$arg2, $arg3 = [])
function fooBar($arg1, &$arg2, $arg3 = []): void
{
// function body
}
}

public function testOneSingleLineBetweenMethods()
public function testOneSingleLineBetweenMethods(): void
{
// There MUST be a single empty line between methods in a class.
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixed/4.5.MethodAndFunctionArguments.php
Expand Up @@ -74,7 +74,7 @@ public function testVariadicThreeDotOperator(string $foo, &...$baz): void
// When combining both the reference operator and the variadic three dot
// operator, there MUST NOT be any space between the two of them.

function method($a, $b, ...$c)
function method($a, $b, ...$c): void
{
if ($a < $b) {
method(...func_get_args());
Expand Down
2 changes: 1 addition & 1 deletion test/fixed/6.Operators.php
Expand Up @@ -65,7 +65,7 @@ public function testOperatorSpacing(): void
$result *= 4;
}

public function testObjectOperatorSpacing()
public function testObjectOperatorSpacing(): void
{
// There MAY NOT be any white space around the object operator unless
// multilines are used.
Expand Down
6 changes: 3 additions & 3 deletions test/fixed/7.Closures.php
Expand Up @@ -37,11 +37,11 @@ public function testClosures(): void
// MUST follow the use list closing parentheses with no spaces between
// the two characters.

$closureWithArgs = function ($arg1, $arg2) {
$closureWithArgs = function ($arg1, $arg2): void {
echo "$arg1, $arg2";
};

$closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2) {
$closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2): void {
echo "$arg1, $arg2, $var1, $var2";
};

Expand All @@ -65,7 +65,7 @@ public function testInheritedVariablesMustBeUsed(): void
// Inherited variables passed via `use` MUST be used in closures.

$message = 'world';
$example = function ($arg) use ($message) {
$example = function ($arg) use ($message): void {
echo "$arg $message";
};
$example('hello');
Expand Down
36 changes: 36 additions & 0 deletions test/fixed/9.GenericTypeHintSyntax.php
@@ -0,0 +1,36 @@
<?php

/**
* @see https://github.com/laminas/laminas-coding-standard for the canonical source repository
* @copyright https://github.com/laminas/laminas-coding-standard/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-coding-standard/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);

use IteratorAggregate;

class GenericTypeHintSyntax
{
/** @psalm-var IteratorAggregate */
private $config;

/** @var IteratorAggregate<string,string> */
private $bar;

/**
* @param IteratorAggregate<string,string> $bar
*/
public function __construct(ArrayObject $bar)
{
$this->bar = $bar;
}

/**
* @param array<string, mixed> $config
*/
public function doSomethingWithArray(array $config): void
{
$this->config = $config;
}
}