Passed
Pull Request — master (#57)
by Andrey
13:11
created

PathJson   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 62
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A real() 0 3 1
A source() 0 7 1
A getPathForEnglish() 0 5 2
A clean() 0 5 2
A target() 0 6 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\LaravelLangPublisher\Contracts\Path as PathContract;
0 ignored issues
show
Bug introduced by
The type Helldar\LaravelLangPublisher\Contracts\Path was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Helldar\LaravelLangPublisher\Facades\Config as ConfigFacade;
7
8
final class PathJson implements PathContract
9
{
10
    protected $extension = '.json';
11
12
    /**
13
     * Returns a direct link to the folder with the source localization files.
14
     *
15
     * If the file name is specified, a full link to the file will be returned,
16
     * otherwise a direct link to the folder.
17
     *
18
     * @param string|null $locale
19
     * @param string|null $filename
20
     *
21
     * @return string
22
     */
23
    public function source(string $locale = null, string $filename = null): string
24
    {
25
        $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...on::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

25
        $locale = $this->getPathForEnglish(/** @scrutinizer ignore-type */ $locale);
Loading history...
26
        $locale = $this->clean($locale);
27
28
        return $this->real(
29
            ConfigFacade::getVendorPath() . '/../json' . $locale . $this->extension
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
    public function target(string $locale = null, string $filename = null): string
46
    {
47
        dd('qqq');
48
        $locale = $this->clean($locale);
49
50
        return resource_path(self::LANG . $locale . $this->extension);
51
    }
52
53
    protected function real(string $path): string
54
    {
55
        return realpath($path);
56
    }
57
58
    protected function clean(string $path = null): ?string
59
    {
60
        return $path
61
            ? self::DIVIDER . ltrim($path, self::DIVIDER)
62
            : $path;
63
    }
64
65
    protected function getPathForEnglish(string $locale): string
66
    {
67
        return $locale === 'en'
68
            ? '../script/en'
69
            : $locale;
70
    }
71
}
72