Completed
Push — master ( a29d2d...4681dd )
by Hannes
10:53 queued 08:08
created

AmountProcessorSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 27
loc 27
rs 10
c 0
b 0
f 0

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
declare(strict_types = 1);
4
5
namespace spec\byrokrat\autogiro\Processor;
6
7
use byrokrat\autogiro\Processor\AmountProcessor;
8
use byrokrat\autogiro\Tree\AmountNode;
9
use byrokrat\amount\Currency\SEK;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
13
class AmountProcessorSpec extends ObjectBehavior
14
{
15
    function it_is_initializable()
16
    {
17
        $this->shouldHaveType(AmountProcessor::CLASS);
18
    }
19
20
    function it_fails_on_unvalid_amounts(AmountNode $amountNode)
21
    {
22
        $amountNode->getLineNr()->willReturn(1);
23
        $amountNode->getType()->willReturn('AmountNode');
24
        $amountNode->getValue()->willReturn('this-is-not-a-valid-signal-string');
25
        $this->visitBefore($amountNode);
26
        $this->getErrors()->shouldHaveCount(1);
27
    }
28
29
    function it_creates_valid_amounts(AmountNode $amountNode)
30
    {
31
        $amountNode->getType()->willReturn('AmountNode');
32
        $amountNode->getValue()->willReturn('1230K');
33
34
        $amountNode->setAttribute('amount', Argument::exact(new SEK('-123.02')))->shouldBeCalled();
35
36
        $this->visitBefore($amountNode);
37
        $this->getErrors()->shouldHaveCount(0);
38
    }
39
}
40