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
Push — master ( 314542...f7a57a )
by Henrique
03:23
created

Callback::getArguments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
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 file
9
 * that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use function array_merge;
17
use function call_user_func_array;
18
use function count;
19
20
/**
21
 * Validates the input using the return of a given callable.
22
 *
23
 * @author Alexandre Gomes Gaigalas <[email protected]>
24
 * @author Henrique Moody <[email protected]>
25
 * @author William Espindola <[email protected]>
26
 */
27
final class Callback extends AbstractRule
28
{
29
    /**
30
     * @var callable
31
     */
32
    private $callback;
33
34
    /**
35
     * @var mixed[]
36
     */
37
    private $arguments;
38
39
    /**
40
     * Initializes the rule.
41
     *
42
     * @param mixed ...$arguments
43
     */
44 7
    public function __construct(callable $callback, ...$arguments)
45
    {
46 7
        $this->callback = $callback;
47 7
        $this->arguments = $arguments;
48 7
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 13
    public function validate($input): bool
54
    {
55 13
        return (bool) call_user_func_array($this->callback, $this->getArguments($input));
56 13
    }
57 3
58
    /**
59
     * @param mixed $input
60 13
     * @return mixed[]
61
     */
62
    private function getArguments($input): array
63
    {
64
        $arguments = [$input];
65
        if (count($this->arguments) === 0) {
66
            return $arguments;
67
        }
68
69
        return array_merge($arguments, $this->arguments);
70
    }
71
}
72