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.

ComposingAssertion::withFormatter()   A
last analyzed

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
/**
12
 * @template T
13
 */
14
abstract class ComposingAssertion
15
{
16
    public const MESSAGE = 'composing-assertion.not-as-asserted';
17
18
    /**
19
     * @var callable|null with signature $data -> string[]
20
     */
21
    private $errorFormatter;
22
23
    public function __construct(?callable $errorFormatter = null)
24
    {
25
        $this->errorFormatter = $errorFormatter;
26
    }
27
28
    public static function withFormatter(callable $errorFormatter): self
29
    {
30
        return new static($errorFormatter);
31
    }
32
33
    public static function withTranslator(Translator $translator): self
34
    {
35
        return new static(
36
            /**
37
             * @param mixed $data
38
             * @psalm-param T $data
39
             * @return string[]
40
             * @psalm-return array{0:mixed}
41
             */
42
            function ($data) use ($translator): array {
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

42
            function (/** @scrutinizer ignore-unused */ $data) use ($translator): array {

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...
43
                return [$translator->translate(static::MESSAGE)];
44
            }
45
        );
46
    }
47
48
    /**
49
     * @param mixed $data
50
     * @psalm-param T $data
51
     * @param array $context
52
     * @return ValidationResult
53
     */
54
    abstract public function validate($data, array $context = []): ValidationResult;
55
56
    /**
57
     * @param callable $assertion
58
     * @param mixed $data
59
     * @psalm-param T $data
60
     * @param array $context
61
     * @return ValidationResult
62
     */
63
    protected function validateAssertion(callable $assertion, $data, array $context = []): ValidationResult
64
    {
65
        return IsAsAsserted::withAssertionAndErrorFormatter(
66
            $assertion,
67
            is_callable($this->errorFormatter) ?
0 ignored issues
show
Bug introduced by
It seems like is_callable($this->error...tion(...) { /* ... */ } can also be of type null; however, parameter $errorFormatter of Marcosh\PhpValidationDSL...tionAndErrorFormatter() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

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

67
            /** @scrutinizer ignore-type */ is_callable($this->errorFormatter) ?
Loading history...
68
                $this->errorFormatter :
69
                /**
70
                 * @param mixed $data
71
                 * @psalm-param T $data
72
                 * @return string[]
73
                 * @psalm-return array{0:mixed}
74
                 */
75
                function ($data): array {
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

75
                function (/** @scrutinizer ignore-unused */ $data): array {

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...
76
                    return [static::MESSAGE];
77
                }
78
        )->validate($data, $context);
79
    }
80
}
81