Passed
Push — master ( 2ac40d...533e17 )
by Adam
07:04
created

AppServiceProvider::boot()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1.0028

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 28
ccs 12
cts 14
cp 0.8571
crap 1.0028
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Support\Facades\Validator;
6
use Illuminate\Support\ServiceProvider;
7
8
class AppServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap any application services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        /*
18
         * Custom validation rules
19
         */
20 41
        Validator::extend('alpha_spaces', function ($attribute, $value) {
21
            // Accept only alpha and spaces.
22 5
            return preg_match('/^[\pL\s]+$/u', $value);
23 41
        });
24
25 41
        Validator::extend('alpha_spaces_hyphens', function ($attribute, $value) {
26
            // Accept only alpha, spaces and hyphens.
27
            return preg_match('/^[\pL\s-]+$/u', $value);
28 41
        });
29
30 41
        Validator::extend('alpha_spaces_hyphens_apostrophes', function ($attribute, $value) {
31
            // Accept only alpha, spaces, hyphens and apostrophes.
32 5
            return preg_match('/^[\pL\s-\']+$/u', $value);
33 41
        });
34
35 41
        Validator::extend('alpha_spaces_hyphens_apostrophes_parentheses', function ($attribute, $value) {
36
            // Accept only alpha, spaces, hyphens, apostrophes and parentheses.
37
            return preg_match('/^[\pL\s-\'()]+$/u', $value);
38 41
        });
39
40 41
        Validator::extend('alpha_spaces_hyphens_apostrophes_parentheses_slashes', function ($attribute, $value) {
41
            // Accept only alpha, spaces, hyphens, apostrophes, parentheses and slashes.
42 5
            return preg_match('/^[\pL\s-\'()\/]+$/u', $value);
43 41
;        });
44 41
    }
45
46
    /**
47
     * Register any application services.
48
     *
49
     * @return void
50
     */
51 41
    public function register()
52
    {
53
        //
54 41
    }
55
}
56