FieldMapSpec::it_throws_if_field_is_not_found()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace spec\TomPHP\HalClient\Resource;
4
5
use PhpSpec\ObjectBehavior;
6
use TomPHP\HalClient\Exception\FieldNotFoundException;
7
use TomPHP\HalClient\Resource\FieldNode;
8
9
class FieldMapSpec extends ObjectBehavior
10
{
11
    function let(FieldNode $f1, FieldNode $f2)
12
    {
13
        $this->beConstructedWith([
14
            'field1' => $f1,
15
            'field2' => $f2,
16
        ]);
17
    }
18
19
    function it_returns_field_via_field_method(FieldNode $f1)
20
    {
21
        $this->getField('field1')->shouldReturn($f1);
22
    }
23
24
    function it_throws_if_field_is_not_found()
25
    {
26
        $this->shouldThrow(new FieldNotFoundException('unknown-field'))
27
             ->duringGetField('unknown-field');
28
    }
29
30
    function it_returns_field_via_magic_method(FieldNode $f1)
31
    {
32
        $this->field1->shouldReturn($f1);
0 ignored issues
show
Documentation introduced by
The property field1 does not exist on object<spec\TomPHP\HalCl...\Resource\FieldMapSpec>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
33
    }
34
35
    function it_does_not_match_if_critera_includes_unknown_field()
36
    {
37
        $this->matches(['unknown_field' => 'some-value'])->shouldReturn(false);
38
    }
39
40 View Code Duplication
    function it_does_match_if_all_criteria_fields_match(FieldNode $f1, FieldNode $f2)
0 ignored issues
show
Duplication introduced by
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...
41
    {
42
        $f1->matches('search-value1')->willReturn(true);
43
        $f2->matches('search-value2')->willReturn(true);
44
45
        $this->matches([
46
            'field1' => 'search-value1',
47
            'field2' => 'search-value2',
48
        ])->shouldReturn(true);
49
    }
50
51 View Code Duplication
    function it_does_not_match_if_any_criteria_fields_fail_to_match(FieldNode $f1, FieldNode $f2)
0 ignored issues
show
Duplication introduced by
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...
52
    {
53
        $f1->matches('search-value1')->willReturn(true);
54
        $f2->matches('search-value2')->willReturn(false);
55
56
        $this->matches([
57
            'field1' => 'search-value1',
58
            'field2' => 'search-value2',
59
        ])->shouldReturn(false);
60
    }
61
}
62