Completed
Pull Request — master (#62)
by Alessandro
07:11
created

PHPUnitBinFile::__construct()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 11

Duplication

Lines 10
Ratio 41.67 %

Code Coverage

Tests 8
CRAP Score 4.128

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 10
loc 24
ccs 8
cts 10
cp 0.8
rs 8.6845
cc 4
eloc 11
nc 4
nop 0
crap 4.128
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
16
    /** @var string Realpath to PHPUnit bin location */
17
    private $phpUnitBin;
18
19
    /**
20
     * PHPUnitBinFile constructor.
21
     * @throws \RuntimeException
22 12
     */
23
    public function __construct()
24 12
    {
25
        if (defined('PARAUNIT_PHAR_FILE')) {
26 12
            // Paraunit is running as a standalone PHAR archive
27 12
            // PHPUnit is embedded in the archive, self execute it in special mode
28 12
            $this->phpUnitBin = PARAUNIT_PHAR_FILE . ' phpunit';
29
30
            return;
31
        }
32 12
33 12 View Code Duplication
        if (file_exists(__DIR__ . self::PHPUNIT_RELPATH_FOR_VENDOR)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            $this->phpUnitBin = realpath(__DIR__ . self::PHPUNIT_RELPATH_FOR_VENDOR);
35
36
            return;
37
        }
38 12
39 View Code Duplication
        if (file_exists(__DIR__ . self::PHPUNIT_RELPATH_FOR_STANDALONE)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40 12
            $this->phpUnitBin = realpath(__DIR__ . self::PHPUNIT_RELPATH_FOR_STANDALONE);
41
42
            return;
43
        }
44
45
        throw new \RuntimeException('PHPUnit bin not found');
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getPhpUnitBin()
52
    {
53
        return $this->phpUnitBin;
54
    }
55
}
56