Completed
Push — master ( dba3c8...01cd01 )
by Jean C.
07:48 queued 01:45
created

Links::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Helper;
4
5
use stdClass;
6
7
/**
8
 * Class that represents the HATEOAS structure of the API resources.
9
 */
10
class Links
11
{
12
    /**
13
     * @var array[string]Link Map a link name to it's representation.
14
     */
15
    private $links;
16
17
    /**
18
     * @var \stdClass
19
     */
20
    private $checkout;
21
22
    /**
23
     * Links constructor.
24
     *
25
     * @param stdClass $links "_link" returned from the API, if there isn't any.
26
     */
27
    public function __construct(stdClass $links)
28
    {
29
        $this->links = $links;
30
        $this->generateMethods();
31
    }
32
33
    /**
34
     * @return mixed
35
     */
36
    public function getSelf()
37
    {
38
        return $this->links->self->href;
39
    }
40
41
    /**
42
     * @param null|string $pay
43
     *
44
     * @return mixed
45
     */
46
    public function getCheckout($pay)
47
    {
48
        return $this->links->checkout->$pay->redirectHref;
49
    }
50
51
    /**
52
     * @return mixed
53
     */
54
    public function getAllCheckout()
55
    {
56
        return $this->checkout;
57
    }
58
59
    private function generateMethods()
60
    {
61
        $this->checkout = new stdClass();
62
63
        foreach ($this->links->checkout as $method => $link) {
64
            $this->checkout->$method = $link->redirectHref;
65
        }
66
    }
67
}
68