Completed
Pull Request — master (#62)
by Alessandro
09:23
created

PHPUnitBinFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 69.23%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 38
ccs 9
cts 13
cp 0.6923
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 4
A getPhpUnitBin() 0 4 1
1
<?php
2
3
namespace Paraunit\Configuration;
4
5
/**
6
 * Class PHPUnitBinFile
7
 * @package Paraunit\Configuration
8
 */
9
class PHPUnitBinFile
10
{
11
    // I'm using Paraunit as a vendor package
12
    const PHPUNIT_RELPATH_FOR_VENDOR = '/../../../../../phpunit/phpunit/phpunit';
13
    // I'm using Paraunit standalone (developing)
14
    const PHPUNIT_RELPATH_FOR_STANDALONE = '/../../../vendor/phpunit/phpunit/phpunit';
15
    // I'm using Paraunit in a PHAR
16
    const PHPUNIT_RELPATH_FOR_PHAR = 'vendor/phpunit/phpunit/phpunit';
17
18
    /** @var string Realpath to PHPUnit bin location */
19
    private $phpUnitBin;
20
21
    /**
22
     * PHPUnitBinFile constructor.
23
     */
24 11
    public function __construct()
25
    {
26 11
        if (file_exists(__DIR__.self::PHPUNIT_RELPATH_FOR_VENDOR)) {
27
            $this->phpUnitBin = __DIR__.self::PHPUNIT_RELPATH_FOR_VENDOR;
28 11
        } elseif (file_exists(__DIR__.self::PHPUNIT_RELPATH_FOR_STANDALONE)) {
29 11
            $this->phpUnitBin = __DIR__.self::PHPUNIT_RELPATH_FOR_STANDALONE;
30 11
        } elseif (file_exists(self::PHPUNIT_RELPATH_FOR_PHAR)) {
31
            $this->phpUnitBin = self::PHPUNIT_RELPATH_FOR_PHAR;
32
        } else {
33
            throw new \Exception('PHPUnit bin not found');
34
        }
35
36 11
        $this->phpUnitBin = realpath($this->phpUnitBin);
37 11
    }
38
39
    /**
40
     * @return string
41
     */
42 11
    public function getPhpUnitBin()
43
    {
44 11
        return $this->phpUnitBin;
45
    }
46
}
47