InterfacePass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 24
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 21 3
1
<?php
2
/**
3
 * Mockery
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://github.com/padraic/mockery/blob/master/LICENSE
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Mockery
16
 * @package    Mockery
17
 * @copyright  Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
18
 * @license    http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
19
 */
20
21
namespace Mockery\Generator\StringManipulation\Pass;
22
23
use Mockery\Generator\MockConfiguration;
24
25
class InterfacePass implements Pass
26
{
27 399
    public function apply($code, MockConfiguration $config)
28
    {
29 399
        foreach ($config->getTargetInterfaces() as $i) {
0 ignored issues
show
Bug introduced by
The expression $config->getTargetInterfaces() of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
30 20
            $name = ltrim($i->getName(), "\\");
31 20
            if (!interface_exists($name)) {
32 2
                \Mockery::declareInterface($name);
33 2
            }
34 399
        }
35
36 399
        $interfaces = array_reduce((array) $config->getTargetInterfaces(), function ($code, $i) {
37 20
            return $code . ", \\" . ltrim($i->getName(), "\\");
38 399
        }, "");
39
40 399
        $code = str_replace(
41 399
            "implements MockInterface",
42 399
            "implements MockInterface" . $interfaces,
43
            $code
44 399
        );
45
46 399
        return $code;
47
    }
48
}
49