Test Setup Failed
Pull Request — master (#24)
by
unknown
02:19
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 list of rows referring to the code of the rows in the table.
30
    *
31
    * @param string $code - The code of the row in the Table we want to pull.
32
    *
33
    * @return array $found - The rows in the code table that match the code passed in.
34
    */
35
    public function getRowByCode($code)
36
    {
37
        $found = array();
38
        $codeTable = json_decode($this->client->get($this->urlBase()));
39
        foreach ($codeTable->row as $row) {
40
            if ($row->code == $code) {
41
                array_push($found,$row);
42
            }
43
        }
44
        return($found);
45
    }
46
47
    /**
48
     * Check if we have the full representation of our data object.
49
     *
50
     * @param \stdClass $data
51
     *
52
     * @return bool
53
     */
54
    protected function isInitialized($data)
55
    {
56
        return isset($data->name);
57
    }
58
59
    /**
60
     * Generate the base URL for this resource.
61
     *
62
     * @return string
63
     */
64
    protected function urlBase()
65
    {
66
        return "/conf/code-tables/{$this->code}";
67
    }
68
69
}
70