CollectionAttribute   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 113
rs 10
c 2
b 1
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A each() 0 6 1
A hasKeyFormat() 0 6 1
A endsWith() 0 6 1
A contains() 0 6 1
A hasKey() 0 6 1
A hasLength() 0 6 1
A isNotEmpty() 0 6 1
A startsWith() 0 6 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 9/16/14
5
 * Time: 9:16 PM
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Validator\Attribute\Collection;
12
13
use NilPortugues\Validator\AbstractValidator;
14
use NilPortugues\Validator\Validator;
15
16
/**
17
 * Class CollectionAttribute
18
 * @package NilPortugues\Validator\Attribute\CollectionAttribute
19
 */
20
class CollectionAttribute extends AbstractValidator
21
{
22
    /**
23
     * @param string    $propertyName
24
     * @param Validator $validator
25
     * @param array     $errorMessages
26
     * @param array     $functionMap
27
     */
28
    public function __construct($propertyName, Validator $validator, array &$errorMessages, array &$functionMap)
29
    {
30
        parent::__construct($propertyName, $validator, $errorMessages, $functionMap);
31
32
        $this->addCondition(__METHOD__);
33
    }
34
35
    /**
36
     * @param \NilPortugues\Validator\AbstractValidator $valueValidator
37
     * @param \NilPortugues\Validator\AbstractValidator $keyValidator
38
     *
39
     * @return $this
40
     */
41
    public function each(AbstractValidator $valueValidator, AbstractValidator $keyValidator = null)
42
    {
43
        $this->addCondition(__METHOD__, [$valueValidator, $keyValidator], [], true);
44
45
        return $this;
46
    }
47
48
    /**
49
     * @param \NilPortugues\Validator\AbstractValidator $keyValidator
50
     *
51
     * @return $this
52
     */
53
    public function hasKeyFormat(AbstractValidator $keyValidator)
54
    {
55
        $this->addCondition(__METHOD__, [$keyValidator], [], true);
56
57
        return $this;
58
    }
59
60
    /**
61
     * @param mixed $needle
62
     * @param bool  $strict
63
     *
64
     * @return $this
65
     */
66
    public function endsWith($needle, $strict = false)
67
    {
68
        $this->addCondition(__METHOD__, [$needle, $strict]);
69
70
        return $this;
71
    }
72
73
    /**
74
     * @param mixed $needle
75
     * @param bool  $strict
76
     *
77
     * @return $this
78
     */
79
    public function contains($needle, $strict = false)
80
    {
81
        $this->addCondition(__METHOD__, [$needle, $strict]);
82
83
        return $this;
84
    }
85
86
    /**
87
     * @param $keyName
88
     *
89
     * @return $this
90
     */
91
    public function hasKey($keyName)
92
    {
93
        $this->addCondition(__METHOD__, [$keyName]);
94
95
        return $this;
96
    }
97
98
    /**
99
     * @param integer $length
100
     *
101
     * @return $this
102
     */
103
    public function hasLength($length)
104
    {
105
        $this->addCondition(__METHOD__, [$length]);
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return $this
112
     */
113
    public function isNotEmpty()
114
    {
115
        $this->addCondition(__METHOD__);
116
117
        return $this;
118
    }
119
120
    /**
121
     * @param      $needle
122
     * @param bool $strict
123
     *
124
     * @return $this
125
     */
126
    public function startsWith($needle, $strict = false)
127
    {
128
        $this->addCondition(__METHOD__, [$needle, $strict]);
129
130
        return $this;
131
    }
132
}
133