Completed
Pull Request — master (#186)
by Vladimir
05:50 queued 02:55
created

Country::getCountries()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file contains functionality relating to the countries players are allowed to set in their profiles as their location
4
 *
5
 * @package    BZiON\Models
6
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
7
 */
8
9
/**
10
 * A country
11
 */
12
class Country extends Model implements NamedModel
13
{
14
    /** @var string The name of the country */
15
    protected $name;
16
17
    /** @var string The ISO code of the country */
18
    protected $iso;
19
20
    const DELETED_COLUMN = 'is_deleted';
21
    const TABLE = 'countries';
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function assignResult($country)
27
    {
28
        $this->name = $country['name'];
29
        $this->iso = $country['iso'];
30
    }
31
32
    /**
33
     * Get the name of the country in the default language
34
     *
35 1
     * @return string The name of the country
36
     */
37 1
    public function getName()
38 1
    {
39 1
        return $this->name;
40
    }
41
42
    /**
43
     * Get the ISO code of a country
44
     *
45
     * @return string The ISO code of the country
46 1
     */
47
    public function getISO()
48 1
    {
49
        return $this->iso;
50
    }
51
52
    /**
53
     * Get the HTML to display a specific flag
54
     *
55
     * @return string HTML to generate a flag
56 1
     */
57
    public function getFlagLiteral()
58 1
    {
59
        return '<div class="c-flag ' . $this->getFlagCssClass() . '" aria-hidden="true" title="' . $this->getName() . '"></div>';
60
    }
61
62
    /**
63
     * Get the country's flag's CSS class
64
     *
65
     * @return string The URL to the country's flag
66 1
     */
67
    private function getFlagCssClass()
68 1
    {
69
        return "c-flag--" . strtolower($this->getISO());
70
    }
71
72
    /**
73
     * Get a query builder for countries
74
     *
75
     * @throws Exception When no database is configured for BZiON
76
     *
77
     * @return QueryBuilderFlex
78
     */
79
    public static function getQueryBuilder()
80
    {
81
        return QueryBuilderFlex::createForModel(Country::class)
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
82
            ->setNameColumn('name')
83
        ;
84
    }
85
}
86