Passed
Pull Request — main (#109)
by Andrey
71:41 queued 56:39
created

Pathable::pathResolveLocaleFilename()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 11
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Concerns;
4
5
use Helldar\LaravelLangPublisher\Facades\Config;
6
use Helldar\LaravelLangPublisher\Facades\Path;
7
8
trait Pathable
9
{
10 24
    protected function pathSource(string $package, string $locale): string
11
    {
12 24
        $this->log('Retrieving a link to the source directory for the', $package, 'package and the', $locale, 'localization...');
0 ignored issues
show
Bug introduced by
It seems like log() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

12
        $this->/** @scrutinizer ignore-call */ 
13
               log('Retrieving a link to the source directory for the', $package, 'package and the', $locale, 'localization...');
Loading history...
13
14 24
        return Path::source($package, $locale);
15
    }
16
17 24
    protected function pathTarget(string $locale, bool $is_json = false): string
18
    {
19 24
        $this->log('Retrieving a link to the target directory for the', $locale, '(is json:', $is_json, ') localization...');
20
21 24
        return Path::target($locale, $is_json);
22
    }
23
24 15
    protected function pathTargetFull(string $locale, ?string $filename): string
25
    {
26 15
        $this->log('Retrieving a link to the target file for the', $locale, 'localization, filename is ', $filename, '...');
27
28 15
        return Path::targetFull($locale, $filename);
29
    }
30
31 19
    protected function pathLocales(string $package, string $locale = null): string
32
    {
33 19
        $this->log('Getting the path to excluding English localization: ' . $locale);
34
35 19
        return Path::locales($package, $locale);
36
    }
37
38 24
    protected function pathVendor(): string
39
    {
40 24
        $this->log('Getting the vendor path.');
41
42 24
        return Config::basePath();
43
    }
44
45 14
    protected function pathDirectory(string $path): ?string
46
    {
47 14
        $this->log('Getting file directory:', $path);
48
49 14
        $directory = Path::directory($path);
50
51 14
        return $directory !== '.' ? $directory : null;
52
    }
53
54 14
    protected function pathFilename(string $path): string
55
    {
56 14
        $this->log('Getting file name without extension:', $path);
57
58 14
        return Path::filename($path);
59
    }
60
61 14
    protected function pathExtension(string $path): string
62
    {
63 14
        $this->log('Getting file extension:', $path);
64
65 14
        return Path::extension($path);
66
    }
67
68
    protected function pathResolveLocaleFilename(string $locale, string $filename): string
69
    {
70
        $directory = $this->pathDirectory($filename);
71
        $name      = $this->pathFilename($filename);
72
        $extension = $this->pathExtension($filename);
73
74
        $name = $this->isEnglish($name) ? $locale : $name;
0 ignored issues
show
Bug introduced by
It seems like isEnglish() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

74
        $name = $this->/** @scrutinizer ignore-call */ isEnglish($name) ? $locale : $name;
Loading history...
75
76
        $path = $directory . '/' . $name . '.' . $extension;
77
78
        return ltrim($path, '/');
79
    }
80
}
81