Completed
Pull Request — master (#24)
by
unknown
05:45 queued 03:36
created

CodeTable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scriptotek\Alma\Conf;
4
5
use Scriptotek\Alma\Client;
6
use Scriptotek\Alma\Model\LazyResource;
7
8
/**
9
 * A single CodeTable resource.
10
 */
11
class CodeTable extends LazyResource
12
{
13
    /** @var string */
14
    public $code;
15
16
    /**
17
     * CodeTable constructor.
18
     *
19
     * @param Client $client
20
     * @param string $code
21
     */
22
    public function __construct(Client $client, $code)
23
    {
24
        parent::__construct($client);
25
        $this->code = $code;
26
    }
27
28
    /**
29
    * Return a single row referring to the code table.
30
    *
31
    * @param $code - The code in the Table we want to pull.
32
    *
33
    * @return object - the row in the code table.
34
    */
35
    public function getRowByCode($code)
36
    {
37
        $found = array();
38
        $codeTable = json_decode($this->client->get($this->urlBase()));
39
40
        foreach ($codeTable->row as $row) {
41
            if ($row->code == $code) {
42
                array_push($found,$row);
43
            }
44
        }
45
46
        return($found);
47
    }
48
49
    /**
50
     * Check if we have the full representation of our data object.
51
     *
52
     * @param \stdClass $data
53
     *
54
     * @return bool
55
     */
56
    protected function isInitialized($data)
57
    {
58
        return isset($data->name);
59
    }
60
61
    /**
62
     * Generate the base URL for this resource.
63
     *
64
     * @return string
65
     */
66
    protected function urlBase()
67
    {
68
        return "/conf/code-tables/{$this->code}";
69
    }
70
71
}
72