Fees   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A get() 4 4 1
A convertToResource() 4 4 1
A urlBase() 4 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 Scriptotek\Alma\Users;
4
5
use Scriptotek\Alma\Client;
6
use Scriptotek\Alma\Model\IterableCollection;
7
use Scriptotek\Alma\Model\LazyResourceList;
8
use Scriptotek\Alma\Model\ReadOnlyArrayAccess;
9
10
/**
11
 * Iterable collection of Fee resources.
12
 */
13 View Code Duplication
class Fees extends LazyResourceList implements \Countable, \Iterator, \ArrayAccess
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...
14
{
15
    use ReadOnlyArrayAccess;
16
    use IterableCollection;
17
18
    /**
19
     * The User object this Fees list belongs to.
20
     *
21
     * @var User
22
     */
23
    public $user;
24
25
    /**
26
     * Fees constructor.
27
     *
28
     * @param Client $client
29
     * @param User   $user
30
     */
31
    public function __construct(Client $client, User $user)
32
    {
33
        parent::__construct($client, 'fee');
34
        $this->user = $user;
35
    }
36
37
    /**
38
     * Get a single Fee by id.
39
     *
40
     * @param string $id
41
     *
42
     * @return Fee
43
     */
44
    public function get($id)
45
    {
46
        return Fee::make($this->client, $this->user, $id);
47
    }
48
49
    /**
50
     * Convert a retrieved resource object to a model object.
51
     *
52
     * @param $data
53
     *
54
     * @return Fee
55
     */
56
    public function convertToResource($data)
57
    {
58
        return $this->get($data->id)->init($data);
59
    }
60
61
    /**
62
     * Generate the base URL for this resource.
63
     *
64
     * @return string
65
     */
66
    protected function urlBase()
67
    {
68
        return sprintf('/users/%s/fees', rawurlencode($this->user->id));
69
    }
70
}
71