Completed
Push — master ( d2992a...8fe16f )
by Michał
06:47
created

Helper::currentPathFixer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace CloverReporterTest;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
7
trait Helper
8
{
9
    protected $reportPaths = [
10
        'base' => 'tests' . DIRECTORY_SEPARATOR . 'reports' . DIRECTORY_SEPARATOR,
11
        'fix' => 'tests' . DIRECTORY_SEPARATOR . 'reports' . DIRECTORY_SEPARATOR . 'fixed' . DIRECTORY_SEPARATOR,
12
    ];
13
    protected $coverageClassesPath = 'tests' . DIRECTORY_SEPARATOR . 'CoverageClasses' . DIRECTORY_SEPARATOR;
14
15
    /**
16
     * @param string $report
17
     * @return string
18
     */
19
    public function currentPathFixer($report)
20
    {
21
        $basePath = getcwd();
22
        $newPath = $basePath . DIRECTORY_SEPARATOR . $this->coverageClassesPath;
23
24
        return str_replace('{$path}', $newPath, $report);
25
    }
26
27
    /**
28
     * @param string $reportName
29
     */
30
    public function copyFixedReports($reportName)
31
    {
32
        (new FileSystem)->remove($this->reportPaths['fix'] . $reportName);
33
34
        $report = file_get_contents($this->reportPaths['base'] . $reportName);
35
        file_put_contents($this->reportPaths['fix'] . $reportName, $this->currentPathFixer($report));
36
    }
37
}
38