PHPUnitConfig   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 2
cbo 0
dl 0
loc 76
ccs 20
cts 20
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getFileFullPath() 0 4 1
A getBaseDirectory() 0 4 1
A addPhpunitOption() 0 4 1
A getPhpunitOptions() 0 4 1
A getConfigFileRealpath() 0 18 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Configuration;
6
7
/**
8
 * Class PHPUnitConfig
9
 * @package Paraunit\Configuration
10
 */
11
class PHPUnitConfig
12
{
13
    const DEFAULT_FILE_NAME = 'phpunit.xml.dist';
14
15
    /** @var string */
16
    private $configFilename;
17
18
    /** @var PHPUnitOption[] */
19
    private $phpunitOptions;
20
21
    /**
22
     * @param string $inputPathOrFileName
23
     * @throws \InvalidArgumentException
24
     */
25 45
    public function __construct(string $inputPathOrFileName)
26
    {
27 45
        $this->configFilename = $this->getConfigFileRealpath($inputPathOrFileName);
28 43
        $this->phpunitOptions = [];
29
    }
30
31
    /**
32
     * @return string The full path for this configuration file
33
     */
34 42
    public function getFileFullPath(): string
35
    {
36 42
        return $this->configFilename;
37
    }
38
39
    /**
40
     * @return string The relative path from where the configuration defines the testsuites
41
     */
42 42
    public function getBaseDirectory(): string
43
    {
44 42
        return dirname($this->configFilename);
45
    }
46
47
    /**
48
     * @param PHPUnitOption $option
49
     */
50 5
    public function addPhpunitOption(PHPUnitOption $option)
51
    {
52 5
        $this->phpunitOptions[] = $option;
53
    }
54
55
    /**
56
     * @return PHPUnitOption[]
57
     */
58 40
    public function getPhpunitOptions(): array
59
    {
60 40
        return $this->phpunitOptions;
61
    }
62
63
    /**
64
     * @param string $inputPathOrFileName
65
     * @return string
66
     * @throws \InvalidArgumentException
67
     */
68 45
    private function getConfigFileRealpath(string $inputPathOrFileName): string
69
    {
70 45
        $configFile = realpath($inputPathOrFileName);
71
72 45
        if (false === $configFile) {
73 1
            throw new \InvalidArgumentException('Config path/file provided is not valid: ' . $inputPathOrFileName);
74
        }
75
76 44
        if (is_dir($configFile)) {
77 5
            $configFile .= DIRECTORY_SEPARATOR . self::DEFAULT_FILE_NAME;
78
        }
79
80 44
        if (! is_file($configFile) || ! is_readable($configFile)) {
81 1
            throw new \InvalidArgumentException('Config file ' . $configFile . ' does not exist or is not readable');
82
        }
83
84 43
        return $configFile;
85
    }
86
}
87