Completed
Push — master ( 592d95...c00565 )
by Abdelrahman
18:11 queued 10s
created

RedirectRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A passes() 0 12 3
A message() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Oauth\Http\Rules;
6
7
use Illuminate\Contracts\Validation\Rule;
8
use Illuminate\Contracts\Validation\Factory;
9
10
class RedirectRule implements Rule
11
{
12
    /**
13
     * The validator instance.
14
     *
15
     * @var \Illuminate\Contracts\Validation\Factory
16
     */
17
    protected $validator;
18
19
    /**
20
     * Create a new rule instance.
21
     *
22
     * @param \Illuminate\Contracts\Validation\Factory $validator
23
     *
24
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
25
     */
26
    public function __construct(Factory $validator)
27
    {
28
        $this->validator = $validator;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function passes($attribute, $value)
35
    {
36
        foreach (explode(',', $value) as $redirect) {
37
            $validator = $this->validator->make(['redirect' => $redirect], ['redirect' => 'url']);
38
39
            if ($validator->fails()) {
40
                return false;
41
            }
42
        }
43
44
        return true;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function message()
51
    {
52
        return 'One or more redirects have an invalid url format.';
53
    }
54
}
55