HandlesRedirects   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 64
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRedirectUrl() 0 14 4
A setRedirector() 0 6 1
1
<?php
2
3
namespace PerfectOblivion\Valid\ValidationService\Concerns;
4
5
use Illuminate\Routing\Redirector;
6
7
trait HandlesRedirects
8
{
9
    /**
10
     * The redirector instance.
11
     *
12
     * @var \Illuminate\Routing\Redirector
13
     */
14
    protected $redirector;
15
16
    /**
17
     * The URI to redirect to if validation fails.
18
     *
19
     * @var string
20
     */
21
    protected $redirect;
22
23
    /**
24
     * The route to redirect to if validation fails.
25
     *
26
     * @var string
27
     */
28
    protected $redirectRoute;
29
30
    /**
31
     * The controller action to redirect to if validation fails.
32
     *
33
     * @var string
34
     */
35
    protected $redirectAction;
36
37
    /**
38
     * Get the URL to redirect to on a validation error.
39
     *
40
     * @return string
41
     */
42
    protected function getRedirectUrl()
43
    {
44
        $url = $this->redirector->getUrlGenerator();
45
46
        if ($this->redirect) {
47
            return $url->to($this->redirect);
48
        } elseif ($this->redirectRoute) {
49
            return $url->route($this->redirectRoute);
50
        } elseif ($this->redirectAction) {
51
            return $url->action($this->redirectAction);
52
        }
53
54
        return $url->previous();
55
    }
56
57
    /**
58
     * Set the Redirector instance.
59
     *
60
     * @param  \Illuminate\Routing\Redirector  $redirector
61
     *
62
     * @return $this
63
     */
64
    public function setRedirector(Redirector $redirector)
65
    {
66
        $this->redirector = $redirector;
67
68
        return $this;
69
    }
70
}
71