IndexPage   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 21
dl 0
loc 45
rs 10
c 1
b 0
f 1
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A render() 0 3 1
B makeDynamicClass() 0 11 7
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