Completed
Push — master ( 188ffb...31684b )
by Maxime
02:48
created

ServiceController::getSynchronize()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.5806
cc 4
eloc 12
nc 4
nop 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
    public function __construct(ServiceDatatable $datatable, ServiceForm $form, Service $model, LayoutManagerContract $layoutManager)
13
    {
14
        parent::__construct($model, $layoutManager);
15
        $this->datatable = $datatable;
16
        $this->form      = $form;
17
    }
18
19
20
    // ------------------------------------------------------------------------------------------------
21
22
    public function getSynchronize(Registrar $router)
23
    {
24
25
        $routes = $router->getRoutes();
26
27
        foreach ($routes->getRoutes() as $controller)
28
        {
29
            $actions = $controller->getAction();
30
31
            if (!empty($actions['controller'])) {
32
                $service       = $actions['controller'];
33
                $serviceObject = $this->model->getByAction($service);
0 ignored issues
show
Documentation Bug introduced by
The method getByAction does not exist on object<Distilleries\Expendable\Models\BaseModel>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
34
35
                if ($serviceObject->isEmpty())
36
                {
37
                    $model         = new $this->model;
38
                    $model->action = $service;
39
                    $model->save();
40
                }
41
            }
42
43
44
        }
45
46
        return redirect()->back();
47
    }
48
}