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.
Completed
Push — master ( 59342b...9ed6b0 )
by Miša
01:23
created

TranslationManager::createInlineDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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