Skip to content

Commit c0dfa8f

Browse files
authored
Merge pull request #90 from sasezaki/php74cs
Update codebase to PHP 7.4
2 parents 5757088 + 7b3afce commit c0dfa8f

20 files changed

Lines changed: 86 additions & 99 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"struggle-for-php/sfp-stubs-psr-log": "^1.0.1 || ^2 || ^3.0.1"
1414
},
1515
"require-dev": {
16-
"laminas/laminas-coding-standard": "^2.5.0",
16+
"laminas/laminas-coding-standard": "^3",
1717
"maglnet/composer-require-checker": "^3 || ^4.15",
1818
"phpstan/phpstan-phpunit": "^2.0.7",
1919
"phpstan/phpstan-strict-rules": "^2.0.7",

example/src/Example.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace src;
66

77
use Psr\Log\LoggerInterface;
8+
use Throwable;
89

910
use function sprintf;
1011

@@ -19,8 +20,7 @@ public function __construct(LoggerInterface $logger)
1920
}
2021

2122
public function exceptionKeyOnlyAllowThrowable(
22-
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
23-
\Throwable $throwable
23+
Throwable $throwable
2424
): void {
2525
// invalid
2626
$this->logger->notice('foo', ['exception' => $throwable->getMessage()]);
@@ -31,8 +31,7 @@ public function exceptionKeyOnlyAllowThrowable(
3131
}
3232

3333
public function mustIncludesCurrentScopeThrowableIntoContext(
34-
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
35-
\Throwable $throwable
34+
Throwable $throwable
3635
): void {
3736
// Parameter $context of logger method Psr\Log\LoggerInterface::info() requires 'exception' key. Current scope has Throwable variable - $throwable
3837
$this->logger->notice('foo');
@@ -41,8 +40,7 @@ public function mustIncludesCurrentScopeThrowableIntoContext(
4140
}
4241

4342
public function reportContextExceptionLogLevel(
44-
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
45-
\Throwable $throwable
43+
Throwable $throwable
4644
): void {
4745
// phpstan.enableContextTypeRule.neon sfpPsrLog.reportContextExceptionLogLevel is 'notice'
4846
// so bellow would not report.

phpcs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<arg value="p"/>
1414

1515
<!-- Paths to check -->
16+
<file>example/src</file>
1617
<file>src</file>
1718
<file>test</file>
1819

@@ -22,8 +23,11 @@
2223
<!-- Include all rules from Laminas Coding Standard -->
2324
<rule ref="LaminasCodingStandard">
2425
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations" />
26+
<exclude name="Squiz.WhiteSpace.LanguageConstructSpacing" />
2527
</rule>
2628

29+
<rule ref="Generic.WhiteSpace.LanguageConstructSpacing" />
30+
2731
<rule ref="PSR12">
2832
<exclude name="Generic.Files.LineLength"/>
2933
<exclude name="WebimpressCodingStandard.Formatting.StringClassReference" />

src/Rules/ContextKeyRule.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use Override;
99
use PhpParser\Node;
1010
use PHPStan\Analyser\Scope;
11+
use PHPStan\Rules\IdentifierRuleError;
1112
use PHPStan\Rules\Rule;
1213
use PHPStan\Rules\RuleErrorBuilder;
1314
use PHPStan\ShouldNotHappenException;
15+
use PHPStan\Type\Constant\ConstantArrayType;
1416
use PHPStan\Type\ObjectType;
1517

1618
use function count;
@@ -29,8 +31,7 @@ final class ContextKeyRule implements Rule
2931

3032
private const ERROR_NOT_MATCH_ORIGINAL_PATTERN = 'Parameter $context of logger method Psr\Log\LoggerInterface::%s(), key should be match %s.';
3133

32-
/** @var string|null */
33-
private $contextKeyOriginalPattern;
34+
private ?string $contextKeyOriginalPattern;
3435

3536
public function __construct(?string $contextKeyOriginalPattern = null)
3637
{
@@ -109,10 +110,8 @@ public function processNode(Node $node, Scope $scope): array
109110
}
110111

111112
/**
112-
* phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
113-
* @phpstan-param list<\PHPStan\Type\Constant\ConstantArrayType> $constantArrays
114-
* phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
115-
* @phpstan-return list<\PHPStan\Rules\IdentifierRuleError>
113+
* @phpstan-param list<ConstantArrayType> $constantArrays
114+
* @phpstan-return list<IdentifierRuleError>
116115
*/
117116
private static function keysAreNonEmptyString(array $constantArrays, string $methodName): array
118117
{
@@ -133,10 +132,8 @@ private static function keysAreNonEmptyString(array $constantArrays, string $met
133132
}
134133

135134
/**
136-
* phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
137-
* @phpstan-param list<\PHPStan\Type\Constant\ConstantArrayType> $constantArrays
138-
* phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
139-
* @phpstan-return list<\PHPStan\Rules\IdentifierRuleError>
135+
* @phpstan-param list<ConstantArrayType> $constantArrays
136+
* @phpstan-return list<IdentifierRuleError>
140137
*/
141138
private function originalPatternMatches(array $constantArrays, string $methodName): array
142139
{

src/Rules/ContextRequireExceptionKeyRule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ final class ContextRequireExceptionKeyRule implements Rule
3636

3737
private const ERROR_MISSED_EXCEPTION_KEY = 'Parameter $context of logger method Psr\Log\LoggerInterface::%s() requires \'exception\' key. Current scope has Throwable variable - %s';
3838

39-
/** @var string */
40-
private $reportContextExceptionLogLevel;
39+
/** @var value-of<LogLevelListInterface::LOGGER_LEVEL_METHODS> */
40+
private string $reportContextExceptionLogLevel;
4141

42+
/** @param value-of<LogLevelListInterface::LOGGER_LEVEL_METHODS> $reportContextExceptionLogLevel */
4243
public function __construct(string $reportContextExceptionLogLevel = 'debug')
4344
{
4445
$this->reportContextExceptionLogLevel = $reportContextExceptionLogLevel;

src/Rules/ContextTypeRule.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
*/
2626
final class ContextTypeRule implements Rule
2727
{
28-
/** @var RuleLevelHelper */
29-
private $ruleLevelHelper;
28+
private RuleLevelHelper $ruleLevelHelper;
3029

31-
/** @var ContextTypeProviderResolverInterface */
32-
private $contextTypeProviderResolver;
30+
private ContextTypeProviderResolverInterface $contextTypeProviderResolver;
3331

3432
public function __construct(
3533
RuleLevelHelper $ruleLevelHelper,

src/Rules/LogMethodLevelRule.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ final class LogMethodLevelRule implements Rule
2727
Parameter #1 $level of method Psr\Log\LoggerInterface::log() expects %s, %s given.
2828
MESSAGE;
2929

30-
/** @var RuleLevelHelper */
31-
private $ruleLevelHelper;
30+
private RuleLevelHelper $ruleLevelHelper;
3231

33-
/** @var UnionType */
34-
private $acceptingLogLevel;
32+
private UnionType $acceptingLogLevel;
3533

3634
public function __construct(RuleLevelHelper $ruleLevelHelper)
3735
{

src/TypeProvider/BigQueryContextTypeProvider.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
*/
2626
final class BigQueryContextTypeProvider implements ContextTypeProviderInterface
2727
{
28-
/** @var string */
29-
private $schemaFile;
28+
private string $schemaFile;
3029

31-
/** @var TableFieldSchemaJsonPayloadTypeMapperInterface */
32-
private $tableFieldSchemaJsonPayloadTypeMapper;
30+
private TableFieldSchemaJsonPayloadTypeMapperInterface $tableFieldSchemaJsonPayloadTypeMapper;
3331

3432
/** @phpstan-var ?list<schema_item> */
35-
private $jsonPayloadFields;
33+
private ?array $jsonPayloadFields = null;
3634

3735
public function __construct(
3836
string $schemaFile,
@@ -96,7 +94,6 @@ private function getJsonPayloadFields(): array
9694
throw new Exception('schemaFile must have jsonPayload field');
9795
}
9896

99-
// phpcs:ignore
10097
/**
10198
* @todo validate list<schema_item>
10299
* @phpstan-var list<schema_item> $jsonPayloadFields

src/TypeProvider/Psr3ContextTypeProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414
final class Psr3ContextTypeProvider implements ContextTypeProviderInterface
1515
{
16-
/** @var string */
17-
private $exceptionClass;
16+
/** @var class-string */
17+
private string $exceptionClass;
1818

19+
/** @param class-string $exceptionClass */
1920
public function __construct(string $exceptionClass = Throwable::class)
2021
{
2122
$this->exceptionClass = $exceptionClass;

src/TypeProviderResolver/AnyScopeContextTypeProviderResolver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
final class AnyScopeContextTypeProviderResolver implements ContextTypeProviderResolverInterface
1212
{
13-
/** @var ContextTypeProviderInterface */
14-
private $contextTypeProvider;
13+
private ContextTypeProviderInterface $contextTypeProvider;
1514
public function __construct(ContextTypeProviderInterface $contextTypeProvider)
1615
{
1716
$this->contextTypeProvider = $contextTypeProvider;

0 commit comments

Comments
 (0)