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 (#1007)
by Henrique
02:39
created

Charset   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 32
c 0
b 0
f 0
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A validate() 0 5 1
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 Respect\Validation\Exceptions\ComponentException;
17
use function array_diff;
18
use function in_array;
19
use function mb_detect_encoding;
20
use function mb_list_encodings;
21
22
/**
23
 * Validates if a string is in a specific charset.
24
 *
25
 * @author Alexandre Gomes Gaigalas <[email protected]>
26
 * @author Henrique Moody <[email protected]>
27
 * @author William Espindola <[email protected]>
28
 */
29
final class Charset extends AbstractRule
30
{
31
    /**
32
     * @var string[]
33
     */
34
    private $charset;
35
36
    /**
37
     * Initializes the rule.
38
     *
39
     * @param string ...$charset
40
     *
41
     * @throws ComponentException
42
     */
43 1
    public function __construct(string ...$charset)
44
    {
45 1
        $available = mb_list_encodings();
46 1
        if (!empty(array_diff($charset, $available))) {
47
            throw new ComponentException('Invalid charset');
48
        }
49
50 1
        $this->charset = $charset;
51 1
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 11
    public function validate($input): bool
57
    {
58 11
        $detectedEncoding = mb_detect_encoding($input, $this->charset, true);
59
60 11
        return in_array($detectedEncoding, $this->charset, true);
61
    }
62
}
63