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

PHPUnitBinFile::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.7691

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 7
cts 11
cp 0.6364
rs 9.2
cc 4
eloc 10
nc 4
nop 0
crap 4.7691
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