Completed
Push — master ( 38deb0...7544ac )
by Anton
11s
created

InStrictRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 18 4
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Validator\Rule;
12
13
/**
14
 * Check for value in set
15
 *
16
 * @package Bluz\Validator\Rule
17
 */
18
class InStrictRule extends InRule
19
{
20
    /**
21
     * Check input data
22
     *
23
     * @param  string $input
24
     *
25
     * @return bool
26
     */
27 10
    public function validate($input): bool
28
    {
29 10
        if (is_array($this->haystack)) {
30 5
            return in_array($input, $this->haystack, true);
31
        }
32
33 5
        if (!is_string($this->haystack)) {
34 1
            return false;
35
        }
36
37 4
        if (empty($input)) {
38 1
            return false;
39
        }
40
41 3
        $enc = mb_detect_encoding($input);
42
43 3
        return mb_strpos($this->haystack, $input, 0, $enc) !== false;
44
    }
45
}
46