Completed
Push — master ( 22fd50...798002 )
by Neomerx
03:53
created

CustomRules   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isRequiredString() 0 4 1
A isNullOrNonEmptyString() 0 4 1
A isEmail() 0 4 1
A isExistingPaymentPlan() 0 4 1
1
<?php namespace Sample\Validation;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Validation\Contracts\Rules\RuleInterface;
20
use Limoncello\Validation\Rules;
21
22
/**
23
 * @package Sample
24
 */
25
class CustomRules extends Rules
26
{
27
    /**
28
     * @param int $maxLength
29
     *
30
     * @return RuleInterface
31
     */
32
    public static function isRequiredString(int $maxLength): RuleInterface
33
    {
34
        return static::required(static::isString(static::stringLengthMax($maxLength)));
35
    }
36
37
    /**
38
     * @param int $maxLength
39
     *
40
     * @return RuleInterface
41
     */
42
    public static function isNullOrNonEmptyString(int $maxLength): RuleInterface
43
    {
44
        return static::nullable(static::isString(static::stringLengthBetween(1, $maxLength)));
45
    }
46
47
    /**
48
     * @return RuleInterface
49
     */
50
    public static function isEmail(): RuleInterface
51
    {
52
        return new IsEmailRule();
53
    }
54
55
    /**
56
     * @return RuleInterface
57
     */
58
    public static function isExistingPaymentPlan(): RuleInterface
59
    {
60
        return static::stringToInt(new IsPaymentPlanRule());
61
    }
62
}
63