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

Completed
Pull Request — master (#912)
by Henrique
02:51
created

Time::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 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
    public const DEFAULT_FORMAT = 'H:i:s';
30
31
    /**
32
     * @var string
33
     */
34
    private $format;
35
36
    /**
37
     * Initializes the rule.
38
     *
39
     * @param string $format
40
     *
41
     * @throws ComponentException
42
     */
43 3
    public function __construct(string $format = 'H:i:s')
44
    {
45 3
        if (!preg_match('/^[gGhHisuvaA\W]+$/', $format)) {
46 2
            throw new ComponentException(sprintf('"%s" is not a valid date format', $format));
47
        }
48
49 1
        $this->format = $format;
50 1
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 14
    public function validate($input): bool
56
    {
57 14
        if (!is_scalar($input)) {
58 2
            return false;
59
        }
60
61 12
        $info = date_parse_from_format($this->format, (string) $input);
62
63 12
        return ($info['error_count'] + $info['warning_count']) === 0;
64
    }
65
}
66