Passed
Pull Request — 9.x (#103)
by Andrey
12:39
created

Package::sourcePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Packages;
4
5
use Helldar\LaravelLangPublisher\Concerns\Contains;
6
use Helldar\LaravelLangPublisher\Concerns\Logger;
7
use Helldar\LaravelLangPublisher\Contracts\Package as Contract;
8
use Helldar\LaravelLangPublisher\Facades\Config;
9
use Helldar\LaravelLangPublisher\Facades\Path;
10
use Helldar\Support\Concerns\Makeable;
11
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
12
13
abstract class Package implements Contract
14
{
15
    use Contains;
16
    use Logger;
0 ignored issues
show
Bug introduced by
The trait Helldar\LaravelLangPublisher\Concerns\Logger requires the property $output which is not provided by Helldar\LaravelLangPublisher\Packages\Package.
Loading history...
17
    use Makeable;
18
19
    public function target(): string
20
    {
21
        return '/';
22
    }
23
24
    public function has(string $package = null, string $locale = null): bool
25
    {
26
        return Directory::exists($this->basePath() . '/' . $this->vendor());
27
    }
28
29
    public function sourcePath(string $package, string $locale): string
30
    {
31
        $path = Path::source($package, $locale);
32
33
        return $path . '/' . $this->source();
0 ignored issues
show
Bug introduced by
Are you sure $this->source() of type array can be used in concatenation? ( Ignorable by Annotation )

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

33
        return $path . '/' . /** @scrutinizer ignore-type */ $this->source();
Loading history...
34
    }
35
36
    public function targetPath(string $locale, string $filename): string
37
    {
38
        $target = Path::clean(Path::target($locale));
39
40
        $path = $this->target();
41
42
        $name = $this->targetFilename($locale, $filename);
43
44
        $filename = Path::clean($path . '/' . $name, true);
45
46
        return $target . '/' . $filename;
47
    }
48
49
    public function targetFilename(string $locale, string $filename): string
50
    {
51
        if ($this->isJson($filename)) {
52
            return $locale . '.json';
53
        }
54
55
        return $this->fileBasename($filename);
56
    }
57
58
    protected function basePath(): string
59
    {
60
        return Config::basePath();
61
    }
62
63
    protected function fileBasename(string $filename): string
64
    {
65
        return Path::basename($filename);
66
    }
67
}
68