Completed
Push — master ( 9a7b87...ad20a3 )
by Alessandro
03:07
created

PHPUnitBinFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 44
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

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