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
Push — master ( ea683e...478e24 )
by Henrique
03:49
created

Yes::getPattern()   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
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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 const YESEXPR;
17
use function is_string;
18
use function nl_langinfo;
19
use function preg_match;
20
21
/**
22
 * Validates if the input considered as "Yes".
23
 *
24
 * @author Cameron Hall <[email protected]>
25
 * @author Henrique Moody <[email protected]>
26
 */
27
final class Yes extends AbstractRule
28
{
29
    /**
30
     * @var bool
31
     */
32
    private $useLocale;
33
34
    /**
35
     * Initializes the rule.
36
     *
37
     * @param bool $useLocale
38
     */
39 7
    public function __construct(bool $useLocale = false)
40
    {
41 7
        $this->useLocale = $useLocale;
42 7
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 21
    public function validate($input): bool
48
    {
49 21
        if (!is_string($input)) {
50 5
            return false;
51
        }
52
53 16
        return preg_match($this->getPattern(), $input) > 0;
54
    }
55
56 16
    private function getPattern(): string
57
    {
58 16
        if ($this->useLocale) {
59 7
            return '/'.nl_langinfo(YESEXPR).'/';
60
        }
61
62 9
        return '/^y(eah?|ep|es)?$/i';
63
    }
64
}
65