Completed
Push — master ( d033d4...935271 )
by Alessandro
13:34 queued 08:28
created

PHPUnitBinFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 21.28 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 61.53%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 0
dl 10
loc 47
ccs 8
cts 13
cp 0.6153
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 10 24 4
A getPhpUnitBin() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
     */
23 12
    public function __construct()
24
    {
25 12
        if (defined('PARAUNIT_PHAR_FILE')) {
26
            // Paraunit is running as a standalone PHAR archive
27
            // PHPUnit is embedded in the archive, self execute it in special mode
28
            $this->phpUnitBin = PARAUNIT_PHAR_FILE . ' phpunit';
29
30
            return;
31
        }
32
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
39 12 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 12
            return;
43
        }
44
45
        throw new \RuntimeException('PHPUnit bin not found');
46
    }
47
48
    /**
49
     * @return string
50
     */
51 12
    public function getPhpUnitBin()
52
    {
53 12
        return $this->phpUnitBin;
54
    }
55
}
56