Commit e51fef64 authored by Jan Kuchař's avatar Jan Kuchař

Merge branch 'implement-strict-phpstan-rules' into 'master'

phpstan: improved strictness of project coding standard

See merge request !7
parents fb4e98b8 de3989a3
Pipeline #14342 passed with stages
in 34 seconds
......@@ -15,7 +15,7 @@
"@phpstan",
"@test"
],
"phpstan": "vendor/bin/phpstan analyze -l 7 src tests --no-interaction --ansi --no-progress",
"phpstan": "vendor/bin/phpstan analyze -l 7 -c phpstan.neon --error-format compact --no-interaction --ansi --no-progress -- src",
"test": "vendor/bin/tester tests --colors 1"
},
......@@ -33,7 +33,9 @@
"require-dev": {
"nette/tester": "^2.1.0",
"phpstan/phpstan": "^0.10.7"
"phpstan/phpstan": "^0.10.7",
"phpstan/phpstan-strict-rules": "^0.10.1",
"grifart/phpstan-oneline": "^0.2.0"
},
"autoload-dev": {
"files": [
......
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/grifart/phpstan-oneline/config.neon
@echo off
vendor\bin\phpstan analyze src tests --level 7
\ No newline at end of file
......@@ -52,7 +52,7 @@ abstract class Enum
*/
public static function __callStatic(string $constantName, array $arguments): Enum
{
\assert(empty($arguments));
\assert(\count($arguments) === 0);
$value = self::getMeta()->getValueForConstantName($constantName);
if($value === NULL) {
......
......@@ -28,7 +28,7 @@ final class ConsistencyChecker
}
}
if (!empty($missingAnnotations)) {
if (\count($missingAnnotations) !== 0) {
$properDoc = "/**\n * " . implode("\n * ", $missingAnnotations) . "\n */\n";
throw new \LogicException("You have forgotten to add @method annotations for enum '{$enumReflection->getName()}'. Documentation block should contain: \n$properDoc");
}
......
......@@ -49,6 +49,7 @@ final class Meta
}
/**
* @param string $constantName
* @throws MissingValueDeclarationException
*/
public function getValueForConstantName($constantName): ?Enum
......@@ -60,11 +61,17 @@ final class Meta
return $this->getValueForScalar($scalar);
}
/**
* @param string|int $scalarValue
*/
public function hasValueForScalar($scalarValue): bool
{
return isset($this->scalarToValue[$scalarValue]);
}
/**
* @param string|int $scalarValue
*/
public function getConstantNameForScalar($scalarValue): string
{
$result = \array_search($scalarValue, $this->constantToScalar, true);
......@@ -74,6 +81,9 @@ final class Meta
return $result;
}
/**
* @return int|string
*/
public function getScalarForValue(Enum $enum)
{
$result = \array_search($enum, $this->scalarToValue, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment