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 ( ab602a...3093d7 )
by Henrique
03:42
created

Formatter::format()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 1
nop 3
dl 0
loc 14
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.md"
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Message;
15
16
use function call_user_func;
17
use function preg_replace_callback;
18
use function Respect\Stringifier\stringify;
19
20
final class Formatter
21
{
22
    /**
23
     * @var callable
24
     */
25
    private $translator;
26
27
    /**
28
     * @var ParameterStringifier
29
     */
30
    private $parameterStringifier;
31
32
    public function __construct(callable $translator, ParameterStringifier $parameterStringifier)
33
    {
34
        $this->translator = $translator;
35
        $this->parameterStringifier = $parameterStringifier;
36
    }
37
38
    /**
39
     * @param mixed $input
40
     * @param mixed[] $parameters
41
     */
42
    public function format(string $template, $input, array $parameters): string
43
    {
44
        $parameters['name'] = $parameters['name'] ?? stringify($input);
45
46
        return preg_replace_callback(
47
            '/{{(\w+)}}/',
48
            function ($match) use ($parameters) {
49
                if (!isset($parameters[$match[1]])) {
50
                    return $match[0];
51
                }
52
53
                return $this->parameterStringifier->stringify($match[1], $parameters[$match[1]]);
54
            },
55
            call_user_func($this->translator, $template)
56
        );
57
    }
58
}
59