Completed
Pull Request — master (#430)
by Anton
04:30
created

ContainsStrictRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 3
A getDescription() 0 4 1
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 contains
15
 *
16
 * @package Bluz\Validator\Rule
17
 */
18
class ContainsStrictRule extends ContainsRule
19
{
20
    /**
21
     * Check input data
22
     *
23
     * @param  string|array $input
24
     *
25
     * @return bool
26
     */
27 6
    public function validate($input): bool
28
    {
29
        // for array
30 6
        if (is_array($input)) {
31 4
            return in_array($this->containsValue, $input, true);
32
        }
33
        // for string
34 2
        if (is_string($input)) {
35 2
            return false !== mb_strpos($input, $this->containsValue, 0, mb_detect_encoding($input));
36
        }
37
        return false;
38
    }
39
40
    /**
41
     * Get error template
42
     *
43
     * @return string
44
     */
45 6
    public function getDescription() : string
46
    {
47 6
        return __('must contain the value "%s"', $this->containsValue);
48
    }
49
}
50