Passed
Push — master ( c2e9f1...7cd9b3 )
by Dedipyaman
01:41
created

AlphaNumeric   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 2
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\Chartype;
13
14
use Phypes\Error\RuleError;
15
use Phypes\Error\RuleErrorCode;
16
use Phypes\Result\Failure;
17
use Phypes\Result\Result;
18
use Phypes\Result\Success;
19
use Phypes\Rule\Rule;
20
21
class AlphaNumeric extends Chartype implements Rule
22
{
23
    // TODO: Add AlphaNumeric test
24
25
    public function validate($data): Result
26
    {
27
        if (ctype_alnum(str_replace($this->allowedSpecialChars, '', $data)))
28
            return new Success();
29
        else
30
            return new Failure(new RuleError(RuleErrorCode::NOT_ALNUM, 'String is not Alphanumeric.'));
31
    }
32
}