ServiceController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 37
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSynchronize() 0 25 4
A __construct() 0 5 1
1
<?php namespace Distilleries\Expendable\Http\Controllers\Backend;
2
3
use Distilleries\Expendable\Contracts\LayoutManagerContract;
4
use Distilleries\Expendable\Http\Datatables\Service\ServiceDatatable;
5
use Distilleries\Expendable\Http\Forms\Service\ServiceForm;
6
use Distilleries\Expendable\Http\Controllers\Backend\Base\BaseComponent;
7
use Distilleries\Expendable\Models\Service;
8
use Illuminate\Contracts\Routing\Registrar;
9
10
class ServiceController extends BaseComponent {
11
12 16
    public function __construct(ServiceDatatable $datatable, ServiceForm $form, Service $model, LayoutManagerContract $layoutManager)
13
    {
14 16
        parent::__construct($model, $layoutManager);
15 16
        $this->datatable = $datatable;
16 16
        $this->form      = $form;
17
    }
18
19
20
    // ------------------------------------------------------------------------------------------------
21
22 2
    public function getSynchronize(Registrar $router)
23
    {
24
25 2
        $routes = $router->getRoutes();
26
27 2
        foreach ($routes->getRoutes() as $controller)
28
        {
29 2
            $actions = $controller->getAction();
30
31 2
            if (!empty($actions['controller'])) {
32 2
                $service       = $actions['controller'];
33 2
                $serviceObject = $this->model->getByAction($service);
34
35 2
                if ($serviceObject->isEmpty())
36
                {
37 2
                    $model         = new $this->model;
38 2
                    $model->action = $service;
39 2
                    $model->save();
40
                }
41
            }
42
43
44
        }
45
46 2
        return redirect()->back();
47
    }
48
}