Issues (158)

app/Rules/StartsWithUo.php (1 issue)

1
<?php
2
3
namespace App\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class StartsWithUo implements Rule
8
{
9
    /**
10
     * Create a new rule instance.
11
     *
12
     * @return void
13
     */
14
    public function __construct()
15
    {
16
        //
17
    }
18
19
    /**
20
     * Determine if the validation rule passes.
21
     *
22
     * @param  string  $attribute
23
     * @param  mixed  $value
24
     * @return bool
25
     */
26
    public function passes($attribute, $value)
27
    {
28
        if (!isset($this->data['thing']) || ($this->data['thing'] != '1')) {  // Ikke bibsys-dok:
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist on App\Rules\StartsWithUo. Did you maybe forget to declare it?
Loading history...
29
            return true;
30
        }
31
        if (!preg_match('/[0-9]/', $value)) { // Inneholder ikke tall: antakelig et navn
32
            return true;
33
        }
34
        return substr($value, 0, 2) == 'uo';
35
    }
36
37
    /**
38
     * Get the validation error message.
39
     *
40
     * @return string
41
     */
42
    public function message()
43
    {
44
        return 'Card number must start with "uo".';
45
    }
46
}
47