PHPUnitBinFile   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 61.53%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 54
ccs 8
cts 13
cp 0.6153
rs 10
c 0
b 0
f 0

3 Methods

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