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.

Coalesce   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A translate() 0 9 3
A withTranslators() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marcosh\PhpValidationDSL\Translator\Combinator;
6
7
use Marcosh\PhpValidationDSL\Translator\Translator;
8
9
final class Coalesce implements Translator
10
{
11
    /**
12
     * @var (Translator|null)[]
13
     */
14
    private $translators;
15
16
    private function __construct(array $translators)
17
    {
18
        $this->translators = $translators;
19
    }
20
21
    public static function withTranslators(?Translator ...$translators): self
22
    {
23
        return new self($translators);
24
    }
25
26
    public function translate(string $string): string
27
    {
28
        foreach ($this->translators as $translator) {
29
            if ($translator instanceof Translator) {
30
                return $translator->translate($string);
31
            }
32
        }
33
34
        return $string;
35
    }
36
}
37