Completed
Push — ezp25376-fields_groups ( 240dba...3c499d )
by
unknown
44:05 queued 20:09
created

ArrayTranslatorFieldsGroupsList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getGroups() 0 4 1
A getDefaultGroup() 0 4 1
1
<?php
2
/**
3
 * This file is part of the ezpublish-kernel package.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Publish\Core\Helper\FieldsGroups;
7
8
use Symfony\Component\Translation\TranslatorInterface;
9
10
/**
11
 * A fields groups list implementation based on settings (scalar values) injection.
12
 * Human-readable names are obtained using the translator, in the `ezplatform_fields_groups` domain.
13
 *
14
 * @internal meant to be instantiated by the DIC. Do not inherit from it or instantiate it manually.
15
 */
16
final class ArrayTranslatorFieldsGroupsList implements FieldsGroupsList
17
{
18
    /** @var array */
19
    private $groups;
20
21
    /** @var string */
22
    private $defaultGroup;
23
24
    /** @var \Symfony\Component\Translation\TranslatorInterface */
25
    private $translator;
26
27
    public function __construct(TranslatorInterface $translator, $defaultGroup, array $groups)
28
    {
29
        $translatedGroups = [];
30
        foreach ($groups as $groupIdentifier) {
31
            $translatedGroups[$groupIdentifier] = $translator->trans($groupIdentifier, [], 'ezplatform_fields_groups');
32
        }
33
        $this->groups = $translatedGroups;
34
        $this->defaultGroup = $defaultGroup;
35
        $this->translator = $translator;
36
    }
37
38
    public function getGroups()
39
    {
40
        return $this->groups;
41
    }
42
43
    public function getDefaultGroup()
44
    {
45
        return $this->defaultGroup;
46
    }
47
}
48