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.
Completed
Push — master ( 181453...3f335f )
by Edi
25:30
created

NetgenEnhancedSelectionRuntime   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 8.06 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 5
dl 5
loc 62
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B getSelectionName() 5 28 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Netgen\Bundle\EnhancedSelectionBundle\Templating\Twig;
4
5
use eZ\Publish\API\Repository\ContentTypeService;
6
use eZ\Publish\API\Repository\Values\Content\Content;
7
use eZ\Publish\Core\Helper\TranslationHelper;
8
9
class NetgenEnhancedSelectionRuntime
10
{
11
    /**
12
     * @var \eZ\Publish\API\Repository\ContentTypeService
13
     */
14
    protected $contentTypeService;
15
16
    /**
17
     * @var \eZ\Publish\Core\Helper\TranslationHelper
18
     */
19
    protected $translationHelper;
20
21
    /**
22
     * NetgenEnhancedSelectionExtension constructor.
23
     *
24
     * @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService
25
     * @param \eZ\Publish\Core\Helper\TranslationHelper $translationHelper
26
     */
27
    public function __construct(ContentTypeService $contentTypeService, TranslationHelper $translationHelper)
28
    {
29
        $this->contentTypeService = $contentTypeService;
30
        $this->translationHelper = $translationHelper;
31
    }
32
33
    /**
34
     * Returns selection names.
35
     *
36
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
37
     * @param string $fieldDefIdentifier
38
     * @param null|string $selectionIdentifier
39
     *
40
     * @return array|string|null
41
     */
42
    public function getSelectionName(Content $content, $fieldDefIdentifier, $selectionIdentifier = null)
43
    {
44
        $names = array();
45
        $identifiers = array($selectionIdentifier);
46
47
        if ($selectionIdentifier === null) {
48
            $field = $this->translationHelper->getTranslatedField($content, $fieldDefIdentifier);
49
            $identifiers = $field->value->identifiers;
50
        }
51
52
        $contentType = $this->contentTypeService->loadContentType(
53
            $content->contentInfo->contentTypeId
54
        );
55
56
        $fieldDefinition = $contentType->getFieldDefinition($fieldDefIdentifier);
57
58 View Code Duplication
        foreach ($fieldDefinition->fieldSettings['options'] as $option) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
            if (in_array($option['identifier'], $identifiers, true)) {
60
                $names[$option['identifier']] = $option['name'];
61
            }
62
        }
63
64
        if ($selectionIdentifier !== null) {
65
            return !empty($names) ? $names[$selectionIdentifier] : null;
66
        }
67
68
        return $names;
69
    }
70
}
71