FunctionComposite::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Startwind\Forrest\Enrichment\EnrichFunction\Explode;
4
5
use Startwind\Forrest\Enrichment\EnrichFunction\ExplodeEnrichFunction;
6
use Startwind\Forrest\Logger\ForrestLogger;
7
8
class FunctionComposite implements ExplodeEnrichFunction
9
{
10
    /**
11
     * @var ExplodeEnrichFunction[] $functions
12
     */
13
    private static array $functions = [];
14
15
    public function __construct()
16
    {
17
        if (empty(self::$functions)) {
18
            self::$functions = [
19
                new DockerImagesStringFunction(),
20
                new DockerNamesStringFunction(),
21
            ];
22
        }
23
    }
24
25
    public function applyFunction(string $string): array
26
    {
27
        foreach (self::$functions as $function) {
28
            try {
29
                $result = $function->applyFunction($string);
30
            } catch (\Exception $exception) {
31
                ForrestLogger::error($exception->getMessage());
32
                continue;
33
            }
34
35
            if (is_array($result)) {
36
                return $result;
37
            }
38
        }
39
40
        return [];
41
    }
42
}
43