Completed
Pull Request — master (#59)
by
unknown
03:43 queued 01:10
created

Link::__construct()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 15
rs 8.8571
cc 5
eloc 8
nc 5
nop 2
1
<?php
2
3
namespace Moip;
4
5
/**
6
 * Class Link represents a single link from the resource HATEOAS structure.
7
 */
8
class Link
9
{
10
    /**
11
     * @var string link href. Currently it's taken from the href or redirectHref property.
12
     */
13
    private $href;
14
15
    /**
16
     * @var string|null link title, can be null.
17
     */
18
    private $title = null;
19
20
    /**
21
     * @var string link name it's used as key in the Links class.
22
     */
23
    private $name;
24
25
    /**
26
     * Link constructor.
27
     *
28
     * @param string    $name.
0 ignored issues
show
Bug introduced by
There is no parameter named $name.. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
29
     * @param \stdClass $obj.
0 ignored issues
show
Bug introduced by
There is no parameter named $obj.. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
30
     *
31
     * @throws \InvalidArgumentException if there isn't a href property on the $obj.
32
     */
33
    public function __construct($name, $obj)
34
    {
35
        $this->name = $name;
36
37
        $hasHref = empty($obj->href);
38
        if ($hasHref && empty($obj->redirectHref)) {
39
            throw new \InvalidArgumentException('Link is malformed. No href property');
40
        }
41
42
        $this->href = !$hasHref ? $obj->href : $obj->redirectHref;
43
44
        if (!empty($obj->title)) {
45
            $this->title = $obj->title;
46
        }
47
    }
48
49
    /**
50
     * Returns link location.
51
     *
52
     * @return string
53
     */
54
    public function getHref()
55
    {
56
        return $this->href;
57
    }
58
59
    /**
60
     * Return link title, if any.
61
     *
62
     * @return null|string
63
     */
64
    public function getTitle()
65
    {
66
        return $this->title;
67
    }
68
69
    /**
70
     * Returns link name e.g: "self". This is also the key used in the Links class.
71
     *
72
     * @return string
73
     */
74
    public function getName()
75
    {
76
        return $this->name;
77
    }
78
}
79