Passed
Pull Request — main (#96)
by Andrey
79:05 queued 64:02
created

Validator::package()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\LaravelLangPublisher\Concerns\Logger;
6
use Helldar\LaravelLangPublisher\Concerns\Pathable;
7
use Helldar\LaravelLangPublisher\Constants\Locales as LocalesList;
8
use Helldar\LaravelLangPublisher\Exceptions\PackageDoesntExistsException;
9
use Helldar\LaravelLangPublisher\Exceptions\SourceLocaleDoesntExistsException;
10
use Helldar\LaravelLangPublisher\Facades\Locales as LocalesFacade;
11
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
12
13
class Validator
14
{
15
    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\Support\Validator.
Loading history...
16
    use Pathable;
17
18
    /**
19
     * Checking for localization existence.
20
     *
21
     * @param  string  $locale
22
     */
23
    public function locale(string $locale): void
24
    {
25
        $this->log('Checking for localization existence: ' . $locale);
26
27
        if (! LocalesFacade::isAvailable($locale)) {
28
            throw new SourceLocaleDoesntExistsException($locale);
29
        }
30
    }
31
32
    public function package(string $package): void
33
    {
34
        $this->log('Checking for package existence: ' . $package);
35
36
        $source  = $this->pathSource($package, LocalesList::ENGLISH);
37
        $locales = $this->pathLocales($package);
38
39
        if (Directory::doesntExist($source) || Directory::doesntExist($locales)) {
40
            throw new PackageDoesntExistsException($package);
41
        }
42
    }
43
}
44