RemoteCoverageTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
getTestResultObject() 0 1 ?
A appendRemoteCoverage() 0 7 2
A generateRemoteCoverageFile() 0 4 1
A getRemoteCoverageFiles() 0 4 1
A writeRemoteCoverage() 0 14 4
1
<?php
2
3
namespace Phwoolcon\TestStarter;
4
5
trait RemoteCoverageTrait
6
{
7
8
    public function appendRemoteCoverage()
9
    {
10
        foreach ($this->getRemoteCoverageFiles() as $coverageFile) {
11
            $this->getTestResultObject()->getCodeCoverage()->append(include $coverageFile);
12
            unlink($coverageFile);
13
        }
14
    }
15
16
    public function generateRemoteCoverageFile()
17
    {
18
        return tempnam(storagePath('remote-coverage'), 'cov-' . time() . '-');
19
    }
20
21
    public function getRemoteCoverageFiles()
22
    {
23
        return glob(storagePath('remote-coverage/cov-*'));
24
    }
25
26
    /**
27
     * @return \PHPUnit\Framework\TestResult
28
     */
29
    abstract public function getTestResultObject();
30
31
    public function writeRemoteCoverage()
32
    {
33
        $coverage = $this->getTestResultObject()->getCodeCoverage();
34
        $coverage->stop();
35
        $data = $coverage->getData(true);
36
        foreach ($data as $file => &$lines) {
37
            foreach ($lines as $line => &$executed) {
38
                $executed && $executed = 1;
39
            }
40
            unset($executed);
41
        }
42
        unset($lines);
43
        fileSaveArray($this->generateRemoteCoverageFile(), $data);
44
    }
45
}
46