Phpunit   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 13
lcom 2
cbo 2
dl 0
loc 61
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A touchBootstrap() 0 6 2
A getBootstrapFile() 0 12 2
A prepareArgs() 0 14 6
A getVersion() 0 8 2
A detectVersion() 0 6 1
1
<?php
2
/**
3
 * HiDev plugin for PHPUnit
4
 *
5
 * @link      https://github.com/hiqdev/hidev-phpunit
6
 * @package   hidev-phpunit
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\phpunit\components;
12
13
use hidev\base\File;
14
use Yii;
15
16
/**
17
 * PHPunit.
18
 */
19
class Phpunit extends \hidev\base\Component
20
{
21
    protected $_version;
22
23
    protected $_bootstrapFile;
24
25
    public $colors;
26
    public $coverageText;
27
    public $coverageClover;
28
29
    public function touchBootstrap()
30
    {
31
        if (!$this->getBootstrapFile()->exists()) {
32
            $this->getBootstrapFile()->save();
33
        }
34
    }
35
36
    public function getBootstrapFile()
37
    {
38
        if ($this->_bootstrapFile === null) {
39
            $this->_bootstrapFile = Yii::createObject([
40
                'class'     => File::class,
41
                'template'  => 'phpunit/bootstrap.twig',
42
                'path'      => 'tests/_bootstrap.php',
43
            ]);
44
        }
45
46
        return $this->_bootstrapFile;
47
    }
48
49
    public function prepareArgs($args = [])
50
    {
51
        if ($this->coverageText) {
52
            $args[] = '--coverage-text';
53
        }
54
        if ($this->coverageClover) {
55
            $args[] = '--coverage-clover=' . (is_string($this->coverageClover) ? $this->coverageClover : 'coverage.clover');
56
        }
57
        if ($this->colors) {
58
            $args[] = '--colors' . (version_compare($this->getVersion(), '4.7.0', '>=') ? '=' . $this->colors : '');
59
        }
60
61
        return $args;
62
    }
63
64
    public function getVersion()
65
    {
66
        if ($this->_version === null) {
67
            $this->_version = $this->detectVersion();
68
        }
69
70
        return $this->_version;
71
    }
72
73
    public function detectVersion()
74
    {
75
        $lines = $this->exec('phpunit', ['--version']);
0 ignored issues
show
Documentation introduced by
array('--version') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
76
77
        return explode(' ', $lines[0], 3)[1];
78
    }
79
}
80