Skip to content

Commit

Permalink
Revert "Revert "Adding Line Numbers To Mutator Ignore List (#663)""
Browse files Browse the repository at this point in the history
This reverts commit 4216c82.
  • Loading branch information
maks-rafalko committed Mar 29, 2019
1 parent 4216c82 commit d0b3e6a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
7 changes: 7 additions & 0 deletions infection.json.dist
Expand Up @@ -10,5 +10,12 @@
"badge": {
"branch": "master"
}
},
"mutators": {
"MethodCallRemoval": {
"ignore": [
"Infection\\Finder\\SourceFilesFinder::__construct::63"
]
}
}
}
6 changes: 5 additions & 1 deletion src/Mutator/Util/Mutator.php
Expand Up @@ -67,7 +67,11 @@ final public function shouldMutate(Node $node): bool
return true;
}

return !$this->config->isIgnored($reflectionClass->getName(), $node->getAttribute(ReflectionVisitor::FUNCTION_NAME, ''));
return !$this->config->isIgnored(
$reflectionClass->getName(),
$node->getAttribute(ReflectionVisitor::FUNCTION_NAME, ''),
$node->getLine()
);
}

final public static function getName(): string
Expand Down
7 changes: 5 additions & 2 deletions src/Mutator/Util/MutatorConfig.php
Expand Up @@ -56,7 +56,7 @@ public function __construct(array $config)
$this->mutatorSettings = $config['settings'] ?? [];
}

public function isIgnored(string $class, string $method): bool
public function isIgnored(string $class, string $method, int $lineNumber = null): bool
{
if (\in_array($class, $this->ignoreConfig)) {
return true;
Expand All @@ -67,7 +67,10 @@ public function isIgnored(string $class, string $method): bool
}

foreach ($this->ignoreConfig as $ignorePattern) {
if (fnmatch($ignorePattern, $class, FNM_NOESCAPE) || fnmatch($ignorePattern, $class . '::' . $method, FNM_NOESCAPE)) {
if (fnmatch($ignorePattern, $class, FNM_NOESCAPE)
|| fnmatch($ignorePattern, $class . '::' . $method, FNM_NOESCAPE)
|| ($lineNumber !== null && fnmatch($ignorePattern, $class . '::' . $method . '::' . $lineNumber, FNM_NOESCAPE))
) {
return true;
}
}
Expand Down
11 changes: 9 additions & 2 deletions tests/Mutator/Util/MutatorConfigTest.php
Expand Up @@ -46,11 +46,11 @@ final class MutatorConfigTest extends TestCase
/**
* @dataProvider providesIgnoredValues
*/
public function test_is_ignored_returns_true_if_there_is_a_match(array $ignored, string $class, string $method): void
public function test_is_ignored_returns_true_if_there_is_a_match(array $ignored, string $class, string $method, int $lineNumber = null): void
{
$config = new MutatorConfig(['ignore' => $ignored]);

$this->assertTrue($config->isIgnored($class, $method));
$this->assertTrue($config->isIgnored($class, $method, $lineNumber));
}

public function providesIgnoredValues(): \Generator
Expand Down Expand Up @@ -90,6 +90,13 @@ public function providesIgnoredValues(): \Generator
'Foo\Bar\Test',
'method',
];

yield 'It ignores a specific line number' => [
['Foo\Bar\Test::method::63'],
'Foo\Bar\Test',
'method',
63,
];
}

/**
Expand Down

0 comments on commit d0b3e6a

Please sign in to comment.