FieldCollectionSpec   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 40
loc 40
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 4 4 1
A it_is_accessible_via_ArrayAccess() 5 5 1
A it_is_accessible_can_be_checked_if_index_exists() 5 5 1
A it_is_immutable() 5 5 1
A it_finds_matching_nodes() 9 9 1
A it_is_countable() 4 4 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\TomPHP\HalClient\Resource;
4
5
use PhpSpec\ObjectBehavior;
6
use TomPHP\HalClient\Exception\MutabilityException;
7
use TomPHP\HalClient\Resource\FieldCollection;
8
use TomPHP\HalClient\Resource\FieldNode;
9
10 View Code Duplication
class FieldCollectionSpec extends ObjectBehavior
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...
11
{
12
    function let(FieldNode $f1, FieldNode $f2)
13
    {
14
        $this->beConstructedWith([$f1, $f2]);
15
    }
16
17
    function it_is_accessible_via_ArrayAccess(FieldNode $f1, FieldNode $f2)
18
    {
19
        $this[0]->shouldBe($f1);
20
        $this[1]->shouldBe($f2);
21
    }
22
23
    function it_is_accessible_can_be_checked_if_index_exists()
24
    {
25
        $this->offsetExists(0)->shouldReturn(true);
26
        $this->offsetExists(2)->shouldReturn(false);
27
    }
28
29
    function it_is_immutable()
30
    {
31
        $this->shouldThrow(new MutabilityException())->duringOffsetSet(0, 'value');
32
        $this->shouldThrow(new MutabilityException())->duringOffsetUnset(0);
33
    }
34
35
    function it_finds_matching_nodes(FieldNode $f1, FieldNode $f2)
36
    {
37
        $criteria = ['search' => 'criteria'];
38
39
        $f1->matches($criteria)->willReturn(false);
40
        $f2->matches($criteria)->willReturn(true);
41
42
        $this->findMatching($criteria)->shouldBeLike(new FieldCollection([$f2->getWrappedObject()]));
43
    }
44
45
    function it_is_countable()
46
    {
47
        $this->count()->shouldReturn(2);
48
    }
49
}
50