Skip to content

Commit

Permalink
Merge pull request #77 from object-calisthenics/symplify-4
Browse files Browse the repository at this point in the history
bump to Symplify 4
  • Loading branch information
Tomáš Votruba committed Apr 4, 2018
2 parents 8df8d8c + 4963fbf commit 46d2acb
Show file tree
Hide file tree
Showing 38 changed files with 411 additions and 321 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -76,7 +76,7 @@ private function ensureIsAllInstanceOf(array $objects, string $type)
#### :wrench: Configurable

- [in CodeSniffer XML](/src/ObjectCalisthenics/ruleset.xml#L3-L8)
- [in EasyCodingStandard NEON](/easy-coding-standard.neon#L4-L6)
- [in EasyCodingStandard NEON](/easy-coding-standard.yml#L4-L6)

---

Expand Down Expand Up @@ -135,7 +135,7 @@ $containerBuilder->addDefinition(SniffRunner::class);
#### :wrench: Configurable

- [in CodeSniffer XML](/src/ObjectCalisthenics/ruleset.xml#L13-L20)
- [in EasyCodingStandard NEON](/easy-coding-standard.neon#L11-L15)
- [in EasyCodingStandard NEON](/easy-coding-standard.yml#L11-L15)

---

Expand Down Expand Up @@ -170,7 +170,7 @@ class EntityMailer
#### :wrench: Configurable

- [in CodeSniffer XML](/src/ObjectCalisthenics/ruleset.xml#L22-L28)
- [in EasyCodingStandard NEON](/easy-coding-standard.neon#L17-L20)
- [in EasyCodingStandard NEON](/easy-coding-standard.yml#L17-L20)

---

Expand Down Expand Up @@ -264,7 +264,7 @@ class SomeClass
#### :wrench: Configurable

- [in CodeSniffer XML](/src/ObjectCalisthenics/ruleset.xml#L30-L50)
- [in EasyCodingStandard NEON](/easy-coding-standard.neon#L22-L30)
- [in EasyCodingStandard NEON](/easy-coding-standard.yml#L22-L30)

---

Expand Down
13 changes: 6 additions & 7 deletions composer.json
Expand Up @@ -5,16 +5,15 @@
"type": "phpcodesniffer-standard",
"require": {
"php": "^7.1",
"squizlabs/php_codesniffer": "^3.1",
"squizlabs/php_codesniffer": "^3.2",
"nette/utils": "^2.4"
},
"require-dev": {
"phpunit/phpunit": "^6.4",
"phpstan/phpstan": "^0.8",
"tracy/tracy": "^2.4",
"symplify/easy-coding-standard": "^2.5",
"symplify/coding-standard": "^2.5",
"slevomat/coding-standard": "^4.0"
"phpunit/phpunit": "^7.0",
"phpstan/phpstan": "^0.9",
"symplify/easy-coding-standard-tester": "^4.0",
"symplify/coding-standard": "^4.0",
"slevomat/coding-standard": "^4.5"
},
"autoload": {
"psr-4": {
Expand Down
109 changes: 0 additions & 109 deletions easy-coding-standard.neon

This file was deleted.

76 changes: 76 additions & 0 deletions easy-coding-standard.yml
@@ -0,0 +1,76 @@
imports:
- { resource: 'vendor/symplify/easy-coding-standard/config/symfony.yml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/php70.yml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/php71.yml' }
# custom
- { resource: 'vendor/symplify/easy-coding-standard/config/common.yml' }
- { resource: 'vendor/symplify/easy-coding-standard/config/symplify.yml' }

services:
# All rules with default values

# Rule 1: Only X indentation level per function/method (with default values)
ObjectCalisthenics\Sniffs\Metrics\MaxNestingLevelSniff:
maxNestingLevel: 2

# Rule 2: There is no "else"
ObjectCalisthenics\Sniffs\ControlStructures\NoElseSniff: ~

# Rule 5: Only one object operator (->) per line (with default values)
ObjectCalisthenics\Sniffs\CodeAnalysis\OneObjectOperatorPerLineSniff:
variablesHoldingAFluentInterface: ["$queryBuilder", "$containerBuilder"]
methodsStartingAFluentInterface: ["createQueryBuilder"]
methodsEndingAFluentInterface: ["execute", "getQuery"]

# Rule 6: Do not abbreviate (with default values)
ObjectCalisthenics\Sniffs\NamingConventions\ElementNameMinimalLengthSniff:
minLength: 3
allowedShortNames: ["i", "id", "to", "up"]

# Rule 7: Keep your classes small (with default values)
ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff:
maxLength: 200
ObjectCalisthenics\Sniffs\Files\FunctionLengthSniff:
maxLength: 20
ObjectCalisthenics\Sniffs\Metrics\PropertyPerClassLimitSniff:
maxCount: 10
ObjectCalisthenics\Sniffs\Metrics\MethodPerClassLimitSniff:
maxCount: 10

# Rule 9: Do not Use Getters and Setters
ObjectCalisthenics\Sniffs\Classes\ForbiddenPublicPropertySniff: ~
ObjectCalisthenics\Sniffs\NamingConventions\NoSetterSniff: ~

PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer:
equal: false
identical: false
less_and_greater: false

# Metrics
PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\CyclomaticComplexitySniff:
absoluteComplexity: 4
PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\NestingLevelSniff:
absoluteNestingLevel: 2

# Slevomat
SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff: ~
SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff: ~
SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff:
enableEachParameterAndReturnInspection: true

parameters:
skip:
SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff:
- '*src/ObjectCalisthenics/Sniffs/*/*Sniff.php'

PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff.Found: ~

exclude_checkers:
- 'Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenStaticFunctionSniff'
# Symfony ruleset
- 'PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer'
- 'PhpCsFixer\Fixer\Operator\NewWithBracesFixer'
- 'PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer'
# mutually excluded
- 'SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff'
- 'PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer'
3 changes: 1 addition & 2 deletions phpstan.neon
@@ -1,7 +1,6 @@
parameters:
autoload_files:
- %currentWorkingDirectory%/tests/bootstrap.php
- %currentWorkingDirectory%/vendor/squizlabs/php_codesniffer/autoload.php
excludes_analyse:
- **/ObjectCalisthenics/Helper/Slevomat/**
ignoreErrors:
- '#Method ObjectCalisthenics\\Sniffs\\Metrics\\MaxNestingLevelSniff::register\(\) should return int\[\] but returns \(int\|string\)\[\]#'
5 changes: 1 addition & 4 deletions src/ObjectCalisthenics/Helper/ClassAnalyzer.php
Expand Up @@ -64,10 +64,7 @@ private static function ensureIsClassTraitOrInterface(File $file, int $position)

if (! in_array($token['code'], [T_CLASS, T_INTERFACE, T_TRAIT], true)) {
throw new NonClassTypeTokenTypeException(
sprintf(
'Must be class, interface or trait. "%s" given.',
ltrim($token['type'], 'T_')
)
sprintf('Must be class, interface or trait. "%s" given.', ltrim($token['type'], 'T_'))
);
}
}
Expand Down
Expand Up @@ -24,7 +24,6 @@ public function register(): array
}

/**
* @param File $file
* @param int $position
*/
public function process(File $file, $position): void
Expand Down
Expand Up @@ -68,7 +68,6 @@ public function register(): array
}

/**
* @param File $file
* @param int $position
*/
public function process(File $file, $position): void
Expand Down Expand Up @@ -134,7 +133,7 @@ private function isInFluentInterfaceMode(): bool
$lastEndPoint = $this->computeLastCallOfAnyFrom($this->methodsEndingAFluentInterface);
$lastStartPoint = $this->computeLastCallOfAnyFrom($this->methodsStartingAFluentInterface);

if (in_array($this->variableName, $this->variablesHoldingAFluentInterface)) {
if (in_array($this->variableName, $this->variablesHoldingAFluentInterface, true)) {
$lastStartPoint = max($lastStartPoint, -1);
}

Expand All @@ -151,10 +150,10 @@ private function isInFluentInterfaceMode(): bool
private function computeLastCallOfAnyFrom(array $methods): int
{
$calls = array_filter($this->callerTokens, function (array $token) use ($methods) {
return in_array($token['token']['content'], $methods);
return in_array($token['token']['content'], $methods, true);
});
if (count($calls) > 0) {
return array_search(end($calls), $this->callerTokens);
return array_search(end($calls), $this->callerTokens, true);
}

return -2;
Expand Down
Expand Up @@ -21,7 +21,6 @@ public function register(): array
}

/**
* @param File $file
* @param int $position
*/
public function process(File $file, $position): void
Expand Down
Expand Up @@ -27,7 +27,6 @@ public function register(): array
}

/**
* @param File $file
* @param int $position
*/
public function process(File $file, $position): void
Expand Down
Expand Up @@ -27,7 +27,6 @@ public function register(): array
}

/**
* @param File $file
* @param int $position
*/
public function process(File $file, $position): void
Expand Down
14 changes: 4 additions & 10 deletions src/ObjectCalisthenics/Sniffs/Metrics/MaxNestingLevelSniff.php
Expand Up @@ -43,16 +43,15 @@ final class MaxNestingLevelSniff implements Sniff
private $currentPtr;

/**
* @return int[]
* @return int[]|string[]
*/
public function register(): array
{
return [T_FUNCTION, T_CLOSURE];
}

/**
* @param File $file
* @param int $position
* @param int $position
*/
public function process(File $file, $position): void
{
Expand Down Expand Up @@ -80,12 +79,7 @@ private function handleNestingLevel(int $nestingLevel): void
if ($nestingLevel > $this->maxNestingLevel) {
$levelPluralization = $this->maxNestingLevel > 1 ? 's' : '';

$error = sprintf(
self::ERROR_MESSAGE,
$this->maxNestingLevel,
$levelPluralization,
$nestingLevel
);
$error = sprintf(self::ERROR_MESSAGE, $this->maxNestingLevel, $levelPluralization, $nestingLevel);

$this->file->addError($error, $this->position, self::class);
}
Expand Down Expand Up @@ -151,7 +145,7 @@ private function handleClosureToken(array $nestedToken): void
*/
private function handleCaseToken(array $nestedToken): void
{
if (in_array($nestedToken['code'], [T_CASE, T_DEFAULT])) {
if (in_array($nestedToken['code'], [T_CASE, T_DEFAULT], true)) {
array_push($this->ignoredScopeStack, $nestedToken);

return;
Expand Down
Expand Up @@ -28,21 +28,15 @@ public function register(): array
}

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

if ($methodCount > $this->maxCount) {
$typeName = Naming::getTypeName($file, $position);
$message = sprintf(
self::ERROR_MESSAGE,
$typeName,
$methodCount,
$this->maxCount
);
$message = sprintf(self::ERROR_MESSAGE, $typeName, $methodCount, $this->maxCount);

$file->addError($message, $position, self::class);
}
Expand Down

0 comments on commit 46d2acb

Please sign in to comment.