Passed
Push — master ( c97482...68f9e3 )
by Andrey
07:00 queued 04:30
created

Json::source()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support\Path;
4
5
use Helldar\LaravelLangPublisher\Facades\Config;
6
7
final class Json extends BasePath
8
{
9
    protected $is_json = true;
10
11
    /**
12
     * Returns a direct link to the folder with the source localization files.
13
     *
14
     * If the file name is specified, a full link to the file will be returned,
15
     * otherwise a direct link to the folder.
16
     *
17
     * @param  string|null  $locale
18
     * @param  string|null  $filename
19
     *
20
     * @return string
21
     */
22 54
    public function source(string $locale = null, string $filename = null): string
23
    {
24 54
        $locale   = $this->getPathForEnglish($locale);
0 ignored issues
show
Bug introduced by
It seems like $locale can also be of type null; however, parameter $locale of Helldar\LaravelLangPubli...th::getPathForEnglish() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
        $locale   = $this->getPathForEnglish(/** @scrutinizer ignore-type */ $locale);
Loading history...
25 54
        $locale   = $this->clean($locale);
26 54
        $filename = $this->clean($filename);
27
28 54
        return $this->real(
29 54
            Config::getVendorPath() . $locale . $filename
30
        );
31
    }
32
33
    /**
34
     * Returns the direct link to the localization folder or,
35
     * if the file name is specified, a link to the localization file.
36
     *
37
     * If the file name or localization is not specified,
38
     * the link to the shared folder of all localizations will be returned.
39
     *
40
     * @param  string|null  $locale
41
     * @param  string|null  $filename
42
     *
43
     * @return string
44
     */
45 54
    public function target(string $locale = null, string $filename = null): string
46
    {
47 54
        $locale   = $this->clean($locale);
48 54
        $filename = $this->clean($filename);
49
50 54
        return $this->is_json
51 54
            ? resource_path(self::LANG . $locale . '.json')
52 54
            : resource_path(self::LANG . $locale . $filename);
53
    }
54
}
55