Skip to content

Commit 5581dd1

Browse files
authored
Merge pull request #83 from sasezaki/identifer
PHPStan 1.11 support - error identifier must not includes hyphen
2 parents 1e34e00 + 8996c26 commit 5581dd1

7 files changed

+33
-24
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ This package provides the following rules.
4646
4747
| :pushpin: _error identifier_ |
4848
| --- |
49-
| sfp-psr-log.placeholderCharactersInvalidChar |
49+
| sfpPsrLog.placeholderCharactersInvalidChar |
5050

5151
* reports when placeholder in `$message` characters are **not**, `A-Z`, `a-z`, `0-9`, underscore `_`, and period `.`
5252

@@ -57,7 +57,7 @@ $logger->info('message are {foo-hyphen}');
5757

5858
| :pushpin: _error identifier_ |
5959
| --- |
60-
| sfp-psr-log.placeholderCharactersDoubleBraces |
60+
| sfpPsrLog.placeholderCharactersDoubleBraces |
6161

6262
* reports when double braces pair `{{` `}}` are used.
6363

@@ -72,7 +72,7 @@ $logger->info('message are {{foo}}');
7272
7373
| :pushpin: _error identifier_ |
7474
| --- |
75-
| sfp-psr-log.placeholderCorrespondToKeysMissedContext |
75+
| sfpPsrLog.placeholderCorrespondToKeysMissedContext |
7676

7777
* reports when placeholder exists in message, but `$context` parameter is missed.
7878

@@ -83,7 +83,7 @@ $logger->info('message has {nonContext} .');
8383

8484
| :pushpin: _error identifier_ |
8585
| --- |
86-
| sfp-psr-log.placeholderCorrespondToKeysMissedKey |
86+
| sfpPsrLog.placeholderCorrespondToKeysMissedKey |
8787

8888
* reports when placeholder exists in message, but key in `$context` does not exist against them.
8989

@@ -99,7 +99,7 @@ $logger->info('user {user_id} gets an error {error} .', ['user_id' => $user_id])
9999
100100
| :pushpin: _error identifier_ |
101101
| --- |
102-
| sfp-psr-log.contextKeyNonEmptyString |
102+
| sfpPsrLog.contextKeyNonEmptyString |
103103

104104
* reports when context key is not **non-empty-string**.
105105

@@ -110,7 +110,7 @@ $logger->info('user {user_id} gets an error {error} .', ['user_id' => $user_id])
110110

111111
| :pushpin: _error identifier_ |
112112
| --- |
113-
| sfp-psr-log.contextKeyOriginalPattern |
113+
| sfpPsrLog.contextKeyOriginalPattern |
114114

115115
* reports when context key is not matched you defined pattern.
116116
* if `contextKeyOriginalPattern` parameter is not set, this check would be ignored.
@@ -132,7 +132,7 @@ parameters:
132132
133133
| :pushpin: _error identifier_ |
134134
| --- |
135-
| sfp-psr-log.contextRequireExceptionKey |
135+
| sfpPsrLog.contextRequireExceptionKey |
136136

137137
* It forces `exception` key into context parameter when current scope has `\Throwable` object.
138138

@@ -194,7 +194,7 @@ parameters:
194194

195195
| :pushpin: _error identifier_ |
196196
| --- |
197-
| sfp-psr-log.messageNotStaticString |
197+
| sfpPsrLog.messageNotStaticString |
198198

199199
* reports when $message is not static string value.
200200

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"require": {
1010
"php": "^7.2.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0",
11-
"phpstan/phpstan": "^1.10",
11+
"phpstan/phpstan": "^1.11",
1212
"struggle-for-php/sfp-stubs-psr-log": "^1.0.1 || ^2 || ^3.0.1"
1313
},
1414
"require-dev": {
@@ -21,6 +21,9 @@
2121
"squizlabs/php_codesniffer": "^3.7",
2222
"vimeo/psalm": "^4 || ^5.9"
2323
},
24+
"conflict": {
25+
"nikic/php-parser": "<4.13.0"
26+
},
2427
"autoload": {
2528
"psr-4": {
2629
"Sfp\\PHPStan\\Psr\\Log\\": "src"

src/Rules/ContextKeyRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function processNode(Node $node, Scope $scope): array
110110
* phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
111111
* @phpstan-param list<\PHPStan\Type\Constant\ConstantArrayType> $constantArrays
112112
* phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
113-
* @phpstan-return list<\PHPStan\Rules\RuleError>
113+
* @phpstan-return list<\PHPStan\Rules\IdentifierRuleError>
114114
*/
115115
private static function keysAreNonEmptyString(array $constantArrays, string $methodName): array
116116
{
@@ -123,7 +123,7 @@ private static function keysAreNonEmptyString(array $constantArrays, string $met
123123

124124
$errors[] = RuleErrorBuilder::message(
125125
sprintf(self::ERROR_NOT_NON_EMPTY_STRING, $methodName)
126-
)->identifier('sfp-psr-log.contextKeyNonEmptyString')->build();
126+
)->identifier('sfpPsrLog.contextKeyNonEmptyString')->build();
127127
}
128128
}
129129

@@ -134,7 +134,7 @@ private static function keysAreNonEmptyString(array $constantArrays, string $met
134134
* phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
135135
* @phpstan-param list<\PHPStan\Type\Constant\ConstantArrayType> $constantArrays
136136
* phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
137-
* @phpstan-return list<\PHPStan\Rules\RuleError>
137+
* @phpstan-return list<\PHPStan\Rules\IdentifierRuleError>
138138
*/
139139
private function originalPatternMatches(array $constantArrays, string $methodName): array
140140
{
@@ -166,7 +166,7 @@ private function originalPatternMatches(array $constantArrays, string $methodNam
166166
if ($matched === 0) {
167167
$errors[] = RuleErrorBuilder::message(
168168
sprintf(self::ERROR_NOT_MATCH_ORIGINAL_PATTERN, $methodName, $this->contextKeyOriginalPattern)
169-
)->identifier('sfp-psr-log.contextKeyOriginalPattern')->build();
169+
)->identifier('sfpPsrLog.contextKeyOriginalPattern')->build();
170170
}
171171
}
172172
}

src/Rules/ContextRequireExceptionKeyRule.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ public function processNode(Node $node, Scope $scope): array
108108
return [];
109109
}
110110

111-
return [sprintf(self::ERROR_MISSED_EXCEPTION_KEY, $methodName, "\${$throwable}")];
111+
return [
112+
RuleErrorBuilder::message(
113+
sprintf(self::ERROR_MISSED_EXCEPTION_KEY, $methodName, "\${$throwable}")
114+
)->identifier('sfpPsrLog.contextRequireExceptionKey')->build(),
115+
];
112116
}
113117

114118
$context = $args[$contextArgumentNo];
@@ -121,7 +125,7 @@ public function processNode(Node $node, Scope $scope): array
121125
return [
122126
RuleErrorBuilder::message(
123127
sprintf(self::ERROR_MISSED_EXCEPTION_KEY, $methodName, "\${$throwable}")
124-
)->identifier('sfp-psr-log.contextRequireExceptionKey')->build(),
128+
)->identifier('sfpPsrLog.contextRequireExceptionKey')->build(),
125129
];
126130
}
127131

src/Rules/MessageStaticStringRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function processNode(Node $node, Scope $scope): array
7777
RuleErrorBuilder::message(
7878
sprintf(self::ERROR_MESSAGE_NOT_STATIC, $methodName)
7979
)
80-
->identifier('sfp-psr-log.messageNotStaticString')
80+
->identifier('sfpPsrLog.messageNotStaticString')
8181
->tip('See https://www.php-fig.org/psr/psr-3/meta/#static-log-messages')
8282
->build(),
8383
];

src/Rules/PlaceholderCharactersRule.php

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

77
use PhpParser\Node;
88
use PHPStan\Analyser\Scope;
9+
use PHPStan\Rules\IdentifierRuleError;
910
use PHPStan\Rules\Rule;
1011
use PHPStan\Rules\RuleError;
1112
use PHPStan\Rules\RuleErrorBuilder;
@@ -100,7 +101,7 @@ public function processNode(Node $node, Scope $scope): array
100101
return $errors;
101102
}
102103

103-
private static function checkDoubleBrace(string $message, string $methodName): ?RuleError
104+
private static function checkDoubleBrace(string $message, string $methodName): ?IdentifierRuleError
104105
{
105106
$matched = preg_match_all('#{{(.+?)}}#', $message, $matches);
106107

@@ -111,12 +112,12 @@ private static function checkDoubleBrace(string $message, string $methodName): ?
111112
return RuleErrorBuilder::message(
112113
sprintf(self::ERROR_DOUBLE_BRACES, $methodName, implode(',', $matches[0]))
113114
)
114-
->identifier('sfp-psr-log.placeholderCharactersDoubleBraces')
115+
->identifier('sfpPsrLog.placeholderCharactersDoubleBraces')
115116
->tip('See https://www.php-fig.org/psr/psr-3/#12-message')
116117
->build();
117118
}
118119

119-
private static function checkInvalidChar(string $message, string $methodName): ?RuleError
120+
private static function checkInvalidChar(string $message, string $methodName): ?IdentifierRuleError
120121
{
121122
$matched = preg_match_all('#{(.+?)}#', $message, $matches);
122123

@@ -138,7 +139,7 @@ private static function checkInvalidChar(string $message, string $methodName): ?
138139
return RuleErrorBuilder::message(
139140
sprintf(self::ERROR_INVALID_CHAR, $methodName, implode(',', $invalidPlaceHolders))
140141
)
141-
->identifier('sfp-psr-log.placeholderCharactersInvalidChar')
142+
->identifier('sfpPsrLog.placeholderCharactersInvalidChar')
142143
->tip('See https://www.php-fig.org/psr/psr-3/#12-message')
143144
->build();
144145
}

src/Rules/PlaceholderCorrespondToKeysRule.php

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

77
use PhpParser\Node;
88
use PHPStan\Analyser\Scope;
9+
use PHPStan\Rules\IdentifierRuleError;
910
use PHPStan\Rules\Rule;
1011
use PHPStan\Rules\RuleError;
1112
use PHPStan\Rules\RuleErrorBuilder;
@@ -91,7 +92,7 @@ public function processNode(Node $node, Scope $scope): array
9192
if (! isset($args[$contextArgumentNo])) {
9293
$errors[] = RuleErrorBuilder::message(
9394
sprintf(self::ERROR_MISSED_CONTEXT, $methodName, implode(',', $matches[0]))
94-
)->identifier('sfp-psr-log.placeholderCorrespondToKeysMissedContext')->build();
95+
)->identifier('sfpPsrLog.placeholderCorrespondToKeysMissedContext')->build();
9596

9697
continue;
9798
}
@@ -111,12 +112,12 @@ public function processNode(Node $node, Scope $scope): array
111112
* @phpstan-param list<string> $braces
112113
* @phpstan-param list<string> $placeholders
113114
*/
114-
private static function contextDoesNotHavePlaceholderKey(Type $arrayType, string $methodName, array $braces, array $placeholders): ?RuleError
115+
private static function contextDoesNotHavePlaceholderKey(Type $arrayType, string $methodName, array $braces, array $placeholders): ?IdentifierRuleError
115116
{
116117
if ($arrayType->isIterableAtLeastOnce()->no()) {
117118
return RuleErrorBuilder::message(
118119
self::ERROR_EMPTY_CONTEXT
119-
)->identifier('sfp-psr-log.placeholderCorrespondToKeysMissedKey')->build();
120+
)->identifier('sfpPsrLog.placeholderCorrespondToKeysMissedKey')->build();
120121
}
121122

122123
$constantArrays = $arrayType->getConstantArrays();
@@ -146,7 +147,7 @@ private static function contextDoesNotHavePlaceholderKey(Type $arrayType, string
146147

147148
return RuleErrorBuilder::message(
148149
sprintf(self::ERROR_MISSED_KEY, $methodName, implode(',', $checkBraces))
149-
)->identifier('sfp-psr-log.placeholderCorrespondToKeysMissedKey')->build();
150+
)->identifier('sfpPsrLog.placeholderCorrespondToKeysMissedKey')->build();
150151
}
151152

152153
return null;

0 commit comments

Comments
 (0)