Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — master ( 0db1cd...2007c7 )
by Henrique
03:59
created

Time   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 9 2
A __construct() 0 7 2
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use function date_parse_from_format;
17
use function is_scalar;
18
use function preg_match;
19
use function sprintf;
20
use Respect\Validation\Exceptions\ComponentException;
21
22
/**
23
 * Validates whether an input is a time or not
24
 *
25
 * @author Henrique Moody <[email protected]>
26
 */
27
final class Time extends AbstractRule
28
{
29
    /**
30
     * @var string
31
     */
32
    private $format;
33
34
    /**
35
     * Initializes the rule.
36
     *
37
     * @param string $format
38
     *
39
     * @throws ComponentException
40
     */
41 3
    public function __construct(string $format = 'H:i:s')
42
    {
43 3
        if (!preg_match('/^[gGhHisuvaA\W]+$/', $format)) {
44 2
            throw new ComponentException(sprintf('"%s" is not a valid date format', $format));
45
        }
46
47 1
        $this->format = $format;
48 1
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 14
    public function validate($input): bool
54
    {
55 14
        if (!is_scalar($input)) {
56 2
            return false;
57
        }
58
59 12
        $info = date_parse_from_format($this->format, (string) $input);
60
61 12
        return ($info['error_count'] + $info['warning_count']) === 0;
62
    }
63
}
64