CallPrediction   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 23.33 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A check() 14 36 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\Argument\ArgumentsWildcard;
18
use Prophecy\Argument\Token\AnyValuesToken;
19
use Prophecy\Util\StringUtil;
20
use Prophecy\Exception\Prediction\NoCallsException;
21
22
/**
23
 * Call prediction.
24
 *
25
 * @author Konstantin Kudryashov <[email protected]>
26
 */
27
class CallPrediction implements PredictionInterface
28
{
29
    private $util;
30
31
    /**
32
     * Initializes prediction.
33
     *
34
     * @param StringUtil $util
35
     */
36
    public function __construct(StringUtil $util = null)
37
    {
38
        $this->util = $util ?: new StringUtil;
39
    }
40
41
    /**
42
     * Tests that there was at least one call.
43
     *
44
     * @param Call[]         $calls
45
     * @param ObjectProphecy $object
46
     * @param MethodProphecy $method
47
     *
48
     * @throws \Prophecy\Exception\Prediction\NoCallsException
49
     */
50
    public function check(array $calls, ObjectProphecy $object, MethodProphecy $method)
51
    {
52
        if (count($calls)) {
53
            return;
54
        }
55
56
        $methodCalls = $object->findProphecyMethodCalls(
57
            $method->getMethodName(),
58
            new ArgumentsWildcard(array(new AnyValuesToken))
59
        );
60
61 View Code Duplication
        if (count($methodCalls)) {
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...
62
            throw new NoCallsException(sprintf(
63
                "No calls have been made that match:\n".
64
                "  %s->%s(%s)\n".
65
                "but expected at least one.\n".
66
                "Recorded `%s(...)` calls:\n%s",
67
68
                get_class($object->reveal()),
69
                $method->getMethodName(),
70
                $method->getArgumentsWildcard(),
71
                $method->getMethodName(),
72
                $this->util->stringifyCalls($methodCalls)
73
            ), $method);
74
        }
75
76
        throw new NoCallsException(sprintf(
77
            "No calls have been made that match:\n".
78
            "  %s->%s(%s)\n".
79
            "but expected at least one.",
80
81
            get_class($object->reveal()),
82
            $method->getMethodName(),
83
            $method->getArgumentsWildcard()
84
        ), $method);
85
    }
86
}
87