FunctionComposite   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 33
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A applyFunction() 0 16 4
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