Passed
Push — master ( a65350...ae9f09 )
by Dedipyaman
02:00
created

ContainsKeyword::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of Phypes <https://github.com/2DSharp/Phypes>.
4
 *
5
 * (c) Dedipyaman Das <[email protected]>
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
12
namespace Phypes\Rule\Pattern;
13
14
15
use Phypes\Error\RuleError;
16
use Phypes\Error\RuleErrorCode;
17
use Phypes\Result\Failure;
18
use Phypes\Result\Result;
19
use Phypes\Result\Success;
20
use Phypes\Rule\Rule;
21
22
class ContainsKeyword implements Rule
23
{
24
    /**
25
     * @var string $keyword
26
     */
27
    private $keyword;
28
29
    public function __construct(string $keyword)
30
    {
31
        $this->keyword = $keyword;
32
    }
33
34
    public function validate($data): Result
35
    {
36
        if (strpos($data, $this->keyword) !== false)
37
            return new Success();
38
        else
39
            return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, "String does not contain keyword"));
40
    }
41
}