ApiJwtScaffold::setup()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Lacasera\ApiJwtScaffold;
4
5
class ApiJwtScaffold
6
{
7
8
    /**
9
     * @param string $packageToUse
10
     * @return mixed
11
     * @throws \Exception
12
     */
13
    public function setup(string $packageToUse)
14
    {
15
        return app()->make($this->getPackageClass($packageToUse))
16
            ->scaffold();
17
    }
18
19
    /**
20
     * @param string $packageToUse
21
     * @return string
22
     * @throws \Exception
23
     */
24
    public function getPackageClass(string $packageToUse)
25
    {
26
        $packageName = $this->getInstallerClassName($packageToUse);
27
28
        $installerClass = "Lacasera\\ApiJwtScaffold\Installers\\{$packageName}Installer";
29
30
        if (!class_exists($installerClass)) {
31
            throw new \Exception("$installerClass does not exist");
32
        }
33
34
        return $installerClass;
35
    }
36
37
    /**
38
     * @param string $package
39
     * @return mixed
40
     */
41
    private function getInstallerClassName(string $package)
42
    {
43
        $packageName = ucwords(str_replace(['-', '_'], ' ', $package));
44
45
        return str_replace(' ', '', $packageName);
46
    }
47
}
48