Skip to content

Commit b399c7a

Browse files
committed
ContextKeyRule - add missing original pattern test case
1 parent 7e40315 commit b399c7a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/Rules/ContextKeyRule.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ private function originalPatternMatches(array $constantArrays, string $methodNam
152152
$key = $keyType->getValue();
153153

154154
if (! is_string($key)) {
155-
continue;
155+
// keyType be string is checked by keysAreNonEmptyString()
156+
// @codeCoverageIgnoreStart
157+
continue; // @codeCoverageIgnoreEnd
156158
}
157159

158160
$matched = preg_match($this->contextKeyOriginalPattern, $key, $matches);

src/Rules/PlaceholderCorrespondToKeysRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private static function contextDoesNotHavePlaceholderKey(Type $arrayType, string
126126
$checkBraces = $braces;
127127
foreach ($constantArray->getKeyTypes() as $keyType) {
128128
if ($keyType->isString()->no()) {
129-
// keyType is checked by ContextKeyRule
129+
// keyType be string checked by ContextKeyRule
130130
// @codeCoverageIgnoreStart
131131
continue; // @codeCoverageIgnoreEnd
132132
}

test/Rules/ContextKeyRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ public function testAlwaysShouldBeCheckedNonEmptyString(): void
5858
]);
5959
}
6060

61+
public function testOriginalPattern(): void
62+
{
63+
$this->contextKeyOriginalPattern = '#\A[A-Za-z0-9-]+\z#';
64+
$this->analyse([__DIR__ . '/data/contextKey_originalPattern.php'], [
65+
[
66+
'Parameter $context of logger method Psr\Log\LoggerInterface::info(), key should be match #\A[A-Za-z0-9-]+\z#.',
67+
14,
68+
],
69+
]);
70+
}
71+
6172
public function testEmptyStringPattern(): void
6273
{
6374
$this->contextKeyOriginalPattern = '';

0 commit comments

Comments
 (0)