Completed
Push — master ( 9da439...13f38d )
by ARCANEDEV
03:20
created

Yon::keys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php namespace Arcanesoft\Core\Entities;
2
3
/**
4
 * Class     Yon
5
 *
6
 * @package  Arcanesoft\Core\Entities
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
class Yon
10
{
11
    /* -----------------------------------------------------------------
12
     |  Constants
13
     | -----------------------------------------------------------------
14
     */
15
16
    const YES = 'yes';
17
    const NO  = 'no';
18
19
    /* -----------------------------------------------------------------
20
     |  All
21
     | -----------------------------------------------------------------
22
     */
23
24
    /**
25
     * Get all.
26
     *
27
     * @return \Illuminate\Support\Collection
28
     */
29
    public static function all()
30
    {
31
        return collect([
32
            static::YES => trans('core::statuses.'.static::YES),
33
            static::NO  => trans('core::statuses.'.static::NO),
34
        ]);
35
    }
36
37
    /**
38
     * Get all keys.
39
     *
40
     * @return \Illuminate\Support\Collection
41
     */
42
    public static function keys()
43
    {
44
        return static::all()->keys();
45
    }
46
47
    /**
48
     * Get a translated YoN status.
49
     *
50
     * @param  string|boolean  $key
51
     * @param  null            $default
52
     *
53
     * @return string|null
54
     */
55
    public static function get($key, $default = null)
56
    {
57
        return static::all()->get(static::parseKey($key), $default);
0 ignored issues
show
Bug introduced by
Since parseKey() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of parseKey() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
58
    }
59
60
    /**
61
     * Parse the key.
62
     *
63
     * @param  string|boolean  $key
64
     *
65
     * @return string
66
     */
67
    private static function parseKey($key)
68
    {
69
        return is_bool($key)
70
            ? ($key ? static::YES : static::NO)
71
            : $key;
72
    }
73
}
74