ItemSpec   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 21.43 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 0
Metric Value
dl 18
loc 84
rs 10
c 0
b 0
f 0
wmc 8
lcom 2
cbo 7

8 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 8 1
A it_is_initializable() 0 4 1
A it_can_be_checked_out() 0 18 1
A it_can_be_on_loan() 9 9 1
A it_can_be_available() 9 9 1
A it_can_be_scanned_in() 0 11 1
A it_can_be_scanned_in_with_params() 0 11 1
A it_has_requests() 0 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\Scriptotek\Alma\Bibs;
4
5
use PhpSpec\ObjectBehavior;
6
use Scriptotek\Alma\Bibs\Bib;
7
use Scriptotek\Alma\Bibs\Holding;
8
use Scriptotek\Alma\Bibs\Item;
9
use Scriptotek\Alma\Bibs\ScanInResponse;
10
use Scriptotek\Alma\Client as AlmaClient;
11
use Scriptotek\Alma\Conf\Library;
12
use Scriptotek\Alma\Users\Loan;
13
use Scriptotek\Alma\Users\Requests;
14
use Scriptotek\Alma\Users\User;
15
use spec\Scriptotek\Alma\SpecHelper;
16
17
class ItemSpec extends ObjectBehavior
18
{
19
    public function let(AlmaClient $client, Bib $bib, Holding $holding)
20
    {
21
        $bib->mms_id = '990006312214702204';
22
        $holding->holding_id = '22163771200002204';
23
        $item_id = '23163771190002204';
24
25
        $this->beConstructedWith($client, $bib, $holding, $item_id);
26
    }
27
28
    public function it_is_initializable()
29
    {
30
        $this->shouldHaveType(Item::class);
31
    }
32
33
    public function it_can_be_checked_out(AlmaClient $client, User $user, Library $library)
34
    {
35
        $client->postJSON(
36
            '/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204/loans?user_id=Dan+Michael',
37
            [
38
                'library'   => ['value' => 'THAT LIBRARY'],
39
                'circ_desk' => ['value' => 'DEFAULT_CIRC_DESK'],
40
            ]
41
        )
42
            ->shouldBeCalled()
43
            ->willReturn(SpecHelper::getDummyData('create_loan_response.json'));
44
45
        $user->id = 'Dan Michael';
46
        $library->code = 'THAT LIBRARY';
47
48
        $this->checkOut($user, $library)
49
            ->shouldHaveType(Loan::class);
50
    }
51
52 View Code Duplication
    public function it_can_be_on_loan(AlmaClient $client, User $user, Library $library)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $library is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
53
    {
54
        $client->getJSON('/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204/loans')
55
            ->shouldBeCalled()
56
            ->willReturn(SpecHelper::getDummyData('item_loan_response.json'));
57
58
        $this->getLoan()->shouldHaveType(Loan::class);
59
        $this->loan->shouldHaveType(Loan::class);
0 ignored issues
show
Documentation introduced by
The property loan does not exist on object<spec\Scriptotek\Alma\Bibs\ItemSpec>. 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...
60
    }
61
62 View Code Duplication
    public function it_can_be_available(AlmaClient $client, User $user, Library $library)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $library is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
63
    {
64
        $client->getJSON('/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204/loans')
65
            ->shouldBeCalled()
66
            ->willReturn(SpecHelper::getDummyData('item_no_loan_response.json'));
67
68
        $this->getLoan()->shouldBe(null);
69
        $this->loan->shouldBe(null);
0 ignored issues
show
Documentation introduced by
The property loan does not exist on object<spec\Scriptotek\Alma\Bibs\ItemSpec>. 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...
70
    }
71
72
    public function it_can_be_scanned_in(AlmaClient $client, Library $library)
73
    {
74
        $client->postJSON('/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204?op=scan&library=THAT+LIBRARY&circ_desk=DEFAULT_CIRC_DESK')
75
            ->shouldBeCalled()
76
            ->willReturn(SpecHelper::getDummyData('scanin_transit_response.json'));
77
78
        $library->code = 'THAT LIBRARY';
79
80
        $this->scanIn($library)
81
            ->shouldHaveType(ScanInResponse::class);
82
    }
83
84
    public function it_can_be_scanned_in_with_params(AlmaClient $client, Library $library)
85
    {
86
        $client->postJSON('/bibs/990006312214702204/holdings/22163771200002204/items/23163771190002204?place_on_hold_shelf=true&op=scan&library=THAT+LIBRARY&circ_desk=OTHER_DESK')
87
            ->shouldBeCalled()
88
            ->willReturn(SpecHelper::getDummyData('scanin_transit_response.json'));
89
90
        $library->code = 'THAT LIBRARY';
91
92
        $this->scanIn($library, 'OTHER_DESK', ['place_on_hold_shelf' => 'true'])
93
            ->shouldHaveType(ScanInResponse::class);
94
    }
95
96
    public function it_has_requests()
97
    {
98
        $this->requests->shouldHaveType(Requests::class);
0 ignored issues
show
Documentation introduced by
The property requests does not exist on object<spec\Scriptotek\Alma\Bibs\ItemSpec>. 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...
99
    }
100
}
101