Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
7 / 7 |
Factory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
7 / 7 |
handle | |
100.00% |
1 / 1 |
3 | |
100.00% |
7 / 7 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\FileGenerator\Services\FileGenerator; |
4 | |
5 | use Illuminate\Support\Str; |
6 | use Qmp\Laravel\FileGenerator\Config; |
7 | use Qmp\Laravel\FileGenerator\Services\FileGenerator\Exceptions\GeneratorNotExistException; |
8 | use Qmp\Laravel\FileGenerator\Services\FileGenerator\Generators\GeneratorInterface; |
9 | |
10 | class Factory |
11 | { |
12 | const PREFIX_NAMESPACE = 'Qmp\\Laravel\\FileGenerator\\Services\\FileGenerator\\Generators\\'; |
13 | |
14 | /** |
15 | * @param \Qmp\Laravel\FileGenerator\Config $config |
16 | * @return \Qmp\Laravel\FileGenerator\Services\FileGenerator\Generators\GeneratorInterface |
17 | * @throws \Qmp\Laravel\FileGenerator\Services\FileGenerator\Exceptions\GeneratorNotExistException |
18 | */ |
19 | static function handle(Config $config): GeneratorInterface |
20 | { |
21 | if(class_exists(self::PREFIX_NAMESPACE . ucfirst(Str::camel($config->type)) . 'Generator')) { |
22 | $className = self::PREFIX_NAMESPACE . ucfirst(Str::camel($config->type)) . 'Generator'; |
23 | return new $className($config); |
24 | } |
25 | |
26 | if(class_exists(self::PREFIX_NAMESPACE . 'Google' . ucfirst($config->type) . 'Generator')) { |
27 | $className = self::PREFIX_NAMESPACE . 'Google' . ucfirst($config->type) . 'Generator'; |
28 | return new $className($config); |
29 | } |
30 | |
31 | throw new GeneratorNotExistException($config->type); |
32 | } |
33 | } |