BibSpec   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 5

11 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_exist() 0 6 1
A it_links_to_network_zone() 0 12 1
A it_provides_lazy_access_to_holdings() 0 5 1
A it_has_a_MARC_record() 0 7 1
A it_can_be_edited() 0 11 1
A it_catches_resource_not_found() 0 8 1
A it_has_requests() 0 4 1
A let() 0 4 1
A expectRequest() 0 6 1
A it_is_lazy() 0 5 1
A it_fetches_record_data_when_needed() 0 7 1
1
<?php
2
3
namespace spec\Scriptotek\Alma\Bibs;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Scriptotek\Alma\Bibs\Bib;
8
use Scriptotek\Alma\Bibs\Bibs;
9
use Scriptotek\Alma\Bibs\Holdings;
10
use Scriptotek\Alma\Client as AlmaClient;
11
use Scriptotek\Alma\Exception\ResourceNotFound;
12
use Scriptotek\Alma\Users\Requests;
13
use Scriptotek\Marc\Record;
14
use spec\Scriptotek\Alma\SpecHelper;
15
16
class BibSpec extends ObjectBehavior
17
{
18
    public function let(AlmaClient $client)
19
    {
20
        $this->beConstructedWith($client, '999104760474702204');
21
    }
22
23
    protected function expectRequest($client)
24
    {
25
        $client->getXML('/bibs/999104760474702204')
26
            ->shouldBeCalled()
27
            ->willReturn(SpecHelper::getDummyData('bib_response_iz.xml'));
28
    }
29
30
    public function it_is_lazy(AlmaClient $client)
31
    {
32
        SpecHelper::expectNoRequests($client);
33
        $this->shouldHaveType(Bib::class);
34
    }
35
36
    public function it_fetches_record_data_when_needed(AlmaClient $client)
37
    {
38
        $this->expectRequest($client);
39
40
        $this->created_by->shouldBe('import');
0 ignored issues
show
Documentation introduced by
The property created_by does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
41
        $this->created_date->shouldBe('2015-11-05Z');
0 ignored issues
show
Documentation introduced by
The property created_date does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
42
    }
43
44
    public function it_can_exist(AlmaClient $client)
45
    {
46
        $this->expectRequest($client);
47
48
        $this->exists()->shouldBe(true);
49
    }
50
51
    public function it_links_to_network_zone(AlmaClient $client, AlmaClient $nz, Bibs $bibs, Bib $nz_bib)
52
    {
53
        $this->expectRequest($client);
54
55
        $client->nz = $nz;
56
        $nz->bibs = $bibs;
57
        $bibs->get('999104760474702201')
58
            ->shouldBeCalled()
59
            ->willReturn($nz_bib);
60
61
        $this->getNzRecord()->shouldHaveType(Bib::class);
62
    }
63
64
    public function it_provides_lazy_access_to_holdings(AlmaClient $client)
65
    {
66
        SpecHelper::expectNoRequests($client);
67
        $this->holdings->shouldHaveType(Holdings::class);
0 ignored issues
show
Documentation introduced by
The property holdings does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
68
    }
69
70
    public function it_has_a_MARC_record(AlmaClient $client)
71
    {
72
        $this->expectRequest($client);
73
74
        $this->record->shouldHaveType(Record::class);
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
75
        $this->record->getField('245')->getSubfield('a')->getData()->shouldBe('Lonely hearts of the cosmos :');
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
76
    }
77
78
    public function it_can_be_edited(AlmaClient $client)
79
    {
80
        $this->expectRequest($client);
81
82
        $this->record->getField('245')->getSubfield('a')->setData('New title');
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
83
84
        $client->putXML('/bibs/999104760474702204', Argument::containingString('New title'))
85
            ->shouldBeCalled();
86
87
        $this->save();
88
    }
89
90
    public function it_catches_resource_not_found(AlmaClient $client)
91
    {
92
        $client->getXML('/bibs/999104760474702204')
93
            ->shouldBeCalled()
94
            ->willThrow(ResourceNotFound::class);
95
96
        $this->exists()->shouldBe(false);
97
    }
98
99
    public function it_has_requests()
100
    {
101
        $this->requests->shouldHaveType(Requests::class);
0 ignored issues
show
Documentation introduced by
The property requests does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
102
    }
103
}
104