IndexPage::makeDynamicClass()   B
last analyzed

Complexity

Conditions 7
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 7
eloc 7
nc 3
nop 1
dl 0
loc 11
rs 8.8333
c 1
b 0
f 1
1
<?php
2
3
namespace Pratiksh\Adminetic\View\Components;
4
5
use Illuminate\Support\Str;
6
use Illuminate\View\Component;
7
8
class IndexPage extends Component
9
{
10
    public $name;
11
    public $plural_name;
12
    public $property;
13
    public $route;
14
    public $class;
15
    public $icon;
16
17
    /**
18
     * Create a new component instance.
19
     *
20
     * @return void
21
     */
22
    public function __construct($name, $route, $property = '', $icon = null)
23
    {
24
        $this->name = Str::ucfirst($name);
25
        $this->plural_name = Str::plural(Str::ucfirst($name));
26
        $this->property = $property;
27
        $this->route = $route ?? Str::plural($name);
28
        $this->class = $this->makeDynamicClass($this->name);
29
        $this->icon = $icon;
30
    }
31
32
    /**
33
     * Get the view / contents that represent the component.
34
     *
35
     * @return \Illuminate\Contracts\View\View|string
36
     */
37
    public function render()
38
    {
39
        return view('adminetic::components.index-page');
40
    }
41
42
    protected function makeDynamicClass($name)
43
    {
44
        if ($name == 'User') {
45
            $className = 'App\\Models\\'.Str::ucfirst($name);
46
        } elseif ($name == 'Permission' || $name == 'Preference' || $name == 'Profile' || $name == 'Role' || $name == 'Setting') {
47
            $className = 'Pratiksh\\Adminetic\\Models\\Admin\\'.Str::ucfirst($name);
48
        } else {
49
            $className = 'App\\Models\\Admin\\'.Str::ucfirst($name);
50
        }
51
52
        return new  $className;
53
    }
54
}
55