Passed
Branch dev (33fe06)
by Alan
10:25
created
src/Rule.php 1 patch
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -7,184 +7,184 @@
 block discarded – undo
7 7
 
8 8
 class Rule implements RuleInterface
9 9
 {
10
-	public function __construct(protected int $filterType, protected int $flags = 0, protected array $options = [], protected ?Closure $callback = null)
11
-	{
12
-		//
13
-	}
14
-
15
-	/**
16
-	 * Get the Rule filter type.
17
-	 *
18
-	 * @return integer
19
-	 */
20
-	public function getFilterType(): int
21
-	{
22
-		return $this->filterType;
23
-	}
24
-
25
-	/**
26
-	 * Get the Rule flags.
27
-	 *
28
-	 * @return integer
29
-	 */
30
-	public function getFlags(): int
31
-	{
32
-		return $this->flags;
33
-	}
34
-
35
-	/**
36
-	 * Check if a Rule flag is set.
37
-	 *
38
-	 * @param integer $flag
39
-	 *
40
-	 * @return boolean
41
-	 */
42
-	public function hasFlag(int $flag): bool
43
-	{
44
-		return $this->flags & $flag;
45
-	}
46
-
47
-	/**
48
-	 * Add a Rule flag.
49
-	 *
50
-	 * @param integer $flag
51
-	 *
52
-	 * @return $this
53
-	 */
54
-	public function addFlag(int $flag): RuleInterface
55
-	{
56
-		$this->flags |= $flag;
57
-
58
-		return $this;
59
-	}
60
-
61
-	/**
62
-	 * Remove a Rule flag.
63
-	 *
64
-	 * @param integer $flag
65
-	 *
66
-	 * @return $this
67
-	 */
68
-	public function removeFlag(int $flag): RuleInterface
69
-	{
70
-		$this->flags &= $flag;
71
-
72
-		return $this;
73
-	}
74
-
75
-	/**
76
-	 * Get the Rule options.
77
-	 *
78
-	 * @return array
79
-	 */
80
-	public function getOptions(): array
81
-	{
82
-		return $this->options;
83
-	}
84
-
85
-	/**
86
-	 * Check if a given Rule option exists.
87
-	 *
88
-	 * @param string $name
89
-	 *
90
-	 * @return boolean
91
-	 */
92
-	public function hasOption(string $name): bool
93
-	{
94
-		return key_exists($name, $this->options);
95
-	}
96
-
97
-	/**
98
-	 * Get the value of a given Rule option.
99
-	 *
100
-	 * @param string $name
101
-	 * @param mixed $default
102
-	 *
103
-	 * @return mixed
104
-	 */
105
-	public function getOption(string $name, $default = null)
106
-	{
107
-		return $this->options[$name] ?? $default;
108
-	}
109
-
110
-	/**
111
-	 * Set the value of a given Rule option.
112
-	 *
113
-	 * @param string $name
114
-	 * @param mixed $value
115
-	 *
116
-	 * @return $this
117
-	 */
118
-	public function setOption(string $name, $value): RuleInterface
119
-	{
120
-		$this->options[$name] = $value;
121
-
122
-		return $this;
123
-	}
124
-
125
-	/**
126
-	 * Remove the given option from the Rule.
127
-	 *
128
-	 * @param string $name
129
-	 *
130
-	 * @return $this
131
-	 */
132
-	public function removeOption(string $name): RuleInterface
133
-	{
134
-		unset($this->options[$name]);
135
-
136
-		return $this;
137
-	}
138
-
139
-	/**
140
-	 * Get the Rule callback.
141
-	 *
142
-	 * @return \Closure|null
143
-	 */
144
-	public function getCallback(): ?Closure
145
-	{
146
-		return $this->callback;
147
-	}
148
-
149
-	/**
150
-	 * Get the Rule callback.
151
-	 *
152
-	 * @param \Closure|null $callback
153
-	 *
154
-	 * @return $this
155
-	 */
156
-	public function setCallback(?Closure $callback): RuleInterface
157
-	{
158
-		$this->callback = $callback;
159
-
160
-		return $this;
161
-	}
162
-
163
-	/**
164
-	 * Cast the Rule into an array.
165
-	 *
166
-	 * @return array
167
-	 */
168
-	public function toArray(): array
169
-	{
170
-		$flags = $this->getFlags();
171
-		$options = $this->getOptions();
172
-		$callback = $this->getCallback();
173
-
174
-		$array = [
175
-			'filter' => $this->getFilterType(),
176
-		];
177
-
178
-		if ($flags !== 0) {
179
-			$array['flags'] = $flags;
180
-		}
181
-
182
-		if (!empty($callback)) {
183
-			$array['options'] = $callback;
184
-		} elseif (!empty($options)) {
185
-			$array['options'] = $options;
186
-		}
187
-
188
-		return $array;
189
-	}
10
+    public function __construct(protected int $filterType, protected int $flags = 0, protected array $options = [], protected ?Closure $callback = null)
11
+    {
12
+        //
13
+    }
14
+
15
+    /**
16
+     * Get the Rule filter type.
17
+     *
18
+     * @return integer
19
+     */
20
+    public function getFilterType(): int
21
+    {
22
+        return $this->filterType;
23
+    }
24
+
25
+    /**
26
+     * Get the Rule flags.
27
+     *
28
+     * @return integer
29
+     */
30
+    public function getFlags(): int
31
+    {
32
+        return $this->flags;
33
+    }
34
+
35
+    /**
36
+     * Check if a Rule flag is set.
37
+     *
38
+     * @param integer $flag
39
+     *
40
+     * @return boolean
41
+     */
42
+    public function hasFlag(int $flag): bool
43
+    {
44
+        return $this->flags & $flag;
45
+    }
46
+
47
+    /**
48
+     * Add a Rule flag.
49
+     *
50
+     * @param integer $flag
51
+     *
52
+     * @return $this
53
+     */
54
+    public function addFlag(int $flag): RuleInterface
55
+    {
56
+        $this->flags |= $flag;
57
+
58
+        return $this;
59
+    }
60
+
61
+    /**
62
+     * Remove a Rule flag.
63
+     *
64
+     * @param integer $flag
65
+     *
66
+     * @return $this
67
+     */
68
+    public function removeFlag(int $flag): RuleInterface
69
+    {
70
+        $this->flags &= $flag;
71
+
72
+        return $this;
73
+    }
74
+
75
+    /**
76
+     * Get the Rule options.
77
+     *
78
+     * @return array
79
+     */
80
+    public function getOptions(): array
81
+    {
82
+        return $this->options;
83
+    }
84
+
85
+    /**
86
+     * Check if a given Rule option exists.
87
+     *
88
+     * @param string $name
89
+     *
90
+     * @return boolean
91
+     */
92
+    public function hasOption(string $name): bool
93
+    {
94
+        return key_exists($name, $this->options);
95
+    }
96
+
97
+    /**
98
+     * Get the value of a given Rule option.
99
+     *
100
+     * @param string $name
101
+     * @param mixed $default
102
+     *
103
+     * @return mixed
104
+     */
105
+    public function getOption(string $name, $default = null)
106
+    {
107
+        return $this->options[$name] ?? $default;
108
+    }
109
+
110
+    /**
111
+     * Set the value of a given Rule option.
112
+     *
113
+     * @param string $name
114
+     * @param mixed $value
115
+     *
116
+     * @return $this
117
+     */
118
+    public function setOption(string $name, $value): RuleInterface
119
+    {
120
+        $this->options[$name] = $value;
121
+
122
+        return $this;
123
+    }
124
+
125
+    /**
126
+     * Remove the given option from the Rule.
127
+     *
128
+     * @param string $name
129
+     *
130
+     * @return $this
131
+     */
132
+    public function removeOption(string $name): RuleInterface
133
+    {
134
+        unset($this->options[$name]);
135
+
136
+        return $this;
137
+    }
138
+
139
+    /**
140
+     * Get the Rule callback.
141
+     *
142
+     * @return \Closure|null
143
+     */
144
+    public function getCallback(): ?Closure
145
+    {
146
+        return $this->callback;
147
+    }
148
+
149
+    /**
150
+     * Get the Rule callback.
151
+     *
152
+     * @param \Closure|null $callback
153
+     *
154
+     * @return $this
155
+     */
156
+    public function setCallback(?Closure $callback): RuleInterface
157
+    {
158
+        $this->callback = $callback;
159
+
160
+        return $this;
161
+    }
162
+
163
+    /**
164
+     * Cast the Rule into an array.
165
+     *
166
+     * @return array
167
+     */
168
+    public function toArray(): array
169
+    {
170
+        $flags = $this->getFlags();
171
+        $options = $this->getOptions();
172
+        $callback = $this->getCallback();
173
+
174
+        $array = [
175
+            'filter' => $this->getFilterType(),
176
+        ];
177
+
178
+        if ($flags !== 0) {
179
+            $array['flags'] = $flags;
180
+        }
181
+
182
+        if (!empty($callback)) {
183
+            $array['options'] = $callback;
184
+        } elseif (!empty($options)) {
185
+            $array['options'] = $options;
186
+        }
187
+
188
+        return $array;
189
+    }
190 190
 }
Please login to merge, or discard this patch.
src/AbstractFilter.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -3,124 +3,124 @@
 block discarded – undo
3 3
 namespace FigTree\Validation;
4 4
 
5 5
 use FigTree\Validation\Contracts\{
6
-	FilterInterface,
7
-	RuleFactoryInterface,
8
-	RuleInterface
6
+    FilterInterface,
7
+    RuleFactoryInterface,
8
+    RuleInterface
9 9
 };
10 10
 
11 11
 abstract class AbstractFilter implements FilterInterface
12 12
 {
13
-	protected RuleFactoryInterface $ruleFactory;
14
-
15
-	/**
16
-	 * Set or remove a RuleFactory.
17
-	 *
18
-	 * @param \FigTree\Validation\Contracts\RuleFactoryInterface $ruleFactory
19
-	 *
20
-	 * @return $this
21
-	 */
22
-	public function setRuleFactory(RuleFactoryInterface $ruleFactory): FilterInterface
23
-	{
24
-		$this->ruleFactory = $ruleFactory;
25
-
26
-		return $this;
27
-	}
28
-
29
-	/**
30
-	 * Filter a single value against the Filter.
31
-	 *
32
-	 * @param string $field
33
-	 * @param mixed $value
34
-	 *
35
-	 * @return mixed
36
-	 */
37
-	public function filterValue(string $field, mixed $value, $default = null): mixed
38
-	{
39
-		$definition = $this->getDefinition($field);
40
-
41
-		if (empty($definition)) {
42
-			return $default;
43
-		}
44
-
45
-		$filter = $definition['filter'] ?? null;
46
-
47
-		return filter_var($value, $filter, $definition);
48
-	}
49
-
50
-	/**
51
-	 * Filter a single input field against the Filter.
52
-	 *
53
-	 * @param integer $type
54
-	 * @param string $field
55
-	 *
56
-	 * @return mixed
57
-	 */
58
-	public function filterInput(int $type, string $field, $default = null): mixed
59
-	{
60
-		$definition = $this->getDefinition($field);
61
-
62
-		if (empty($definition)) {
63
-			return $default;
64
-		}
65
-
66
-		$filter = $definition['filter'] ?? null;
67
-
68
-		return filter_input($type, $field, $filter, $definition);
69
-	}
70
-
71
-	/**
72
-	 * Filter an array of values against the Filter.
73
-	 *
74
-	 * @param array $data
75
-	 * @param boolean $addEmpty
76
-	 *
77
-	 * @return mixed
78
-	 */
79
-	public function filterArray(array $data, bool $addEmpty = true): array
80
-	{
81
-		return filter_var_array($data, $this->getDefinitions(), $addEmpty);
82
-	}
83
-
84
-	/**
85
-	 * Filter an array of input values against the Filter.
86
-	 *
87
-	 * @param integer $type
88
-	 * @param boolean $addEmpty
89
-	 *
90
-	 * @return mixed
91
-	 */
92
-	public function filterInputArray(int $type, bool $addEmpty = true): array
93
-	{
94
-		return filter_input_array($type, $this->getDefinitions(), $addEmpty);
95
-	}
96
-
97
-	/**
98
-	 * Get a single Rule as a native filter definition.
99
-	 *
100
-	 * @param string $field
101
-	 *
102
-	 * @return array|null
103
-	 */
104
-	protected function getDefinition(string $field): ?array
105
-	{
106
-		$rules = $this->getRules();
107
-
108
-		$rule = $rules[$field] ?? null;
109
-
110
-		if (!($rule instanceof RuleInterface)) {
111
-			return null;
112
-		}
113
-
114
-		return $rule->toArray();
115
-	}
116
-
117
-	/**
118
-	 * Get the Rules as a native filter definition.
119
-	 *
120
-	 * @return array
121
-	 */
122
-	protected function getDefinitions(): array
123
-	{
124
-		return array_map(fn (RuleInterface $rule) => $rule->toArray(), $this->getRules());
125
-	}
13
+    protected RuleFactoryInterface $ruleFactory;
14
+
15
+    /**
16
+     * Set or remove a RuleFactory.
17
+     *
18
+     * @param \FigTree\Validation\Contracts\RuleFactoryInterface $ruleFactory
19
+     *
20
+     * @return $this
21
+     */
22
+    public function setRuleFactory(RuleFactoryInterface $ruleFactory): FilterInterface
23
+    {
24
+        $this->ruleFactory = $ruleFactory;
25
+
26
+        return $this;
27
+    }
28
+
29
+    /**
30
+     * Filter a single value against the Filter.
31
+     *
32
+     * @param string $field
33
+     * @param mixed $value
34
+     *
35
+     * @return mixed
36
+     */
37
+    public function filterValue(string $field, mixed $value, $default = null): mixed
38
+    {
39
+        $definition = $this->getDefinition($field);
40
+
41
+        if (empty($definition)) {
42
+            return $default;
43
+        }
44
+
45
+        $filter = $definition['filter'] ?? null;
46
+
47
+        return filter_var($value, $filter, $definition);
48
+    }
49
+
50
+    /**
51
+     * Filter a single input field against the Filter.
52
+     *
53
+     * @param integer $type
54
+     * @param string $field
55
+     *
56
+     * @return mixed
57
+     */
58
+    public function filterInput(int $type, string $field, $default = null): mixed
59
+    {
60
+        $definition = $this->getDefinition($field);
61
+
62
+        if (empty($definition)) {
63
+            return $default;
64
+        }
65
+
66
+        $filter = $definition['filter'] ?? null;
67
+
68
+        return filter_input($type, $field, $filter, $definition);
69
+    }
70
+
71
+    /**
72
+     * Filter an array of values against the Filter.
73
+     *
74
+     * @param array $data
75
+     * @param boolean $addEmpty
76
+     *
77
+     * @return mixed
78
+     */
79
+    public function filterArray(array $data, bool $addEmpty = true): array
80
+    {
81
+        return filter_var_array($data, $this->getDefinitions(), $addEmpty);
82
+    }
83
+
84
+    /**
85
+     * Filter an array of input values against the Filter.
86
+     *
87
+     * @param integer $type
88
+     * @param boolean $addEmpty
89
+     *
90
+     * @return mixed
91
+     */
92
+    public function filterInputArray(int $type, bool $addEmpty = true): array
93
+    {
94
+        return filter_input_array($type, $this->getDefinitions(), $addEmpty);
95
+    }
96
+
97
+    /**
98
+     * Get a single Rule as a native filter definition.
99
+     *
100
+     * @param string $field
101
+     *
102
+     * @return array|null
103
+     */
104
+    protected function getDefinition(string $field): ?array
105
+    {
106
+        $rules = $this->getRules();
107
+
108
+        $rule = $rules[$field] ?? null;
109
+
110
+        if (!($rule instanceof RuleInterface)) {
111
+            return null;
112
+        }
113
+
114
+        return $rule->toArray();
115
+    }
116
+
117
+    /**
118
+     * Get the Rules as a native filter definition.
119
+     *
120
+     * @return array
121
+     */
122
+    protected function getDefinitions(): array
123
+    {
124
+        return array_map(fn (RuleInterface $rule) => $rule->toArray(), $this->getRules());
125
+    }
126 126
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,6 +121,6 @@
 block discarded – undo
121 121
 	 */
122 122
 	protected function getDefinitions(): array
123 123
 	{
124
-		return array_map(fn (RuleInterface $rule) => $rule->toArray(), $this->getRules());
124
+		return array_map(fn(RuleInterface $rule) => $rule->toArray(), $this->getRules());
125 125
 	}
126 126
 }
Please login to merge, or discard this patch.
src/Contracts/FilterInterface.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -4,61 +4,61 @@
 block discarded – undo
4 4
 
5 5
 interface FilterInterface
6 6
 {
7
-	/**
8
-	 * Set or remove a RuleFactory.
9
-	 *
10
-	 * @param \FigTree\Validation\Contracts\RuleFactoryInterface $ruleFactory
11
-	 *
12
-	 * @return \FigTree\Validation\Contracts\FilterInterface
13
-	 */
14
-	public function setRuleFactory(RuleFactoryInterface $ruleFactory): FilterInterface;
7
+    /**
8
+     * Set or remove a RuleFactory.
9
+     *
10
+     * @param \FigTree\Validation\Contracts\RuleFactoryInterface $ruleFactory
11
+     *
12
+     * @return \FigTree\Validation\Contracts\FilterInterface
13
+     */
14
+    public function setRuleFactory(RuleFactoryInterface $ruleFactory): FilterInterface;
15 15
 
16
-	/**
17
-	 * Get the set of Rules for this Filter.
18
-	 *
19
-	 * @return array
20
-	 */
21
-	public function getRules(): array;
16
+    /**
17
+     * Get the set of Rules for this Filter.
18
+     *
19
+     * @return array
20
+     */
21
+    public function getRules(): array;
22 22
 
23
-	/**
24
-	 * Filter a single value against the Filter.
25
-	 *
26
-	 * @param string $field
27
-	 * @param mixed $value
28
-	 * @param mixed $default
29
-	 *
30
-	 * @return mixed
31
-	 */
32
-	public function filterValue(string $field, mixed $value, $default = null): mixed;
23
+    /**
24
+     * Filter a single value against the Filter.
25
+     *
26
+     * @param string $field
27
+     * @param mixed $value
28
+     * @param mixed $default
29
+     *
30
+     * @return mixed
31
+     */
32
+    public function filterValue(string $field, mixed $value, $default = null): mixed;
33 33
 
34
-	/**
35
-	 * Filter a single input field against the Filter.
36
-	 *
37
-	 * @param integer $type
38
-	 * @param string $field
39
-	 * @param mixed $default
40
-	 *
41
-	 * @return mixed
42
-	 */
43
-	public function filterInput(int $type, string $field, $default = null): mixed;
34
+    /**
35
+     * Filter a single input field against the Filter.
36
+     *
37
+     * @param integer $type
38
+     * @param string $field
39
+     * @param mixed $default
40
+     *
41
+     * @return mixed
42
+     */
43
+    public function filterInput(int $type, string $field, $default = null): mixed;
44 44
 
45
-	/**
46
-	 * Filter an array of values against the Filter.
47
-	 *
48
-	 * @param array $data
49
-	 * @param boolean $addEmpty
50
-	 *
51
-	 * @return mixed
52
-	 */
53
-	public function filterArray(array $data, bool $addEmpty = true): array;
45
+    /**
46
+     * Filter an array of values against the Filter.
47
+     *
48
+     * @param array $data
49
+     * @param boolean $addEmpty
50
+     *
51
+     * @return mixed
52
+     */
53
+    public function filterArray(array $data, bool $addEmpty = true): array;
54 54
 
55
-	/**
56
-	 * Filter an array of input values against the Filter.
57
-	 *
58
-	 * @param integer $type
59
-	 * @param boolean $addEmpty
60
-	 *
61
-	 * @return mixed
62
-	 */
63
-	public function filterInputArray(int $type, bool $addEmpty = true): array;
55
+    /**
56
+     * Filter an array of input values against the Filter.
57
+     *
58
+     * @param integer $type
59
+     * @param boolean $addEmpty
60
+     *
61
+     * @return mixed
62
+     */
63
+    public function filterInputArray(int $type, bool $addEmpty = true): array;
64 64
 }
Please login to merge, or discard this patch.
src/Contracts/RuleInterface.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -6,112 +6,112 @@
 block discarded – undo
6 6
 
7 7
 interface RuleInterface
8 8
 {
9
-	/**
10
-	 * Get the Rule filter type.
11
-	 *
12
-	 * @return integer
13
-	 */
14
-	public function getFilterType(): int;
9
+    /**
10
+     * Get the Rule filter type.
11
+     *
12
+     * @return integer
13
+     */
14
+    public function getFilterType(): int;
15 15
 
16
-	/**
17
-	 * Get the Rule flags.
18
-	 *
19
-	 * @return integer
20
-	 */
21
-	public function getFlags(): int;
16
+    /**
17
+     * Get the Rule flags.
18
+     *
19
+     * @return integer
20
+     */
21
+    public function getFlags(): int;
22 22
 
23
-	/**
24
-	 * Check if a Rule flag is set.
25
-	 *
26
-	 * @param integer $flag
27
-	 *
28
-	 * @return boolean
29
-	 */
30
-	public function hasFlag(int $flag): bool;
23
+    /**
24
+     * Check if a Rule flag is set.
25
+     *
26
+     * @param integer $flag
27
+     *
28
+     * @return boolean
29
+     */
30
+    public function hasFlag(int $flag): bool;
31 31
 
32
-	/**
33
-	 * Add a Rule flag.
34
-	 *
35
-	 * @param integer $flag
36
-	 *
37
-	 * @return \FigTree\Validation\Contracts\RuleInterface
38
-	 */
39
-	public function addFlag(int $flag): RuleInterface;
32
+    /**
33
+     * Add a Rule flag.
34
+     *
35
+     * @param integer $flag
36
+     *
37
+     * @return \FigTree\Validation\Contracts\RuleInterface
38
+     */
39
+    public function addFlag(int $flag): RuleInterface;
40 40
 
41
-	/**
42
-	 * Remove a Rule flag.
43
-	 *
44
-	 * @param integer $flag
45
-	 *
46
-	 * @return \FigTree\Validation\Contracts\RuleInterface
47
-	 */
48
-	public function removeFlag(int $flag): RuleInterface;
41
+    /**
42
+     * Remove a Rule flag.
43
+     *
44
+     * @param integer $flag
45
+     *
46
+     * @return \FigTree\Validation\Contracts\RuleInterface
47
+     */
48
+    public function removeFlag(int $flag): RuleInterface;
49 49
 
50
-	/**
51
-	 * Get the Rule options.
52
-	 *
53
-	 * @return array
54
-	 */
55
-	public function getOptions(): array;
50
+    /**
51
+     * Get the Rule options.
52
+     *
53
+     * @return array
54
+     */
55
+    public function getOptions(): array;
56 56
 
57
-	/**
58
-	 * Check if a given Rule option exists.
59
-	 *
60
-	 * @param string $name
61
-	 *
62
-	 * @return boolean
63
-	 */
64
-	public function hasOption(string $name): bool;
57
+    /**
58
+     * Check if a given Rule option exists.
59
+     *
60
+     * @param string $name
61
+     *
62
+     * @return boolean
63
+     */
64
+    public function hasOption(string $name): bool;
65 65
 
66
-	/**
67
-	 * Get the value of a given Rule option.
68
-	 *
69
-	 * @param string $name
70
-	 * @param mixed $default
71
-	 *
72
-	 * @return mixed
73
-	 */
74
-	public function getOption(string $name, $default = null);
66
+    /**
67
+     * Get the value of a given Rule option.
68
+     *
69
+     * @param string $name
70
+     * @param mixed $default
71
+     *
72
+     * @return mixed
73
+     */
74
+    public function getOption(string $name, $default = null);
75 75
 
76
-	/**
77
-	 * Set the value of a given Rule option.
78
-	 *
79
-	 * @param string $name
80
-	 * @param mixed $value
81
-	 *
82
-	 * @return \FigTree\Validation\Contracts\RuleInterface
83
-	 */
84
-	public function setOption(string $name, $value): RuleInterface;
76
+    /**
77
+     * Set the value of a given Rule option.
78
+     *
79
+     * @param string $name
80
+     * @param mixed $value
81
+     *
82
+     * @return \FigTree\Validation\Contracts\RuleInterface
83
+     */
84
+    public function setOption(string $name, $value): RuleInterface;
85 85
 
86
-	/**
87
-	 * Remove the given option from the Rule.
88
-	 *
89
-	 * @param string $name
90
-	 *
91
-	 * @return \FigTree\Validation\Contracts\RuleInterface
92
-	 */
93
-	public function removeOption(string $name): RuleInterface;
86
+    /**
87
+     * Remove the given option from the Rule.
88
+     *
89
+     * @param string $name
90
+     *
91
+     * @return \FigTree\Validation\Contracts\RuleInterface
92
+     */
93
+    public function removeOption(string $name): RuleInterface;
94 94
 
95
-	/**
96
-	 * Get the Rule callback.
97
-	 *
98
-	 * @return \Closure|null
99
-	 */
100
-	public function getCallback(): ?Closure;
95
+    /**
96
+     * Get the Rule callback.
97
+     *
98
+     * @return \Closure|null
99
+     */
100
+    public function getCallback(): ?Closure;
101 101
 
102
-	/**
103
-	 * Get the Rule callback.
104
-	 *
105
-	 * @param \Closure|null $callback
106
-	 *
107
-	 * @return \FigTree\Validation\Contracts\RuleInterface
108
-	 */
109
-	public function setCallback(?Closure $callback): RuleInterface;
102
+    /**
103
+     * Get the Rule callback.
104
+     *
105
+     * @param \Closure|null $callback
106
+     *
107
+     * @return \FigTree\Validation\Contracts\RuleInterface
108
+     */
109
+    public function setCallback(?Closure $callback): RuleInterface;
110 110
 
111
-	/**
112
-	 * Cast the Rule into an array.
113
-	 *
114
-	 * @return array
115
-	 */
116
-	public function toArray(): array;
111
+    /**
112
+     * Cast the Rule into an array.
113
+     *
114
+     * @return array
115
+     */
116
+    public function toArray(): array;
117 117
 }
Please login to merge, or discard this patch.
src/Contracts/RuleFactoryInterface.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -6,18 +6,18 @@
 block discarded – undo
6 6
 
7 7
 interface RuleFactoryInterface
8 8
 {
9
-	/**
10
-	 * Create a new Rule.
11
-	 *
12
-	 * @param int $filterType The filter type.
13
-	 * @param int $flags Bitewise set of filter flags.
14
-	 * @param array $options Filter options.
15
-	 * @param \Closure|null Callback method.
16
-	 *
17
-	 * @return \FigTree\Validation\Contracts\RuleInterface
18
-	 *
19
-	 * @see https://www.php.net/manual/en/filter.filters.php
20
-	 * @see https://www.php.net/manual/en/filter.filters.flags.php
21
-	 */
22
-	public function create(int $filterType, int $flags = 0, array $options = [], ?Closure $callback = null): RuleInterface;
9
+    /**
10
+     * Create a new Rule.
11
+     *
12
+     * @param int $filterType The filter type.
13
+     * @param int $flags Bitewise set of filter flags.
14
+     * @param array $options Filter options.
15
+     * @param \Closure|null Callback method.
16
+     *
17
+     * @return \FigTree\Validation\Contracts\RuleInterface
18
+     *
19
+     * @see https://www.php.net/manual/en/filter.filters.php
20
+     * @see https://www.php.net/manual/en/filter.filters.flags.php
21
+     */
22
+    public function create(int $filterType, int $flags = 0, array $options = [], ?Closure $callback = null): RuleInterface;
23 23
 }
Please login to merge, or discard this patch.
src/Concerns/CreatesProgrammaticRules.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,29 +7,29 @@
 block discarded – undo
7 7
 
8 8
 trait CreatesProgrammaticRules
9 9
 {
10
-	/**
11
-	 * Create a Rule for a valid boolean.
12
-	 *
13
-	 * @param callable $callback
14
-	 *
15
-	 * @return \FigTree\Validation\Contracts\RuleInterface
16
-	 */
17
-	public function withCallable(callable $callback): RuleInterface
18
-	{
19
-		return $this->create(FILTER_CALLBACK)
20
-			->setCallback(Closure::fromCallable($callback));
21
-	}
10
+    /**
11
+     * Create a Rule for a valid boolean.
12
+     *
13
+     * @param callable $callback
14
+     *
15
+     * @return \FigTree\Validation\Contracts\RuleInterface
16
+     */
17
+    public function withCallable(callable $callback): RuleInterface
18
+    {
19
+        return $this->create(FILTER_CALLBACK)
20
+            ->setCallback(Closure::fromCallable($callback));
21
+    }
22 22
 
23
-	/**
24
-	 * Create a Rule for a valid boolean.
25
-	 *
26
-	 * @param \Closure $callback
27
-	 *
28
-	 * @return \FigTree\Validation\Contracts\RuleInterface
29
-	 */
30
-	public function withClosure(Closure $callback): RuleInterface
31
-	{
32
-		return $this->create(FILTER_CALLBACK)
33
-			->setCallback($callback);
34
-	}
23
+    /**
24
+     * Create a Rule for a valid boolean.
25
+     *
26
+     * @param \Closure $callback
27
+     *
28
+     * @return \FigTree\Validation\Contracts\RuleInterface
29
+     */
30
+    public function withClosure(Closure $callback): RuleInterface
31
+    {
32
+        return $this->create(FILTER_CALLBACK)
33
+            ->setCallback($callback);
34
+    }
35 35
 }
Please login to merge, or discard this patch.
src/Concerns/CreatesSanitationRules.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -6,169 +6,169 @@
 block discarded – undo
6 6
 
7 7
 trait CreatesSanitationRules
8 8
 {
9
-	public function addSlashes(): RuleInterface
10
-	{
11
-		return $this->create(FILTER_SANITIZE_ADD_SLASHES);
12
-	}
9
+    public function addSlashes(): RuleInterface
10
+    {
11
+        return $this->create(FILTER_SANITIZE_ADD_SLASHES);
12
+    }
13 13
 
14
-	public function cleanEmail(): RuleInterface
15
-	{
16
-		return $this->create(FILTER_SANITIZE_EMAIL);
17
-	}
14
+    public function cleanEmail(): RuleInterface
15
+    {
16
+        return $this->create(FILTER_SANITIZE_EMAIL);
17
+    }
18 18
 
19
-	public function cleanEncodedString(bool $stripLow = false, bool $stripHigh = false, bool $stripBacktick = false, bool $encodeLow = false, bool $encodeHigh = false): RuleInterface
20
-	{
21
-		$flags = 0;
19
+    public function cleanEncodedString(bool $stripLow = false, bool $stripHigh = false, bool $stripBacktick = false, bool $encodeLow = false, bool $encodeHigh = false): RuleInterface
20
+    {
21
+        $flags = 0;
22 22
 
23
-		if ($stripLow) {
24
-			$flags |= FILTER_FLAG_STRIP_LOW;
25
-		}
23
+        if ($stripLow) {
24
+            $flags |= FILTER_FLAG_STRIP_LOW;
25
+        }
26 26
 
27
-		if ($stripHigh) {
28
-			$flags |= FILTER_FLAG_STRIP_HIGH;
29
-		}
27
+        if ($stripHigh) {
28
+            $flags |= FILTER_FLAG_STRIP_HIGH;
29
+        }
30 30
 
31
-		if ($stripBacktick) {
32
-			$flags |= FILTER_FLAG_STRIP_BACKTICK;
33
-		}
31
+        if ($stripBacktick) {
32
+            $flags |= FILTER_FLAG_STRIP_BACKTICK;
33
+        }
34 34
 
35
-		if ($encodeLow) {
36
-			$flags |= FILTER_FLAG_ENCODE_LOW;
37
-		}
35
+        if ($encodeLow) {
36
+            $flags |= FILTER_FLAG_ENCODE_LOW;
37
+        }
38 38
 
39
-		if ($encodeHigh) {
40
-			$flags |= FILTER_FLAG_ENCODE_HIGH;
41
-		}
39
+        if ($encodeHigh) {
40
+            $flags |= FILTER_FLAG_ENCODE_HIGH;
41
+        }
42 42
 
43
-		return $this->create(FILTER_SANITIZE_ENCODED, $flags);
44
-	}
43
+        return $this->create(FILTER_SANITIZE_ENCODED, $flags);
44
+    }
45 45
 
46
-	public function cleanFloat(bool $allowFractions = false, bool $allowThousands = false, $allowScientific = false): RuleInterface
47
-	{
48
-		$flags = 0;
46
+    public function cleanFloat(bool $allowFractions = false, bool $allowThousands = false, $allowScientific = false): RuleInterface
47
+    {
48
+        $flags = 0;
49 49
 
50
-		if ($allowFractions) {
51
-			$flags |= FILTER_FLAG_ALLOW_FRACTION;
52
-		}
50
+        if ($allowFractions) {
51
+            $flags |= FILTER_FLAG_ALLOW_FRACTION;
52
+        }
53 53
 
54
-		if ($allowThousands) {
55
-			$flags |= FILTER_FLAG_ALLOW_THOUSAND;
56
-		}
54
+        if ($allowThousands) {
55
+            $flags |= FILTER_FLAG_ALLOW_THOUSAND;
56
+        }
57 57
 
58
-		if ($allowScientific) {
59
-			$flags |= FILTER_FLAG_ALLOW_SCIENTIFIC;
60
-		}
58
+        if ($allowScientific) {
59
+            $flags |= FILTER_FLAG_ALLOW_SCIENTIFIC;
60
+        }
61 61
 
62
-		return $this->create(FILTER_SANITIZE_NUMBER_FLOAT, $flags);
63
-	}
62
+        return $this->create(FILTER_SANITIZE_NUMBER_FLOAT, $flags);
63
+    }
64 64
 
65
-	public function cleanFullSpecialChars(bool $encodeQuotes = true): RuleInterface
66
-	{
67
-		$flags = 0;
65
+    public function cleanFullSpecialChars(bool $encodeQuotes = true): RuleInterface
66
+    {
67
+        $flags = 0;
68 68
 
69
-		if (!$encodeQuotes) {
70
-			$flags |= FILTER_FLAG_NO_ENCODE_QUOTES;
71
-		}
69
+        if (!$encodeQuotes) {
70
+            $flags |= FILTER_FLAG_NO_ENCODE_QUOTES;
71
+        }
72 72
 
73
-		return $this->create(FILTER_SANITIZE_FULL_SPECIAL_CHARS, $flags);
74
-	}
73
+        return $this->create(FILTER_SANITIZE_FULL_SPECIAL_CHARS, $flags);
74
+    }
75 75
 
76
-	public function cleanInt(): RuleInterface
77
-	{
78
-		return $this->create(FILTER_SANITIZE_NUMBER_INT);
79
-	}
76
+    public function cleanInt(): RuleInterface
77
+    {
78
+        return $this->create(FILTER_SANITIZE_NUMBER_INT);
79
+    }
80 80
 
81
-	public function cleanSpecialChars(bool $stripLow = false, bool $stripHigh = false, bool $stripBacktick = false, bool $encodeHigh = false): RuleInterface
82
-	{
83
-		$flags = 0;
81
+    public function cleanSpecialChars(bool $stripLow = false, bool $stripHigh = false, bool $stripBacktick = false, bool $encodeHigh = false): RuleInterface
82
+    {
83
+        $flags = 0;
84 84
 
85
-		if ($stripLow) {
86
-			$flags |= FILTER_FLAG_STRIP_LOW;
87
-		}
85
+        if ($stripLow) {
86
+            $flags |= FILTER_FLAG_STRIP_LOW;
87
+        }
88 88
 
89
-		if ($stripHigh) {
90
-			$flags |= FILTER_FLAG_STRIP_HIGH;
91
-		}
89
+        if ($stripHigh) {
90
+            $flags |= FILTER_FLAG_STRIP_HIGH;
91
+        }
92 92
 
93
-		if ($stripBacktick) {
94
-			$flags |= FILTER_FLAG_STRIP_BACKTICK;
95
-		}
93
+        if ($stripBacktick) {
94
+            $flags |= FILTER_FLAG_STRIP_BACKTICK;
95
+        }
96 96
 
97
-		if ($encodeHigh) {
98
-			$flags |= FILTER_FLAG_ENCODE_HIGH;
99
-		}
97
+        if ($encodeHigh) {
98
+            $flags |= FILTER_FLAG_ENCODE_HIGH;
99
+        }
100 100
 
101
-		return $this->create(FILTER_SANITIZE_SPECIAL_CHARS, $flags);
102
-	}
101
+        return $this->create(FILTER_SANITIZE_SPECIAL_CHARS, $flags);
102
+    }
103 103
 
104
-	public function cleanString(bool $encodeQuotes = true, bool $stripLow = false, bool $stripHigh = false, bool $stripBacktick = false, bool $encodeLow = false, bool $encodeHigh = false, bool $encodeAmp = false): RuleInterface
105
-	{
106
-		$flags = 0;
104
+    public function cleanString(bool $encodeQuotes = true, bool $stripLow = false, bool $stripHigh = false, bool $stripBacktick = false, bool $encodeLow = false, bool $encodeHigh = false, bool $encodeAmp = false): RuleInterface
105
+    {
106
+        $flags = 0;
107 107
 
108
-		if (!$encodeQuotes) {
109
-			$flags |= FILTER_FLAG_NO_ENCODE_QUOTES;
110
-		}
108
+        if (!$encodeQuotes) {
109
+            $flags |= FILTER_FLAG_NO_ENCODE_QUOTES;
110
+        }
111 111
 
112
-		if ($stripLow) {
113
-			$flags |= FILTER_FLAG_STRIP_LOW;
114
-		}
112
+        if ($stripLow) {
113
+            $flags |= FILTER_FLAG_STRIP_LOW;
114
+        }
115 115
 
116
-		if ($stripHigh) {
117
-			$flags |= FILTER_FLAG_STRIP_HIGH;
118
-		}
116
+        if ($stripHigh) {
117
+            $flags |= FILTER_FLAG_STRIP_HIGH;
118
+        }
119 119
 
120
-		if ($stripBacktick) {
121
-			$flags |= FILTER_FLAG_STRIP_BACKTICK;
122
-		}
120
+        if ($stripBacktick) {
121
+            $flags |= FILTER_FLAG_STRIP_BACKTICK;
122
+        }
123 123
 
124
-		if ($encodeLow) {
125
-			$flags |= FILTER_FLAG_ENCODE_LOW;
126
-		}
124
+        if ($encodeLow) {
125
+            $flags |= FILTER_FLAG_ENCODE_LOW;
126
+        }
127 127
 
128
-		if ($encodeHigh) {
129
-			$flags |= FILTER_FLAG_ENCODE_HIGH;
130
-		}
128
+        if ($encodeHigh) {
129
+            $flags |= FILTER_FLAG_ENCODE_HIGH;
130
+        }
131 131
 
132
-		if ($encodeAmp) {
133
-			$flags |= FILTER_FLAG_ENCODE_AMP;
134
-		}
132
+        if ($encodeAmp) {
133
+            $flags |= FILTER_FLAG_ENCODE_AMP;
134
+        }
135 135
 
136
-		return $this->create(FILTER_SANITIZE_STRING, $flags);
137
-	}
136
+        return $this->create(FILTER_SANITIZE_STRING, $flags);
137
+    }
138 138
 
139
-	public function cleanUnsafe(bool $stripLow = false, bool $stripHigh = false, bool $stripBacktick = false, bool $encodeLow = false, bool $encodeHigh = false, bool $encodeAmp = false): RuleInterface
140
-	{
141
-		$flags = 0;
139
+    public function cleanUnsafe(bool $stripLow = false, bool $stripHigh = false, bool $stripBacktick = false, bool $encodeLow = false, bool $encodeHigh = false, bool $encodeAmp = false): RuleInterface
140
+    {
141
+        $flags = 0;
142 142
 
143
-		if ($stripLow) {
144
-			$flags |= FILTER_FLAG_STRIP_LOW;
145
-		}
143
+        if ($stripLow) {
144
+            $flags |= FILTER_FLAG_STRIP_LOW;
145
+        }
146 146
 
147
-		if ($stripHigh) {
148
-			$flags |= FILTER_FLAG_STRIP_HIGH;
149
-		}
147
+        if ($stripHigh) {
148
+            $flags |= FILTER_FLAG_STRIP_HIGH;
149
+        }
150 150
 
151
-		if ($stripBacktick) {
152
-			$flags |= FILTER_FLAG_STRIP_BACKTICK;
153
-		}
151
+        if ($stripBacktick) {
152
+            $flags |= FILTER_FLAG_STRIP_BACKTICK;
153
+        }
154 154
 
155
-		if ($encodeLow) {
156
-			$flags |= FILTER_FLAG_ENCODE_LOW;
157
-		}
155
+        if ($encodeLow) {
156
+            $flags |= FILTER_FLAG_ENCODE_LOW;
157
+        }
158 158
 
159
-		if ($encodeHigh) {
160
-			$flags |= FILTER_FLAG_ENCODE_HIGH;
161
-		}
159
+        if ($encodeHigh) {
160
+            $flags |= FILTER_FLAG_ENCODE_HIGH;
161
+        }
162 162
 
163
-		if ($encodeAmp) {
164
-			$flags |= FILTER_FLAG_ENCODE_AMP;
165
-		}
163
+        if ($encodeAmp) {
164
+            $flags |= FILTER_FLAG_ENCODE_AMP;
165
+        }
166 166
 
167
-		return $this->create(FILTER_UNSAFE_RAW, $flags);
168
-	}
167
+        return $this->create(FILTER_UNSAFE_RAW, $flags);
168
+    }
169 169
 
170
-	public function cleanUrl(): RuleInterface
171
-	{
172
-		return $this->create(FILTER_SANITIZE_URL);
173
-	}
170
+    public function cleanUrl(): RuleInterface
171
+    {
172
+        return $this->create(FILTER_SANITIZE_URL);
173
+    }
174 174
 }
Please login to merge, or discard this patch.
src/Concerns/CreatesValidationRules.php 1 patch
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -6,205 +6,205 @@
 block discarded – undo
6 6
 
7 7
 trait CreatesValidationRules
8 8
 {
9
-	/**
10
-	 * Create a Rule for a valid boolean.
11
-	 *
12
-	 * @param mixed $default
13
-	 *
14
-	 * @return \FigTree\Validation\Contracts\RuleInterface
15
-	 */
16
-	public function validBool($default = null): RuleInterface
17
-	{
18
-		return $this->applyDefault($this->create(FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE), $default);
19
-	}
20
-
21
-	/**
22
-	 * Create a Rule for a valid domain name.
23
-	 *
24
-	 * @param boolean $checkHostname Adds ability to specifically validate hostnames (they must start with an alphanumeric character and contain only alphanumerics or hyphens).
25
-	 * @param mixed $default
26
-	 *
27
-	 * @return \FigTree\Validation\Contracts\RuleInterface
28
-	 */
29
-	public function validDomain(bool $checkHostname = false, $default = null): RuleInterface
30
-	{
31
-		$flags = 0;
32
-
33
-		if ($checkHostname) {
34
-			$flags |= FILTER_FLAG_HOSTNAME;
35
-		}
36
-
37
-		return $this->applyDefault($this->create(FILTER_VALIDATE_DOMAIN, $flags), $default);
38
-	}
39
-
40
-	/**
41
-	 * Create a Rule for a valid e-mail address.
42
-	 *
43
-	 * @param boolean $checkUnicode
44
-	 * @param mixed $default
45
-	 *
46
-	 * @return \FigTree\Validation\Contracts\RuleInterface
47
-	 */
48
-	public function validEmail(bool $checkUnicode = false, $default = null): RuleInterface
49
-	{
50
-		$flags = 0;
51
-
52
-		if ($checkUnicode) {
53
-			$flags |= FILTER_FLAG_EMAIL_UNICODE;
54
-		}
55
-
56
-		return $this->applyDefault($this->create(FILTER_VALIDATE_EMAIL, $flags), $default);
57
-	}
58
-
59
-	/**
60
-	 * Create a Rule for a valid floating-point value.
61
-	 *
62
-	 * @param float|null $min
63
-	 * @param float|null $max
64
-	 * @param integer|null $decimals
65
-	 * @param boolean $allowThousands Allow thousand separators (commas).
66
-	 * @param mixed $default
67
-	 *
68
-	 * @return \FigTree\Validation\Contracts\RuleInterface
69
-	 */
70
-	public function validFloat(?float $min = null, ?float $max = null, ?int $decimals = null, bool $allowThousands = false, $default = null): RuleInterface
71
-	{
72
-		$flags = 0;
73
-		$options = [];
74
-
75
-		if (!is_null($min)) {
76
-			$options['min_range'] = $min;
77
-		}
78
-
79
-		if (!is_null($max)) {
80
-			$options['max_range'] = $max;
81
-		}
82
-
83
-		if (!is_null($decimals)) {
84
-			$options['decimal'] = $decimals;
85
-		}
86
-
87
-		if ($allowThousands) {
88
-			$flags |= FILTER_FLAG_ALLOW_THOUSAND;
89
-		}
90
-
91
-		return $this->applyDefault($this->create(FILTER_VALIDATE_FLOAT, $flags, $options), $default);
92
-	}
93
-
94
-	/**
95
-	 * Create a Rule for a valid integer.
96
-	 *
97
-	 * @param integer|null $min
98
-	 * @param integer|null $max
99
-	 * @param boolean $allowOctal
100
-	 * @param boolean $allowHex
101
-	 * @param mixed $default
102
-	 *
103
-	 * @return \FigTree\Validation\Contracts\RuleInterface
104
-	 */
105
-	public function validInt(?int $min = null, ?int $max = null, bool $allowOctal = false, bool $allowHex = false, $default = null): RuleInterface
106
-	{
107
-		$flags = 0;
108
-		$options = [];
109
-
110
-		if (!is_null($min)) {
111
-			$options['min_range'] = $min;
112
-		}
113
-
114
-		if (!is_null($max)) {
115
-			$options['max_range'] = $max;
116
-		}
117
-
118
-		if ($allowOctal) {
119
-			$flags |= FILTER_FLAG_ALLOW_OCTAL;
120
-		}
121
-
122
-		if ($allowHex) {
123
-			$flags |= FILTER_FLAG_ALLOW_HEX;
124
-		}
125
-
126
-		return $this->applyDefault($this->create(FILTER_VALIDATE_INT, $flags, $options), $default);
127
-	}
128
-
129
-	/**
130
-	 * Create a Rule for a valid IP address.
131
-	 *
132
-	 * @param boolean $allowV4
133
-	 * @param boolean $allowV6
134
-	 * @param boolean $allowPrivateRange Allow IP addresses within private ranges.
135
-	 * @param boolean $allowReservedRange Allow IP addresses within other reserved ranges.
136
-	 * @param mixed $default
137
-	 *
138
-	 * @return \FigTree\Validation\Contracts\RuleInterface
139
-	 *
140
-	 * @see https://en.wikipedia.org/wiki/Reserved_IP_addresses
141
-	 */
142
-	public function validIpAddress(bool $allowV4 = false, bool $allowV6 = false, bool $allowPrivateRange = true, bool $allowReservedRange = true, $default = null): RuleInterface
143
-	{
144
-		$flags = 0;
145
-
146
-		if ($allowV4) {
147
-			$flags |= FILTER_FLAG_IPV4;
148
-		}
149
-
150
-		if ($allowV6) {
151
-			$flags |= FILTER_FLAG_IPV6;
152
-		}
153
-
154
-		if (!$allowPrivateRange) {
155
-			$flags |= FILTER_FLAG_NO_PRIV_RANGE;
156
-		}
157
-
158
-		if (!$allowReservedRange) {
159
-			$flags |= FILTER_FLAG_NO_RES_RANGE;
160
-		}
161
-
162
-		return $this->applyDefault($this->create(FILTER_VALIDATE_IP, $flags), $default);
163
-	}
164
-
165
-	/**
166
-	 * Create a Rule for a valid MAC address.
167
-	 *
168
-	 * @param mixed $default
169
-	 *
170
-	 * @return \FigTree\Validation\Contracts\RuleInterface
171
-	 */
172
-	public function validMacAddress($default = null): RuleInterface
173
-	{
174
-		return $this->applyDefault($this->create(FILTER_VALIDATE_MAC), $default);
175
-	}
176
-
177
-	/**
178
-	 * Create a Rule for a valid regular expression match.
179
-	 *
180
-	 * @param string $regex
181
-	 * @param mixed $default
182
-	 *
183
-	 * @return \FigTree\Validation\Contracts\RuleInterface
184
-	 */
185
-	public function validRegExp(string $regex, $default = null): RuleInterface
186
-	{
187
-		$options = [
188
-			'regexp' => $regex,
189
-		];
190
-
191
-		return $this->applyDefault($this->create(FILTER_VALIDATE_REGEXP, 0, $options), $default);
192
-	}
193
-
194
-	/**
195
-	 * Apply default option to the Rule.
196
-	 *
197
-	 * @param \FigTree\Validation\Contracts\RuleInterface $rule
198
-	 * @param mixed $default
199
-	 *
200
-	 * @return \FigTree\Validation\Contracts\RuleInterface
201
-	 */
202
-	protected function applyDefault(RuleInterface $rule, $default = null): RuleInterface
203
-	{
204
-		if (!is_null($default)) {
205
-			$rule->setOption('default', $default);
206
-		}
207
-
208
-		return $rule;
209
-	}
9
+    /**
10
+     * Create a Rule for a valid boolean.
11
+     *
12
+     * @param mixed $default
13
+     *
14
+     * @return \FigTree\Validation\Contracts\RuleInterface
15
+     */
16
+    public function validBool($default = null): RuleInterface
17
+    {
18
+        return $this->applyDefault($this->create(FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE), $default);
19
+    }
20
+
21
+    /**
22
+     * Create a Rule for a valid domain name.
23
+     *
24
+     * @param boolean $checkHostname Adds ability to specifically validate hostnames (they must start with an alphanumeric character and contain only alphanumerics or hyphens).
25
+     * @param mixed $default
26
+     *
27
+     * @return \FigTree\Validation\Contracts\RuleInterface
28
+     */
29
+    public function validDomain(bool $checkHostname = false, $default = null): RuleInterface
30
+    {
31
+        $flags = 0;
32
+
33
+        if ($checkHostname) {
34
+            $flags |= FILTER_FLAG_HOSTNAME;
35
+        }
36
+
37
+        return $this->applyDefault($this->create(FILTER_VALIDATE_DOMAIN, $flags), $default);
38
+    }
39
+
40
+    /**
41
+     * Create a Rule for a valid e-mail address.
42
+     *
43
+     * @param boolean $checkUnicode
44
+     * @param mixed $default
45
+     *
46
+     * @return \FigTree\Validation\Contracts\RuleInterface
47
+     */
48
+    public function validEmail(bool $checkUnicode = false, $default = null): RuleInterface
49
+    {
50
+        $flags = 0;
51
+
52
+        if ($checkUnicode) {
53
+            $flags |= FILTER_FLAG_EMAIL_UNICODE;
54
+        }
55
+
56
+        return $this->applyDefault($this->create(FILTER_VALIDATE_EMAIL, $flags), $default);
57
+    }
58
+
59
+    /**
60
+     * Create a Rule for a valid floating-point value.
61
+     *
62
+     * @param float|null $min
63
+     * @param float|null $max
64
+     * @param integer|null $decimals
65
+     * @param boolean $allowThousands Allow thousand separators (commas).
66
+     * @param mixed $default
67
+     *
68
+     * @return \FigTree\Validation\Contracts\RuleInterface
69
+     */
70
+    public function validFloat(?float $min = null, ?float $max = null, ?int $decimals = null, bool $allowThousands = false, $default = null): RuleInterface
71
+    {
72
+        $flags = 0;
73
+        $options = [];
74
+
75
+        if (!is_null($min)) {
76
+            $options['min_range'] = $min;
77
+        }
78
+
79
+        if (!is_null($max)) {
80
+            $options['max_range'] = $max;
81
+        }
82
+
83
+        if (!is_null($decimals)) {
84
+            $options['decimal'] = $decimals;
85
+        }
86
+
87
+        if ($allowThousands) {
88
+            $flags |= FILTER_FLAG_ALLOW_THOUSAND;
89
+        }
90
+
91
+        return $this->applyDefault($this->create(FILTER_VALIDATE_FLOAT, $flags, $options), $default);
92
+    }
93
+
94
+    /**
95
+     * Create a Rule for a valid integer.
96
+     *
97
+     * @param integer|null $min
98
+     * @param integer|null $max
99
+     * @param boolean $allowOctal
100
+     * @param boolean $allowHex
101
+     * @param mixed $default
102
+     *
103
+     * @return \FigTree\Validation\Contracts\RuleInterface
104
+     */
105
+    public function validInt(?int $min = null, ?int $max = null, bool $allowOctal = false, bool $allowHex = false, $default = null): RuleInterface
106
+    {
107
+        $flags = 0;
108
+        $options = [];
109
+
110
+        if (!is_null($min)) {
111
+            $options['min_range'] = $min;
112
+        }
113
+
114
+        if (!is_null($max)) {
115
+            $options['max_range'] = $max;
116
+        }
117
+
118
+        if ($allowOctal) {
119
+            $flags |= FILTER_FLAG_ALLOW_OCTAL;
120
+        }
121
+
122
+        if ($allowHex) {
123
+            $flags |= FILTER_FLAG_ALLOW_HEX;
124
+        }
125
+
126
+        return $this->applyDefault($this->create(FILTER_VALIDATE_INT, $flags, $options), $default);
127
+    }
128
+
129
+    /**
130
+     * Create a Rule for a valid IP address.
131
+     *
132
+     * @param boolean $allowV4
133
+     * @param boolean $allowV6
134
+     * @param boolean $allowPrivateRange Allow IP addresses within private ranges.
135
+     * @param boolean $allowReservedRange Allow IP addresses within other reserved ranges.
136
+     * @param mixed $default
137
+     *
138
+     * @return \FigTree\Validation\Contracts\RuleInterface
139
+     *
140
+     * @see https://en.wikipedia.org/wiki/Reserved_IP_addresses
141
+     */
142
+    public function validIpAddress(bool $allowV4 = false, bool $allowV6 = false, bool $allowPrivateRange = true, bool $allowReservedRange = true, $default = null): RuleInterface
143
+    {
144
+        $flags = 0;
145
+
146
+        if ($allowV4) {
147
+            $flags |= FILTER_FLAG_IPV4;
148
+        }
149
+
150
+        if ($allowV6) {
151
+            $flags |= FILTER_FLAG_IPV6;
152
+        }
153
+
154
+        if (!$allowPrivateRange) {
155
+            $flags |= FILTER_FLAG_NO_PRIV_RANGE;
156
+        }
157
+
158
+        if (!$allowReservedRange) {
159
+            $flags |= FILTER_FLAG_NO_RES_RANGE;
160
+        }
161
+
162
+        return $this->applyDefault($this->create(FILTER_VALIDATE_IP, $flags), $default);
163
+    }
164
+
165
+    /**
166
+     * Create a Rule for a valid MAC address.
167
+     *
168
+     * @param mixed $default
169
+     *
170
+     * @return \FigTree\Validation\Contracts\RuleInterface
171
+     */
172
+    public function validMacAddress($default = null): RuleInterface
173
+    {
174
+        return $this->applyDefault($this->create(FILTER_VALIDATE_MAC), $default);
175
+    }
176
+
177
+    /**
178
+     * Create a Rule for a valid regular expression match.
179
+     *
180
+     * @param string $regex
181
+     * @param mixed $default
182
+     *
183
+     * @return \FigTree\Validation\Contracts\RuleInterface
184
+     */
185
+    public function validRegExp(string $regex, $default = null): RuleInterface
186
+    {
187
+        $options = [
188
+            'regexp' => $regex,
189
+        ];
190
+
191
+        return $this->applyDefault($this->create(FILTER_VALIDATE_REGEXP, 0, $options), $default);
192
+    }
193
+
194
+    /**
195
+     * Apply default option to the Rule.
196
+     *
197
+     * @param \FigTree\Validation\Contracts\RuleInterface $rule
198
+     * @param mixed $default
199
+     *
200
+     * @return \FigTree\Validation\Contracts\RuleInterface
201
+     */
202
+    protected function applyDefault(RuleInterface $rule, $default = null): RuleInterface
203
+    {
204
+        if (!is_null($default)) {
205
+            $rule->setOption('default', $default);
206
+        }
207
+
208
+        return $rule;
209
+    }
210 210
 }
Please login to merge, or discard this patch.
src/Filter.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -4,18 +4,18 @@
 block discarded – undo
4 4
 
5 5
 class Filter extends AbstractFilter
6 6
 {
7
-	public function __construct(protected array $rules)
8
-	{
9
-		//
10
-	}
7
+    public function __construct(protected array $rules)
8
+    {
9
+        //
10
+    }
11 11
 
12
-	/**
13
-	 * Get the set of Rules for this Filter.
14
-	 *
15
-	 * @return array
16
-	 */
17
-	public function getRules(): array
18
-	{
19
-		return $this->rules;
20
-	}
12
+    /**
13
+     * Get the set of Rules for this Filter.
14
+     *
15
+     * @return array
16
+     */
17
+    public function getRules(): array
18
+    {
19
+        return $this->rules;
20
+    }
21 21
 }
Please login to merge, or discard this patch.