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

Links   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSelf() 0 4 1
A getCheckout() 0 4 1
A getAllCheckout() 0 4 1
A generateMethods() 0 8 2
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