PositiveNumberValidationStrategy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 21
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 15 2
1
<?php declare(strict_types=1);
2
3
namespace PerfectApp\Validation;
4
5
/**
6
 * Validates positive number greater than zero. Handles string & Integer numbers
7
 */
8
class PositiveNumberValidationStrategy implements ValidationStrategy
9
{
10
    /**
11
     * @param $data
12
     * @return bool
13
     */
14 4
    public function validate($data): bool
15
    {
16
        // Convert the data to a string
17 4
        $data = strval($data);
18
19
        // Check if the data is a valid numeric value
20 4
        if (!ctype_digit($data)) {
21 2
            return false;
22
        }
23
24
        // Convert the data to an integer
25 2
        $number = intval($data);
26
27
        // Check if the number is greater than zero
28 2
        return $number > 0;
29
    }
30
}
31