-
Notifications
You must be signed in to change notification settings - Fork 12
Custom Sniffs
- Abstract class must be prefixed with Abstract
- Class and Namespace must be in PascalCase
- Interface must be postfixed with Interface
- No vertical whitespace between use statements
- Only one use statement per line
- Protected properties are not allowed
- Trait must be postfixed with Trait
- Use statements alphabetically ordered
- Variable and property must be in snake case
- @covers fully qualified name
- @covers counter part
- File comment copyright
- Declares strict
- Return type declaration
- Method name starts with 'getis'
- PHPUnit Namespace
- Related class:
Hostnet\Sniffs\Classes\AbstractClassMustBePrefixedWithAbstractSniff - Name of the sniff:
Hostnet.Classes.AbstractClassMustBePrefixedWithAbstract
Incorrect example β
abstract class MyClass
{
public abstract function getEntityManager();
}Correct example π
abstract class AbstractMyClass
{
public abstract function getEntityManager();
}- Related class:
Hostnet\Sniffs\Classes\ClassAndNamespaceMustBeInPascalCaseSniff - Name of the sniff:
Hostnet.Classes.ClassAndNamespaceMustBeInPascalCase
Incorrect example β
namespace This\IS\a\BAD\namespaceE;
class MyClassIs09LookingFaULty
{
}Correct example π
namespace This\Is\A\Good\NameSpaceE;
class MyClassIsLookingGood
{
}- Related class:
Hostnet\Sniffs\Classes\InterfaceMustBePostfixedWithInterfaceSniff - Name of the sniff:
Hostnet.Classes.InterfaceMustBePostfixedWithInterface
Incorrect example β
interface MyClass
{
}Correct example π
interface MyClassInterface
{
}- Related class:
Hostnet\Sniffs\Classes\NoVerticalWhitespaceBetweenUseStatementsSniff - Name of the sniff:
Hostnet.Classes.NoVerticalWhitespaceBetweenUseStatements
Incorrect example β
use SomeSpace; // comment
use MoreSpace;
use LostIn\Space;Correct example π
use SomeSpace; // comment
use MoreSpace;
use LostIn\Space;- Related class:
Hostnet\Sniffs\Classes\OnlyOneUseStatementPerLineSniff - Name of the sniff:
Hostnet.Classes.OnlyOneUseStatementPerLine
Incorrect example β
use SomeOtherSpace as Hello, ThisShouldNotBeHere;Correct example π
use SomeOtherSpace as Hello;- Related class:
Hostnet\Sniffs\Classes\ProtectedPropertiesAreNotAllowedSniff - Name of the sniff:
Hostnet.Classes.ProtectedPropertiesAreNotAllowed
Incorrect example β
private $bar;
protected $foo;
public $public_variable;Correct example π
private $bar;
public $public_variable;- Related class:
Hostnet\Sniffs\Classes\TraitMustBePostfixedWithTraitSniff - Name of the sniff:
Hostnet.Classes.TraitMustBePostfixedWithTrait
Incorrect example β
trait MyClass
{
}Correct example π
trait MyClassTrait
{
}- Related class:
Hostnet\Sniffs\Classes\UseStatementsAlphabeticallyOrderedSniff - Name of the sniff:
Hostnet.Classes.UseStatementsAlphabeticallyOrdered
Incorrect example β
use A;
use C;
use B;Correct example π
use A;
use B;
use C;- Related class:
Hostnet\Sniffs\Classes\VariableAndPropertyMustBeInSnakeCaseSniff - Name of the sniff:
Hostnet.Classes.VariableAndPropertyMustBeInSnakeCase
Incorrect example β
private $badProperty;Correct example π
private $good_property;- Related class:
Hostnet\Sniffs\Commenting\AtCoversFullyQualifiedNameSniff - Name of the sniff:
Hostnet.Commenting.AtCoversFullyQualifiedName
Incorrect example β
/**
* @covers Hostnet\Test\TestUnit\Bad
*/Correct example π
/**
* @covers \Hostnet\Test\TestUnit\Good
*/- Related class:
Hostnet\Sniffs\Commenting\AtCoversCounterPartSniff - Name of the sniff:
Hostnet.Commenting.AtCoversCounterPart
Incorrect example β
namespace Foo;
class Bar
{
}namespace Foo;
class BarTest
{
}Correct example π
namespace Foo;
class Bar
{
}namespace Foo;
/**
* @covers \Foo\Bar
*/
class BarTest
{
}- Related class:
Hostnet\Sniffs\Commenting\FileCommentCopyrightSniff - Name of the sniff:
Hostnet.Commenting.FileCommentCopyright - Parameters:
-
years: Which years should be noted for the copyright, if not configured the _years is 'calculated' -
copyright_holder: The legal holder of the copyright. -
copyright_tag: The 'name' of the tag to search for. phpDocumenter uses @copyright.
-
Incorrect example β
<?php
/**
* Test1234
*/
class abc {
}Correct example π
/**
* @copyright 2017 Hostnet B.V.
*/
/**
* Test1234
*/
class abc {
}- Related class:
Hostnet\Sniffs\Declares\StrictSniff - Name of the sniff:
Hostnet.Declares.Strict
Incorrect example β
<?php
echo 'hi there';
?>Correct example π
<?php
declare(strict_types=1);- Related class:
Hostnet\Sniffs\Functions\ReturnTypeDeclarationSniff - Name of the sniff:
Hostnet.Functions.ReturnTypeDeclaration - Parameters:
-
closing_parenthesis_colon_spacing: spacing between the function's closing parenthesis and colon. -
colon_return_type_spacing: spacing between the colon and the return type.
-
Incorrect example β
public function this() : string
{
return;
}Correct example π
public function this(): string
{
return;
}- Related class:
Hostnet\Sniffs\NamingConventions\MethodNameStartsWithGetIsSniff - Name of the sniff:
Hostnet.NamingConventions.MethodNameStartsWithGetIs
Incorrect example β
protected function getIsStuff()
{
}Correct example π
protected function isStuff()
{
}This test was added during the transition between PHPUnit 6 and 7 to ensure that the right TestCase-file is being used.
- Related class:
Hostnet\Sniffs\PhpUnit\NamespaceSniff - Name of the sniff:
Hostnet.PhpUnit.Namespace
Incorrect example β
class NamespaceTest extends PHPUnit_Framework_TestCaseCorrect example π
class NamespaceTest extends TestCase