Passed
Push — master ( da9e58...68290f )
by Adam
05:13
created

AppServiceProvider::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
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 50
        Validator::extend('alpha_spaces', function ($attribute, $value) {
21
            // Accept only alpha and spaces.
22
            return preg_match('/^[\pL\s]+$/u', $value);
23 50
        });
24
25 50
        Validator::extend('alpha_spaces_hyphens', function ($attribute, $value) {
26
            // Accept only alpha, spaces and hyphens.
27
            return preg_match('/^[\pL\s-]+$/u', $value);
28 50
        });
29
30 50
        Validator::extend('alpha_spaces_hyphens_apostrophes', function ($attribute, $value) {
31
            // Accept only alpha, spaces, hyphens and apostrophes.
32 6
            return preg_match('/^[\pL\s-\']+$/u', $value);
33 50
        });
34
35 50
        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 50
        });
39
40 50
        Validator::extend('alpha_spaces_hyphens_apostrophes_parentheses_slashes', function ($attribute, $value) {
41
            // Accept only alpha, spaces, hyphens, apostrophes, parentheses and slashes.
42
            return preg_match('/^[\pL\s-\'()\/]+$/u', $value);
43 50
        });
44
45 50
        Validator::extend('alpha_spaces_hyphens_apostrophes_parentheses_slashes_dots', function ($attribute, $value) {
46
            // Accept only alpha, spaces, hyphens, apostrophes, parentheses, slashes and dots.
47 6
            return preg_match('/^[\pL\s-\'()\/.]+$/u', $value);
48 50
        });
49 50
    }
50
51
    /**
52
     * Register any application services.
53
     *
54
     * @return void
55
     */
56 50
    public function register()
57
    {
58
        //
59 50
    }
60
}
61