diff --git a/bin/phpcsDiffFilter b/bin/phpcsDiffFilter index 9c94f4b..6a1fb4c 100755 --- a/bin/phpcsDiffFilter +++ b/bin/phpcsDiffFilter @@ -1,56 +1,17 @@ #!/usr/bin/env php getCoveredLines(); -$uncoveredLines = count($lines['uncoveredLines'], COUNT_RECURSIVE); - -if (empty($uncoveredLines)) { - exit(0); -} - -print_r($lines['uncoveredLines']); -exit(2); +handleOutput($lines, $minimumPercentCovered); diff --git a/bin/phpmdDiffFilter b/bin/phpmdDiffFilter index 44754db..f7007c4 100755 --- a/bin/phpmdDiffFilter +++ b/bin/phpmdDiffFilter @@ -1,56 +1,17 @@ #!/usr/bin/env php getCoveredLines(); -$uncoveredLines = count($lines['uncoveredLines'], COUNT_RECURSIVE); - -if (empty($uncoveredLines)) { - exit(0); -} - -print_r($lines['uncoveredLines']); -exit(2); +handleOutput($lines, $minimumPercentCovered); diff --git a/bin/phpunitDiffFilter b/bin/phpunitDiffFilter index 5a95da7..a3e3269 100755 --- a/bin/phpunitDiffFilter +++ b/bin/phpunitDiffFilter @@ -1,69 +1,17 @@ #!/usr/bin/env php getCoveredLines(); -$coveredLines = count($lines['coveredLines'], COUNT_RECURSIVE); -$uncoveredLines = count($lines['uncoveredLines'], COUNT_RECURSIVE); - -if($coveredLines + $uncoveredLines == 0) { - exit(0); -} - -$percentCovered = 100 * ($coveredLines / ($coveredLines + $uncoveredLines)); -if ($percentCovered >= $minimumPercentCovered) { - exit(0); -} - -echo "$percentCovered% Covered, Missed lines " . PHP_EOL; -print_r($lines['uncoveredLines']); -exit(2); +handleOutput($lines, $minimumPercentCovered); diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..8b398b3 --- /dev/null +++ b/functions.php @@ -0,0 +1,87 @@ += $minimumPercentCovered) { + exit(0); + } + + echo "$percentCovered% Covered, Missed lines " . PHP_EOL; + print_r($lines['uncoveredLines']); + exit(2); +} diff --git a/src/FileMatchers/EndsWith.php b/src/FileMatchers/EndsWith.php index 7cefdd9..aca336f 100644 --- a/src/FileMatchers/EndsWith.php +++ b/src/FileMatchers/EndsWith.php @@ -26,7 +26,7 @@ public function match($needle, array $haystack) } /** - * Month for finding if two strings end in the same way + * Find if two strings end in the same way * @param $haystack * @param $needle * @return bool diff --git a/src/FileMatchers/FileMapper.php b/src/FileMatchers/FileMapper.php new file mode 100644 index 0000000..5e7ff07 --- /dev/null +++ b/src/FileMatchers/FileMapper.php @@ -0,0 +1,60 @@ +originalPath = $originalPath; + $this->newPath = $newPath; + } + + /** + * {@inheritdoc} + */ + public function match($needle, array $haystack) + { + foreach ($haystack as $file) { + if ($this->checkMapping($file, $needle)) { + return $file; + } + } + + throw new FileNotFound(); + } + + /** + * @param string $file + * @param string $needle + * @return bool + */ + private function checkMapping($file, $needle) + { + return $file == str_replace( + $this->originalPath, + $this->newPath, + $needle + ); + } +} diff --git a/tests/FileMatchers/FileMapperTest.php b/tests/FileMatchers/FileMapperTest.php new file mode 100644 index 0000000..405588b --- /dev/null +++ b/tests/FileMatchers/FileMapperTest.php @@ -0,0 +1,36 @@ +assertEquals( + '/home/person/code/file.php', + $fileMapper->match($needle, $haystack) + ); + } + + public function testDoesNotExist() + { + $this->expectException(FileNotFound::class); + $fileMapper = new FileMapper('prefix', '/full/path'); + $needle = "fileDoesNotExist.php"; + $haystack = []; + + $fileMapper->match($needle, $haystack); + } +}