FileMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkMapping() 0 6 1
A __construct() 0 4 1
A match() 0 9 3
1
<?php
2
namespace exussum12\CoverageChecker\FileMatchers;
3
4
use exussum12\CoverageChecker\FileMatcher;
5
use exussum12\CoverageChecker\Exceptions\FileNotFound;
6
7
/**
8
 * Class FileMapper
9
 * @package exussum12\CoverageChecker\FileMatchers
10
 */
11
class FileMapper implements FileMatcher
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $originalPath;
17
    /**
18
     * @var string
19
     */
20
    protected $newPath;
21
22
    public function __construct(string $originalPath, string $newPath)
23
    {
24
        $this->originalPath = $originalPath;
25
        $this->newPath = $newPath;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function match(string $needle, array $haystack): string
32
    {
33
        foreach ($haystack as $file) {
34
            if ($this->checkMapping($file, $needle)) {
35
                return $file;
36
            }
37
        }
38
39
        throw new FileNotFound();
40
    }
41
42
    private function checkMapping(string $file, string $needle): bool
43
    {
44
        return $file == str_replace(
45
            $this->originalPath,
46
            $this->newPath,
47
            $needle
48
        );
49
    }
50
}
51