Issues (3)

src/Database/Subdivisions.php (1 issue)

1
<?php
2
3
namespace Sokil\IsoCodes\Database;
4
5
use Sokil\IsoCodes\AbstractDatabase;
6
use Sokil\IsoCodes\Database\Subdivisions\Subdivision;
7
8
class Subdivisions extends AbstractDatabase
9
{
10
    public static function getISONumber()
11
    {
12
        return '3166-2';
13
    }
14
15
    /**
16
     * @param array $entry
17
     *
18
     * @return Subdivision
19
     */
20
    protected function arrayToEntry(array $entry)
21
    {
22
        return new Subdivision(
23
            $entry['name'],
24
            $entry['code'],
25
            $entry['type'],
26
            !empty($entry['parent']) ? $entry['parent'] : null
27
        );
28
    }
29
30
    /**
31
     * @return array
32
     */
33
    protected function getIndexDefinition()
34
    {
35
        return [
36
            'code',
37
            'country_code' => [['code', 2], 'code'],
38
        ];
39
    }
40
41
    /**
42
     * @param $code
43
     * @return Subdivision
44
     */
45
    public function getByCode($code)
46
    {
47
        return $this->find('code', $code);
48
    }
49
50
    /**
51
     * @param $code
52
     * @return Subdivision[]
53
     */
54
    public function getAllByCountryCode($code)
55
    {
56
        return $this->find('country_code', $code);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->find('country_code', $code) also could return the type object which is incompatible with the documented return type Sokil\IsoCodes\Database\Subdivisions\Subdivision[].
Loading history...
57
    }
58
}
59