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

ContainsStrictRule::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
    public function validate($input): bool
28
    {
29
        // for array
30
        if (is_array($input)) {
31
            return in_array($this->containsValue, $input, true);
32
        }
33
        // for string
34
        if (is_string($input)) {
35
            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
    public function getDescription() : string
46
    {
47
        return __('must contain the value "%s"', $this->containsValue);
48
    }
49
}
50