Skip to content

Commit

Permalink
Merge pull request #49 from object-calisthenics/code-sniffer-3
Browse files Browse the repository at this point in the history
Bump to Code Sniffer 3
  • Loading branch information
Tomáš Votruba committed Mar 10, 2017
2 parents 779fb7d + 24b6516 commit 1fc449a
Show file tree
Hide file tree
Showing 36 changed files with 178 additions and 181 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Do you **prefer slides**?
Via composer:

```sh
composer require object-calisthenics/phpcs-calisthenics-rules --dev
composer require object-calisthenics/phpcs-calisthenics-rules "squizlabs/php_codesniffer:3.0.0RC4" --dev
```

Then, enable it as part of your CodeSniffer ruleset (ie. `ruleset.xml` in root project directory):
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"license": "MIT",
"require": {
"php": "^7.1",
"squizlabs/php_codesniffer": "^2.8",
"squizlabs/php_codesniffer": "3.0.0RC4",
"nette/utils": "^2.4"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"friendsofphp/php-cs-fixer": "^2.1",
"phpstan/phpstan": "^0.6.4"
"phpstan/phpstan": "^0.6.4",
"tracy/tracy": "^2.4"
},
"autoload": {
"psr-4": {
Expand All @@ -19,7 +20,8 @@
},
"autoload-dev": {
"psr-4": {
"ObjectCalisthenics\\Tests\\": "tests"
"ObjectCalisthenics\\Tests\\": "tests",
"PHP_CodeSniffer\\": "vendor/squizlabs/php_codesniffer/src"
}
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions src/ObjectCalisthenics/AbstractDataStructureLengthSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ObjectCalisthenics;

use ObjectCalisthenics\Helper\Structure\StructureMetrics;
use PHP_CodeSniffer_File;
use PHP_CodeSniffer\Files\File;

/**
* Base for class, interface, trait, function and method length checks.
Expand All @@ -16,10 +16,10 @@ abstract class AbstractDataStructureLengthSniff
public $maxLength;

/**
* @param PHP_CodeSniffer_File $file
* @param int $position
* @param File $file
* @param int $position
*/
public function process(PHP_CodeSniffer_File $file, $position): void
public function process(File $file, $position): void
{
$tokenType = $file->getTokens()[$position]['content'];
$length = StructureMetrics::getStructureLengthInLines($file, $position);
Expand Down
10 changes: 5 additions & 5 deletions src/ObjectCalisthenics/Helper/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ObjectCalisthenics\Helper;

use ObjectCalisthenics\Helper\DocBlock\MemberComment;
use PHP_CodeSniffer_File;
use PHP_CodeSniffer\Files\File;

final class ClassAnalyzer
{
Expand All @@ -12,7 +12,7 @@ final class ClassAnalyzer
*/
private static $propertyList;

public static function getClassMethodCount(PHP_CodeSniffer_File $file, int $position): int
public static function getClassMethodCount(File $file, int $position): int
{
$methodCount = 0;
$pointer = $position;
Expand All @@ -26,12 +26,12 @@ public static function getClassMethodCount(PHP_CodeSniffer_File $file, int $posi
return $methodCount;
}

public static function getClassPropertiesCount(PHP_CodeSniffer_File $file, int $position): int
public static function getClassPropertiesCount(File $file, int $position): int
{
return count(self::getClassProperties($file, $position));
}

public static function getClassProperties(PHP_CodeSniffer_File $file, int $position): array
public static function getClassProperties(File $file, int $position): array
{
$tokens = $file->getTokens();
$token = $tokens[$position];
Expand All @@ -46,7 +46,7 @@ public static function getClassProperties(PHP_CodeSniffer_File $file, int $posit
return self::$propertyList;
}

private static function extractPropertyIfFound(PHP_CodeSniffer_File $file, int $position): void
private static function extractPropertyIfFound(File $file, int $position): void
{
$tokens = $file->getTokens();
$property = $tokens[$position];
Expand Down
4 changes: 2 additions & 2 deletions src/ObjectCalisthenics/Helper/DocBlock/MemberComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace ObjectCalisthenics\Helper\DocBlock;

use PHP_CodeSniffer_File;
use PHP_CodeSniffer\Files\File;

final class MemberComment
{
public static function getMemberComment(PHP_CodeSniffer_File $file, int $position): string
public static function getMemberComment(File $file, int $position): string
{
$docCommentPosition = $file->findPrevious(T_DOC_COMMENT_STRING, $position, $position - 10);
if (!$docCommentPosition) {
Expand Down
4 changes: 2 additions & 2 deletions src/ObjectCalisthenics/Helper/Naming.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace ObjectCalisthenics\Helper;

use Nette\Utils\Strings;
use PHP_CodeSniffer_File;
use PHP_CodeSniffer\Files\File;

final class Naming
{
public static function getElementName(PHP_CodeSniffer_File $file, int $position): string
public static function getElementName(File $file, int $position): string
{
$name = $file->getTokens()[$position]['content'];

Expand Down
4 changes: 2 additions & 2 deletions src/ObjectCalisthenics/Helper/Structure/StructureMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace ObjectCalisthenics\Helper\Structure;

use PHP_CodeSniffer_File;
use PHP_CodeSniffer\Files\File;

final class StructureMetrics
{
public static function getStructureLengthInLines(PHP_CodeSniffer_File $file, int $position): int
public static function getStructureLengthInLines(File $file, int $position): int
{
$tokens = $file->getTokens();
$token = $tokens[$position];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace ObjectCalisthenics\Sniffs\Classes;

use Nette\Utils\Strings;
use PHP_CodeSniffer_File;
use PHP_CodeSniffer_Sniff;
use PHP_CodeSniffer_Standards_AbstractVariableSniff;
use PHP_CodeSniffer_Tokens;
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;

final class ForbiddenPublicPropertySniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff implements PHP_CodeSniffer_Sniff
final class ForbiddenPublicPropertySniff extends AbstractVariableSniff implements Sniff
{
/**
* @var string[]
Expand All @@ -21,7 +21,7 @@ final class ForbiddenPublicPropertySniff extends PHP_CodeSniffer_Standards_Abstr
private $tokens;

/**
* @var PHP_CodeSniffer_File
* @var File
*/
private $file;

Expand All @@ -31,10 +31,10 @@ final class ForbiddenPublicPropertySniff extends PHP_CodeSniffer_Standards_Abstr
private $position;

/**
* @param PHP_CodeSniffer_File $file
* @param int $position
* @param File $file
* @param int $position
*/
protected function processMemberVar(PHP_CodeSniffer_File $file, $position): void
protected function processMemberVar(File $file, $position): void
{
if ($this->isFileSkipped($file->getFilename())) {
return;
Expand All @@ -46,7 +46,7 @@ protected function processMemberVar(PHP_CodeSniffer_File $file, $position): void

$this->handleMultiPropertyDeclaration();

$modifier = $file->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, ($position - 1));
$modifier = $file->findPrevious(Tokens::$scopeModifiers, ($position - 1));

// Check for no visibility declaration

Expand All @@ -55,19 +55,19 @@ protected function processMemberVar(PHP_CodeSniffer_File $file, $position): void
}

/**
* @param PHP_CodeSniffer_File $file
* @param int $position
* @param File $file
* @param int $position
*/
protected function processVariable(PHP_CodeSniffer_File $file, $position): void
protected function processVariable(File $file, $position): void
{
// We don't care about normal variables.
}

/**
* @param PHP_CodeSniffer_File $file
* @param int $position
* @param File $file
* @param int $position
*/
protected function processVariableInString(PHP_CodeSniffer_File $file, $position): void
protected function processVariableInString(File $file, $position): void
{
// We don't care about normal variables.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use ObjectCalisthenics\Helper\ClassAnalyzer;
use ObjectCalisthenics\Helper\PropertyFilter;
use PHP_CodeSniffer_File;
use PHP_CodeSniffer_Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

final class InstancePropertyPerClassLimitSniff implements PHP_CodeSniffer_Sniff
final class InstancePropertyPerClassLimitSniff implements Sniff
{
/**
* @var int
Expand All @@ -23,10 +23,10 @@ public function register(): array
}

/**
* @param PHP_CodeSniffer_File $file
* @param int $position
* @param File $file
* @param int $position
*/
public function process(PHP_CodeSniffer_File $file, $position): void
public function process(File $file, $position): void
{
$properties = ClassAnalyzer::getClassProperties($file, $position);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace ObjectCalisthenics\Sniffs\CodeAnalysis;

use PHP_CodeSniffer_File;
use PHP_CodeSniffer_Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

final class OneObjectOperatorPerLineSniff implements PHP_CodeSniffer_Sniff
final class OneObjectOperatorPerLineSniff implements Sniff
{
/**
* @var PHP_CodeSniffer_File
* @var File
*/
private $file;

Expand All @@ -31,10 +31,10 @@ public function register(): array
}

/**
* @param PHP_CodeSniffer_File $file
* @param int $position
* @param File $file
* @param int $position
*/
public function process(PHP_CodeSniffer_File $file, $position): void
public function process(File $file, $position): void
{
$this->file = $file;
$this->position = $position;
Expand Down Expand Up @@ -67,7 +67,7 @@ private function ignoreWhitespace(array $tokens, int $start): int
private function handleTwoObjectOperators(bool $isOwnCall): void
{
if ($this->callerTokens && !$isOwnCall) {
$this->file->addError('Only one object operator per line.', $this->position);
$this->file->addError('Only one object operator per line.', $this->position, self::class);

throw new \Exception();
}
Expand All @@ -88,7 +88,7 @@ private function handleExcludedFluentInterfaces(array $tmpToken, string $tmpToke
($memberTokenType === 'method' && $tmpTokenType === 'property') ||
($memberTokenType === 'method' && $tmpTokenType === 'method' && $memberTokenCount > 1 && $memberToken['token']['content'] !== $tmpToken['content'])
) {
$this->file->addError('Only one object operator per line.', $this->position);
$this->file->addError('Only one object operator per line.', $this->position, self::class);

throw new \Exception();
}
Expand Down
12 changes: 6 additions & 6 deletions src/ObjectCalisthenics/Sniffs/ControlStructures/NoElseSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ObjectCalisthenics\Sniffs\ControlStructures;

use PHP_CodeSniffer_File;
use PHP_CodeSniffer_Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

final class NoElseSniff implements PHP_CodeSniffer_Sniff
final class NoElseSniff implements Sniff
{
/**
* @return int[]
Expand All @@ -16,10 +16,10 @@ public function register(): array
}

/**
* @param PHP_CodeSniffer_File $file
* @param int $position
* @param File $file
* @param int $position
*/
public function process(PHP_CodeSniffer_File $file, $position): void
public function process(File $file, $position): void
{
$file->addError('Do not use "else" or "elseif" tokens', $position, self::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace ObjectCalisthenics\Sniffs\Files;

use ObjectCalisthenics\AbstractDataStructureLengthSniff;
use PHP_CodeSniffer_Sniff;
use PHP_CodeSniffer\Sniffs\Sniff;

final class ClassElementLengthSniff extends AbstractDataStructureLengthSniff implements PHP_CodeSniffer_Sniff
final class ClassElementLengthSniff extends AbstractDataStructureLengthSniff implements Sniff
{
/**
* @var int
Expand Down
4 changes: 2 additions & 2 deletions src/ObjectCalisthenics/Sniffs/Files/FunctionLengthSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace ObjectCalisthenics\Sniffs\Files;

use ObjectCalisthenics\AbstractDataStructureLengthSniff;
use PHP_CodeSniffer_Sniff;
use PHP_CodeSniffer\Sniffs\Sniff;

final class FunctionLengthSniff extends AbstractDataStructureLengthSniff implements PHP_CodeSniffer_Sniff
final class FunctionLengthSniff extends AbstractDataStructureLengthSniff implements Sniff
{
/**
* @var int
Expand Down
14 changes: 7 additions & 7 deletions src/ObjectCalisthenics/Sniffs/Metrics/MaxNestingLevelSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace ObjectCalisthenics\Sniffs\Metrics;

use PHP_CodeSniffer_File;
use PHP_CodeSniffer_Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

final class MaxNestingLevelSniff implements PHP_CodeSniffer_Sniff
final class MaxNestingLevelSniff implements Sniff
{
/**
* @var int
*/
public $maxNestingLevel = 2;

/**
* @var PHP_CodeSniffer_File
* @var File
*/
private $file;

Expand Down Expand Up @@ -43,10 +43,10 @@ public function register(): array
}

/**
* @param PHP_CodeSniffer_File $file
* @param int $position
* @param File $file
* @param int $position
*/
public function process(PHP_CodeSniffer_File $file, $position): void
public function process(File $file, $position): void
{
$this->file = $file;
$this->position = $position;
Expand Down

0 comments on commit 1fc449a

Please sign in to comment.