GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 1547bd...7d72a0 )
by Marco
01:39
created

HasNotKey::withKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marcosh\PhpValidationDSL\Basic;
6
7
use Marcosh\PhpValidationDSL\Result\ValidationResult;
8
use Marcosh\PhpValidationDSL\Translator\Translator;
9
use function is_callable;
10
11
final class HasNotKey
12
{
13
    public const PRESENT_KEY = 'has-not-key.present-key';
14
15
    /**
16
     * @var string
17
     */
18
    private $key;
19
20
    /**
21
     * @var callable $key -> $data -> string[]
22
     */
23
    private $errorFormatter;
24
25
    private function __construct(string $key, ?callable $errorFormatter = null)
26
    {
27
        $this->key = $key;
28
        $this->errorFormatter = is_callable($errorFormatter) ?
29
            $errorFormatter :
30
            function (string $key, $data) {
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
            function (string $key, /** @scrutinizer ignore-unused */ $data) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
            function (/** @scrutinizer ignore-unused */ string $key, $data) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
                return [self::PRESENT_KEY];
32
            };
33
    }
34
35
    public static function withKey(string $key): self
36
    {
37
        return new self($key);
38
    }
39
40
    public static function withKeyAndFormatter(string $key, callable $errorFormatter): self
41
    {
42
        return new self($key, $errorFormatter);
43
    }
44
45
    public static function withKeyAndTranslator(string $key, Translator $translator): self
46
    {
47
        return new self(
48
            $key,
49
            function (string $key, $data) use ($translator) {
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
            function (string $key, /** @scrutinizer ignore-unused */ $data) use ($translator) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
            function (/** @scrutinizer ignore-unused */ string $key, $data) use ($translator) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
                return [$translator->translate(self::PRESENT_KEY)];
51
            }
52
        );
53
    }
54
55
    public function validate($data, array $context = []): ValidationResult
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

55
    public function validate($data, /** @scrutinizer ignore-unused */ array $context = []): ValidationResult

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        if (array_key_exists($this->key, $data)) {
58
            return ValidationResult::errors(($this->errorFormatter)($this->key, $data));
59
        }
60
61
        return ValidationResult::valid($data);
62
    }
63
}
64