GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TranslationManager::getDefaultDriver()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace WeAreNeopix\LaravelModelTranslation;
4
5
use Illuminate\Support\Manager;
6
use WeAreNeopix\LaravelModelTranslation\Contracts\TranslationDriver;
7
use WeAreNeopix\LaravelModelTranslation\Drivers\JSONTranslationDriver;
8
use WeAreNeopix\LaravelModelTranslation\Drivers\ArrayTranslationDriver;
9
use WeAreNeopix\LaravelModelTranslation\Exceptions\NoDefaultDriverException;
10
use WeAreNeopix\LaravelModelTranslation\Drivers\MySQL\MySQLTranslationDriver;
11
use WeAreNeopix\LaravelModelTranslation\Exceptions\InvalidTranslationDriverException;
12
13
class TranslationManager extends Manager
14
{
15
    /**
16
     * The default driver to be used.
17
     *
18
     * @var string
19
     */
20
    protected $defaultDriver;
21
22
    /**
23
     * Create the JSON translation driver.
24
     *
25
     * @return \WeAreNeopix\LaravelModelTranslation\Drivers\JSONTranslationDriver
26
     */
27
    public function createJsonDriver()
28
    {
29
        return $this->container->make(JSONTranslationDriver::class);
30
    }
31
32
    /**
33
     * Create the MySQL translation driver.
34
     *
35
     * @return \WeAreNeopix\LaravelModelTranslation\Drivers\MySQL\MySQLTranslationDriver
36
     */
37
    public function createMysqlDriver()
38
    {
39
        return $this->container->make(MySQLTranslationDriver::class);
40
    }
41
42
    /**
43
     * Create the array translation driver.
44
     *
45
     * @return \WeAreNeopix\LaravelModelTranslation\Drivers\ArrayTranslationDriver
46
     */
47
    public function createArrayDriver()
48
    {
49
        return $this->container->make(ArrayTranslationDriver::class);
50
    }
51
52
    /**
53
     * Returns the default driver's name.
54
     *
55
     * @return string
56
     */
57
    public function getDefaultDriver()
58
    {
59
        if ($this->defaultDriver === null) {
60
            $configDriver = $this->container['config']['translation.driver'];
61
            if ($configDriver === null) {
62
                $message = 'A default translation driver has not been specified.';
63
                throw new NoDefaultDriverException($message);
64
            }
65
66
            $this->defaultDriver = $configDriver;
67
        }
68
69
        return $this->defaultDriver;
70
    }
71
72
    /**
73
     * Set the default driver in runtime.
74
     *
75
     * @param string $driver
76
     * @return self
77
     */
78
    public function setDefaultDriver(string $driver)
79
    {
80
        $this->defaultDriver = $driver;
81
82
        return $this;
83
    }
84
85
    /**
86
     * Returns a list of all the instantiable drivers.
87
     *
88
     * @return array
89
     */
90
    public function getAvailableDrivers()
91
    {
92
        return array_merge(
93
            [
94
            'json', 'mysql', 'array',
95
            ],
96
            $this->getRegisteredExtensionNames()
97
        );
98
    }
99
100
    /**
101
     * Returns an array of all the registered extensions.
102
     *
103
     * @return array
104
     */
105
    public function getRegisteredExtensionNames()
106
    {
107
        return array_keys($this->customCreators);
108
    }
109
110
    /**
111
     * We override this method to ensure that all the drivers
112
     * provided by this manager implement the TranslationDriver interface.
113
     *
114
     * @param  string|null $driver
115
     * @throws InvalidTranslationDriverException
116
     * @return TranslationDriver
117
     */
118
    public function driver($driver = null)
119
    {
120
        $driverConcrete = parent::driver($driver);
121
122
        if (! $driverConcrete instanceof TranslationDriver) {
123
            $message = 'All translation drivers must implement the TranslationDriver interface.';
124
            throw new InvalidTranslationDriverException($message);
125
        }
126
127
        return $driverConcrete;
128
    }
129
}
130