PortfolioSpec   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 6 1
A it_is_initializable() 0 4 1
A expectRequest() 0 6 1
A it_fetches_data_when_needed() 0 6 1
A it_belongs_to_collection() 0 7 1
1
<?php
2
3
namespace spec\Scriptotek\Alma\Bibs;
4
5
use PhpSpec\ObjectBehavior;
6
use Scriptotek\Alma\Bibs\Bib;
7
use Scriptotek\Alma\Bibs\Portfolio;
8
use Scriptotek\Alma\Bibs\Portfolios;
9
use Scriptotek\Alma\Client as AlmaClient;
10
use Scriptotek\Alma\Electronic\Collection;
11
use spec\Scriptotek\Alma\SpecHelper;
12
13
class PortfolioSpec extends ObjectBehavior
14
{
15
    public function let(AlmaClient $client, Bib $bib)
16
    {
17
        $bib->mms_id = 'abc';
18
        $portfolio_id = '123';
19
        $this->beConstructedWith($client, $bib, $portfolio_id);
20
    }
21
22
    public function it_is_initializable()
23
    {
24
        $this->shouldHaveType(Portfolio::class);
25
    }
26
27
    protected function expectRequest($client)
28
    {
29
        $client->getJSON('/bibs/abc/portfolios/123')
30
            ->shouldBeCalled()
31
            ->willReturn(SpecHelper::getDummyData('portfolio_response.json'));
32
    }
33
34
    public function it_fetches_data_when_needed(AlmaClient $client)
35
    {
36
        $this->expectRequest($client);
37
38
        $this->availability->desc->shouldBe('Available');
0 ignored issues
show
Documentation introduced by
The property availability does not exist on object<spec\Scriptotek\Alma\Bibs\PortfolioSpec>. 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...
39
    }
40
41
    public function it_belongs_to_collection(AlmaClient $client)
42
    {
43
        $this->expectRequest($client);
44
45
        $this->getElectronicCollection()->shouldHaveType(Collection::class);
46
        $this->electronic_collection->shouldHaveType(Collection::class);
0 ignored issues
show
Documentation introduced by
The property electronic_collection does not exist on object<spec\Scriptotek\Alma\Bibs\PortfolioSpec>. 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...
47
    }
48
}
49