Generators   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateBySection() 0 15 3
A __construct() 0 3 1
A getBuildMessages() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the SexyField package.
5
 *
6
 * (c) Dion Snoeijen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare (strict_types = 1);
13
14
namespace Tardigrades\SectionField\Generator;
15
16
use Tardigrades\Entity\SectionInterface;
17
use Tardigrades\SectionField\Generator\Writer\Writable;
18
19
class Generators implements GeneratorsInterface
20
{
21
    /** @var GeneratorInterface[] */
22
    private $generators;
23
24
    /** @var string[] */
25
    private $buildMessages = [];
26
27
    public function __construct(array $generators)
28
    {
29
        $this->generators = $generators;
30
    }
31
32
    public function generateBySection(SectionInterface $section): array
33
    {
34
        $writables = [];
35
36
        /** @var GeneratorInterface $generator */
37
        foreach ($this->generators as $generator) {
38
            try {
39
                $writables[] = $generator->generateBySection($section);
40
            } catch (\Exception $exception) {
41
                $this->buildMessages[] = $exception->getMessage();
42
            }
43
            $this->buildMessages = array_merge($this->buildMessages, $generator->getBuildMessages());
44
        }
45
46
        return $writables;
47
    }
48
49
    public function getBuildMessages(): array
50
    {
51
        return $this->buildMessages;
52
    }
53
}
54