PendingMultiStepRegister::name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Infinitypaul\MultiStep\Routing;
4
5
use Illuminate\Support\Facades\Route;
6
use Infinitypaul\MultiStep\Controller\MultiStepRedirectController;
7
8
class PendingMultiStepRegister
9
{
10
    protected $uri;
11
    protected $controller;
12
    protected $steps;
13
    protected $name;
14
    protected $only = [];
15
    protected $naming = [];
16
17
    /**
18
     * PendingMultiStepRegister constructor.
19
     *
20
     * @param $uri
21
     * @param $controller
22
     */
23
    public function __construct($uri, $controller)
24
    {
25
        $this->uri = $uri;
26
        $this->controller = $controller;
27
    }
28
29
    /**
30
     * @param $steps
31
     *
32
     * @return $this
33
     */
34
    public function steps($steps)
35
    {
36
        $this->steps = $steps;
37
38
        return $this;
39
    }
40
41
    public function name($name)
42
    {
43
        $this->name = $name;
44
45
        return $this;
46
    }
47
48
    /**
49
     * @param $only
50
     *
51
     * @return $this
52
     */
53
    public function only($only)
54
    {
55
        $this->only = $only;
56
57
        return $this;
58
    }
59
60
    public function __destruct()
61
    {
62
        Route::get($this->uri, '\\'.MultiStepRedirectController::class);
63
        collect()->times($this->steps, function ($step) {
64
            foreach ($this->only as $namespace) {
65
                $this->naming[$namespace] = "{$this->name}.{$step}.{$namespace}";
66
            }
67
            Route::group([
68
                'prefix' => $this->uri,
69
            ], function () use ($step) {
70
                Route::resource($step, "{$this->controller}Step{$step}")
71
               ->only($this->only)
72
               ->names($this->naming);
73
            });
74
        });
75
    }
76
}
77