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

Helper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A currentPathFixer() 0 7 1
A copyFixedReports() 0 7 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