DiceFactoryCollectionSpec   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 29.17 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 14
loc 48
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_doesnt_handle_types_not_handled_by_its_factories() 7 7 1
A it_handles_types_if_one_factory_does() 7 7 1
A it_delegates_construction_to_its_factories() 0 10 1
A it_throws_an_exception_if_asked_to_build_dice_it_cant() 0 8 1

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
namespace spec\MeadSteve\DiceApi\Dice\Factories;
4
5
use MeadSteve\DiceApi\Dice\BasicDice;
6
use MeadSteve\DiceApi\Dice;
7
use MeadSteve\DiceApi\Dice\Factories\DiceFactory;
8
use MeadSteve\DiceApi\Dice\Factories\NumericDiceFactory;
9
use MeadSteve\DiceApi\Dice\UncreatableDiceException;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
13
class DiceFactoryCollectionSpec extends ObjectBehavior
14
{
15
    function let(DiceFactory $factoryOne, DiceFactory $factoryTwo)
16
    {
17
        $this->beConstructedWith([$factoryOne, $factoryTwo]);
18
    }
19
20
    function it_is_initializable()
21
    {
22
        $this->shouldHaveType(DiceFactory::class);
23
    }
24
25 View Code Duplication
    function it_doesnt_handle_types_not_handled_by_its_factories(DiceFactory $factoryOne, DiceFactory $factoryTwo)
0 ignored issues
show
Duplication introduced by steve.brazier
This method 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
        $factoryOne->handlesType('test')->willReturn(false);
28
        $factoryTwo->handlesType('test')->willReturn(false);
29
30
        $this->handlesType('test')->shouldReturn(false);
31
    }
32
33 View Code Duplication
    function it_handles_types_if_one_factory_does(DiceFactory $factoryOne, DiceFactory $factoryTwo)
0 ignored issues
show
Duplication introduced by steve.brazier
This method 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...
34
    {
35
        $factoryOne->handlesType('test')->willReturn(false);
36
        $factoryTwo->handlesType('test')->willReturn(true);
37
38
        $this->handlesType('test')->shouldReturn(true);
39
    }
40
41
    function it_delegates_construction_to_its_factories(DiceFactory $factoryOne, DiceFactory $factoryTwo)
42
    {
43
        $factoryOne->handlesType('test')->willReturn(false);
44
45
        $diceCollection = [new BasicDice(1)];
46
        $factoryTwo->handlesType('test')->willReturn(true);
47
        $factoryTwo->buildDice('test', 1)->willReturn($diceCollection);
48
49
        $this->buildDice('test', 1)->shouldReturn($diceCollection);
50
    }
51
52
    function it_throws_an_exception_if_asked_to_build_dice_it_cant(DiceFactory $factoryOne, DiceFactory $factoryTwo)
53
    {
54
        $factoryOne->handlesType('test')->willReturn(false);
55
        $factoryTwo->handlesType('test')->willReturn(false);
56
57
58
        $this->shouldThrow(UncreatableDiceException::class)->duringBuildDice('test', 1);
59
    }
60
}
61