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.

Focus   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A on() 0 3 1
A validate() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marcosh\PhpValidationDSL\Combinator;
6
7
use Marcosh\PhpValidationDSL\Result\ValidationResult;
8
use Marcosh\PhpValidationDSL\Validation;
9
10
final class Focus implements Validation
11
{
12
    /**
13
     * @var callable
14
     */
15
    private $focus;
16
17
    /**
18
     * @var Validation
19
     */
20
    private $validation;
21
22
    /**
23
     * Focus constructor.
24
     * @param callable $focus :: $data -> mixed
25
     * @param Validation $validation
26
     */
27
    private function __construct(callable $focus, Validation $validation)
28
    {
29
        $this->focus = $focus;
30
        $this->validation = $validation;
31
    }
32
33
    /**
34
     * @param callable $focus :: $data -> mixed
35
     * @param Validation $validation
36
     * @return self
37
     */
38
    public static function on(callable $focus, Validation $validation): self
39
    {
40
        return new self($focus, $validation);
41
    }
42
43
    /**
44
     * @template T
45
     * @psalm-param T $data
46
     * @param mixed $data
47
     * @param array $context
48
     * @return ValidationResult
49
     */
50
    public function validate($data, array $context = []): ValidationResult
51
    {
52
        return $this->validation->validate(($this->focus)($data), $context)
53
            ->map(
54
                /**
55
                 * @return T
56
                 */
57
                function () use ($data) {
58
                    return $data;
59
                }
60
            );
61
    }
62
}
63