MetaDataProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 94
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getMetaData() 0 18 3
A buildData() 0 10 2
A filter() 0 12 3
1
<?php
2
3
namespace HDNET\OnpageIntegration\Provider;
4
5
use HDNET\OnpageIntegration\Service\ArrayService;
6
use HDNET\OnpageIntegration\Service\OnPageService;
7
8
class MetaDataProvider
9
{
10
11
    /**
12
     * @var \HDNET\OnpageIntegration\Provider\ConfigurationProvider
13
     */
14
    protected $configurationProvider;
15
16
    /**
17
     * @var \HDNET\OnpageIntegration\Service\ArrayService
18
     */
19
    protected $arrayService;
20
21
    /**
22
     * @var \HDNET\OnpageIntegration\Service\OnPageService
23
     */
24
    protected $onPageService;
25
26
    /**
27
     * MetaDataProvider constructor.
28
     *
29
     * @param ConfigurationProvider $configurationProvider
30
     * @param ArrayService          $arrayService
31
     */
32
    public function __construct(
33
        ConfigurationProvider $configurationProvider,
34
        ArrayService $arrayService,
35
        OnPageService $onPageService
36
    ) {
37
        $this->configurationProvider = $configurationProvider;
38
        $this->arrayService = $arrayService;
39
        $this->onPageService = $onPageService;
40
    }
41
42
    /**
43
     * @param string $key
44
     *
45
     * @return array
46
     */
47
    public function getMetaData($key)
48
    {
49
        $configData = $this->configurationProvider->getAllConfigurationData();
50
        $searchKeys = ['description', 'priority', 'errors', 'show'];
51
52
        // todo outsourced
53
        $trimmedConfigData = [];
54
        foreach ($configData['zoom'][$key] as $element) {
55
            if (!array_key_exists('disable', $element)) {
56
                $trimmedConfigData[] = $element;
57
            }
58
        }
59
        // todo deprecated
60
        // $elements = $this->arrayService->findElement($trimmedConfigData, $key);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
62
        $buildData = $this->buildData($trimmedConfigData, $searchKeys);
63
        return $this->onPageService->build($buildData, $key);
64
    }
65
66
    /**
67
     * @param array $array
68
     * @param array $searchKeys
69
     *
70
     * @return array
71
     */
72
    protected function buildData(array $array, array $searchKeys)
73
    {
74
        $tmp = [];
75
76
        foreach ($array as $key => $element) {
77
            $tmp[$key] = $this->filter($element, $searchKeys);
78
        }
79
80
        return $tmp;
81
    }
82
83
    /**
84
     * @param array $array
85
     * @param array $searchKeys
86
     *
87
     * @return array
88
     */
89
    protected function filter(array $array, array $searchKeys)
90
    {
91
        $tmp = [];
92
93
        foreach ($array as $key => $element) {
94
            if (in_array($key, $searchKeys)) {
95
                $tmp[$key] = $element;
96
            }
97
        }
98
99
        return $tmp;
100
    }
101
}
102