Passed
Push — master ( 7cd9b3...185f29 )
by Dedipyaman
02:32
created

Positive   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 3
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\Number;
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\Primitive\Numeric;
21
use Phypes\Rule\Rule;
22
23
class Positive implements Rule
24
{
25
26
    public function validate($value): Result
27
    {
28
        $numericResult = (new Numeric())->validate($value);
29
30
        if (!$numericResult->isValid())
31
            return new $numericResult;
32
33
        if ($value > 0)
34
            return new Success();
35
36
        return new Failure(new RuleError(RuleErrorCode::NOT_POSITIVE, 'The supplied number is not positive'));
37
    }
38
}