Completed
Pull Request — master (#16)
by
unknown
01:12
created

getSupportedLocales()   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 RichanFongdasen\I18n\Traits;
4
5
use RichanFongdasen\I18n\I18nService;
6
7
trait TranslatedRouteCommandContext
8
{
9
    /**
10
     * Returns whether a given locale is supported.
11
     *
12
     * @param string $locale
13
     *
14
     * @return bool
15
     */
16
    protected function isSupportedLocale($locale)
17
    {
18
        return $this->getI18nService()->getLocale($locale) !== null;
19
    }
20
21
    /**
22
     * @return string[]
23
     */
24
    protected function getSupportedLocales()
25
    {
26
        return $this->getI18nService()->getLocale()->toArray();
27
    }
28
29
    /**
30
     * @return \RichanFongdasen\I18n\I18nService
31
     */
32
    protected function getI18nService()
33
    {
34
        return app(I18nService::class);
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    protected function getBootstrapPath()
41
    {
42
        return $this->laravel->bootstrapPath();
0 ignored issues
show
Bug introduced by
The property laravel does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
    }
44
45
    /**
46
     * @param string|null $locale
47
     *
48
     * @return string
49
     */
50 View Code Duplication
    protected function makeLocaleRoutesPath($locale = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $path = $this->laravel->getCachedRoutesPath();
53
        if ($locale === null) {
54
            return $path;
55
        }
56
        $path = substr($path, 0, -4).'_'.$locale.'.php';
57
58
        return $path;
59
    }
60
61
    /**
62
     * The env key that the forced locale for routing is stored in.
63
     *
64
     * @return string
65
     */
66
    protected function getLocaleEnvKey()
67
    {
68
        return I18nService::ENV_ROUTE_KEY;
69
    }
70
}
71