Completed
Push — master ( 9d90d4...cee823 )
by Dan Michael O.
03:06
created

Fee   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
dl 50
loc 50
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A urlBase() 4 4 1
A isInitialized() 4 4 1
A getItem() 8 8 2

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 Scriptotek\Alma\Users;
4
5
use Scriptotek\Alma\Bibs\Item;
6
use Scriptotek\Alma\Client;
7
use Scriptotek\Alma\Model\LazyResource;
8
9
/**
10
 * A single Fee resource.
11
 */
12 View Code Duplication
class Fee extends LazyResource
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...
13
{
14
    /* @var User */
15
    protected $user;
16
17
    /* @var string */
18
    protected $id;
19
20
    public function __construct(Client $client, User $user, $id)
21
    {
22
        parent::__construct($client);
23
        $this->user = $user;
24
        $this->id = $id;
25
    }
26
27
    /**
28
     * Generate the base URL for this resource.
29
     *
30
     * @return string
31
     */
32
    protected function urlBase()
33
    {
34
        return "/users/{$this->user->id}/fees/{$this->id}";
35
    }
36
37
    /**
38
     * Check if we have the full representation of our data object.
39
     *
40
     * @param \stdClass $data
41
     * @return boolean
42
     */
43
    protected function isInitialized($data)
44
    {
45
        return isset($data->link);
46
    }
47
48
    /**
49
     * Get the related Item, if any.
50
     *
51
     * @return Item|null
52
     */
53
    public function getItem()
54
    {
55
        if (isset($this->barcode)) {
56
            return $this->client->items->fromBarcode($this->barcode);
0 ignored issues
show
Documentation introduced by
The property barcode does not exist on object<Scriptotek\Alma\Users\Fee>. 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...
57
        }
58
59
        return null;
60
    }
61
}
62