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.
Passed
Push — master ( 7e274b...f22b59 )
by Marco
01:36
created

ComposingAssertion   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withTranslator() 0 4 1
A validateAssertion() 0 10 2
A withFormatter() 0 3 1
A __construct() 0 3 1
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
abstract class ComposingAssertion
12
{
13
    public const MESSAGE = 'composing-assertion.not-as-asserted';
14
15
    /**
16
     * @var callable $data -> string[]
17
     */
18
    private $errorFormatter;
19
20
    public function __construct(?callable $errorFormatter = null)
21
    {
22
        $this->errorFormatter = $errorFormatter;
23
    }
24
25
    public static function withFormatter(callable $errorFormatter): self
26
    {
27
        return new static($errorFormatter);
28
    }
29
30
    public static function withTranslator(Translator $translator): self
31
    {
32
        return new static(function ($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

32
        return new static(function (/** @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...
33
            return [$translator->translate(static::MESSAGE)];
34
        });
35
    }
36
37
    abstract public function validate($data, array $context = []): ValidationResult;
38
39
    protected function validateAssertion(callable $assertion, $data, array $context = []): ValidationResult
40
    {
41
        return IsAsAsserted::withAssertionAndErrorFormatter(
42
            $assertion,
43
            is_callable($this->errorFormatter) ?
44
                $this->errorFormatter :
45
                function ($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

45
                function (/** @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...
46
                    return [static::MESSAGE];
47
                }
48
        )->validate($data, $context);
49
    }
50
}
51