Passed
Push — master ( a7279d...feb425 )
by Andrey
11:45
created

Localization::copied()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services;
4
5
use Helldar\LaravelLangPublisher\Contracts\Localization as LocalizationContract;
6
use Helldar\LaravelLangPublisher\Contracts\Process;
7
use Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException;
8
use Helldar\LaravelLangPublisher\Services\Processing\Delete;
9
use Helldar\LaravelLangPublisher\Services\Processing\Publish;
10
11
use function app;
12
13
final class Localization implements LocalizationContract
14
{
15
    /** @var array */
16
    protected $result = [];
17
18
    /**
19
     * @param string $locale
20
     * @param bool $force
21
     *
22
     * @return array
23
     * @throws \Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException
24
     */
25
    public function publish(string $locale, bool $force = false): array
26
    {
27
        return $this->process(Publish::class, $locale, $force);
28
    }
29
30
    /**
31
     * @param string $locale
32
     *
33
     * @return array
34
     * @throws \Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException
35
     */
36
    public function delete(string $locale): array
37
    {
38
        return $this->process(Delete::class, $locale);
39
    }
40
41
    /**
42
     * @param string $classname
43
     * @param string $locale
44
     * @param bool $force
45
     *
46
     * @return mixed
47
     * @throws \Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException
48
     */
49
    protected function process(string $classname, string $locale, bool $force = false)
50
    {
51
        return $this->makeProcess($classname)
52
            ->locale($locale)
53
            ->force($force)
54
            ->run();
55
    }
56
57
    /**
58
     * @param string $classname
59
     *
60
     * @return \Helldar\LaravelLangPublisher\Contracts\Process
61
     * @throws \Helldar\LaravelLangPublisher\Exceptions\NoProcessInstanceException
62
     */
63
    protected function makeProcess(string $classname): Process
64
    {
65
        if (! is_subclass_of($classname, Process::class)) {
66
            throw new NoProcessInstanceException($classname);
67
        }
68
69
        return app($classname);
0 ignored issues
show
Bug Best Practice introduced by
The expression return app($classname) could return the type Illuminate\Contracts\Foundation\Application which is incompatible with the type-hinted return Helldar\LaravelLangPublisher\Contracts\Process. Consider adding an additional type-check to rule them out.
Loading history...
70
    }
71
}
72