Passed
Push — features/split-packages ( 745907...9ff8f9 )
by Andrey
14:17
created

Plugin::cleanPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Plugins;
4
5
use Helldar\LaravelLangPublisher\Concerns\Contains;
6
use Helldar\LaravelLangPublisher\Concerns\Logger;
7
use Helldar\LaravelLangPublisher\Contracts\Plugin 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 Plugin 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\Plugins\Plugin.
Loading history...
17
    use Makeable;
18
19
    public function target(): ?string
20
    {
21
        return null;
22
    }
23
24
    public function has(): bool
25
    {
26
        $this->log('Check if the package is installed:', $this->vendor());
27
28
        $source = $this->basePath() . '/' . $this->vendor();
29
30
        return Directory::exists($source);
31
    }
32
33
    public function targetPath(string $locale, string $filename): string
34
    {
35
        $this->log('Getting a link to the target file for:', $filename, '(', $locale, ')');
36
37
        $path = $this->resolveTargetPath($locale, $filename);
38
39
        $target = $this->targetFilename($locale, $filename);
40
41
        return $this->cleanPath($path . '/' . $target);
42
    }
43
44
    protected function targetFilename(string $locale, string $filename): string
45
    {
46
        $this->log('Retrieving the changed filename:', $filename, '(', $locale, ')');
47
48
        if ($this->isJson($filename)) {
49
            return $locale . '.json';
50
        }
51
52
        return $this->fileBasename($filename);
53
    }
54
55
    protected function basePath(): string
56
    {
57
        return Config::basePath();
58
    }
59
60
    protected function fileBasename(string $filename): string
61
    {
62
        return Path::basename($filename);
63
    }
64
65
    protected function cleanPath(?string $path): ?string
66
    {
67
        return Path::clean($path, true);
68
    }
69
70
    protected function resolveTargetPath(string $locale, string $filename): ?string
71
    {
72
        $this->log('Resolving the path to the target file:', $filename, '(', $locale, ')');
73
74
        $path = $this->cleanPath($this->target());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->target() targeting Helldar\LaravelLangPubli...lugins\Plugin::target() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
75
76
        if ($this->isPhp($filename)) {
77
            $path .= '/' . $locale;
78
        }
79
80
        return $this->cleanPath($path);
81
    }
82
}
83