Completed
Push — master ( 2df407...de4379 )
by Neomerx
05:05
created

Rules::sku()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 DateTime;
20
use Limoncello\Validation\Contracts\Rules\RuleInterface;
21
22
/**
23
 * @package Sample
24
 */
25
class Rules extends \Limoncello\Validation\Rules
26
{
27
    /**
28
     * @return RuleInterface
29
     */
30
    public static function sku(): RuleInterface
31
    {
32
        return static::stringToInt(new IsSkuRule());
33
    }
34
35
    /**
36
     * @param int $max
37
     *
38
     * @return RuleInterface
39
     */
40
    public static function amount(int $max): RuleInterface
41
    {
42
        assert ($max > 0);
43
44
        return static::stringToInt(static::between(1, $max));
45
    }
46
47
    /**
48
     * @return RuleInterface
49
     */
50
    public static function deliveryDate(): RuleInterface
51
    {
52
        return static::stringToDateTime(DateTime::ISO8601, new IsDeliveryDateRule());
53
    }
54
55
    /**
56
     * @return RuleInterface
57
     */
58
    public static function email(): RuleInterface
59
    {
60
        return static::isString(
61
            static::filter(FILTER_VALIDATE_EMAIL, null, Errors::IS_EMAIL, static::stringLengthMax(255))
62
        );
63
    }
64
65
    /**
66
     * @return RuleInterface
67
     */
68
    public static function address1(): RuleInterface
69
    {
70
        return static::isString(static::stringLengthBetween(1, 255));
71
    }
72
73
    /**
74
     * @return RuleInterface
75
     */
76
    public static function address2(): RuleInterface
77
    {
78
        return static::nullable(static::isString(static::stringLengthMax(255)));
79
    }
80
81
    /**
82
     * @return RuleInterface
83
     */
84
    public static function areTermsAccepted(): RuleInterface
85
    {
86
        return static::stringToBool(static::equals(true));
87
    }
88
}
89