Completed
Push — master ( 36644b...bc2be6 )
by Andrii
09:15
created

src/components/Phpunit.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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-2017, 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
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