CallbackPrediction   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 41
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 2
A check() 10 10 3

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
/*
4
 * This file is part of the Prophecy.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *     Marcello Duarte <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Prophecy\Prediction;
13
14
use Prophecy\Call\Call;
15
use Prophecy\Prophecy\ObjectProphecy;
16
use Prophecy\Prophecy\MethodProphecy;
17
use Prophecy\Exception\InvalidArgumentException;
18
use Closure;
19
20
/**
21
 * Callback prediction.
22
 *
23
 * @author Konstantin Kudryashov <[email protected]>
24
 */
25 View Code Duplication
class CallbackPrediction implements PredictionInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
26
{
27
    private $callback;
28
29
    /**
30
     * Initializes callback prediction.
31
     *
32
     * @param callable $callback Custom callback
33
     *
34
     * @throws \Prophecy\Exception\InvalidArgumentException
35
     */
36
    public function __construct($callback)
37
    {
38
        if (!is_callable($callback)) {
39
            throw new InvalidArgumentException(sprintf(
40
                'Callable expected as an argument to CallbackPrediction, but got %s.',
41
                gettype($callback)
42
            ));
43
        }
44
45
        $this->callback = $callback;
46
    }
47
48
    /**
49
     * Executes preset callback.
50
     *
51
     * @param Call[]         $calls
52
     * @param ObjectProphecy $object
53
     * @param MethodProphecy $method
54
     */
55
    public function check(array $calls, ObjectProphecy $object, MethodProphecy $method)
56
    {
57
        $callback = $this->callback;
58
59
        if ($callback instanceof Closure && method_exists('Closure', 'bind')) {
60
            $callback = Closure::bind($callback, $object);
61
        }
62
63
        call_user_func($callback, $calls, $object, $method);
64
    }
65
}
66