Passed
Push — main ( 545ade...3cfdef )
by Andrey
79:39 queued 77:29
created

Validator::package()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

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
ccs 6
cts 6
cp 1
crap 3
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 13
    public function locale(string $locale): void
24
    {
25 13
        $this->log('Checking for localization existence: ' . $locale);
26
27 13
        if (! LocalesFacade::isAvailable($locale)) {
28 1
            throw new SourceLocaleDoesntExistsException($locale);
29
        }
30 12
    }
31
32 14
    public function package(string $package): void
33
    {
34 14
        $this->log('Checking for package existence: ' . $package);
35
36 14
        $source  = $this->pathSource($package, LocalesList::ENGLISH);
37 14
        $locales = $this->pathLocales($package);
38
39 14
        if (Directory::doesntExist($source) || Directory::doesntExist($locales)) {
40 2
            throw new PackageDoesntExistsException($package);
41
        }
42 12
    }
43
}
44