Completed
Push — develop ( 0bffec...8a2c2d )
by René
12:37
created

BackendController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 30
Bugs 1 Features 7
Metric Value
wmc 4
c 30
b 1
f 7
lcom 1
cbo 5
dl 0
loc 84
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 23 2
A detailAction() 0 19 1
A keywordAction() 0 6 1
1
<?php
2
3
/**
4
 * Class BackendController
5
 */
6
7
namespace HDNET\OnpageIntegration\Controller;
8
9
use HDNET\OnpageIntegration\Exception\UnavailableAccessDataException;
10
use HDNET\OnpageIntegration\Utility\ArrayUtility;
11
use HDNET\OnpageIntegration\Utility\TitleUtility;
12
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
13
14
/**
15
 * Class BackendController
16
 */
17
class BackendController extends ActionController
18
{
19
20
    /**
21
     * @var \HDNET\OnpageIntegration\Loader\ApiResultLoader
22
     * @inject
23
     */
24
    protected $loader;
25
26
    /**
27
     * @var \HDNET\OnpageIntegration\Provider\MetaDataProvider
28
     * @inject
29
     */
30
    protected $metaDataProvider;
31
32
    /**
33
     * @var \HDNET\OnpageIntegration\Domain\Repository\ConfigurationRepository
34
     * @inject
35
     */
36
    protected $configurationRepository;
37
38
    /**
39
     * Represent the index page
40
     */
41
    public function indexAction()
42
    {
43
        try {
44
            $seoMetaData[] = $this->metaDataProvider->getMetaData('seoaspects');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$seoMetaData was never initialized. Although not strictly required by PHP, it is generally a good practice to add $seoMetaData = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
45
            $contentMetaData[] = $this->metaDataProvider->getMetaData('contentaspects');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$contentMetaData was never initialized. Although not strictly required by PHP, it is generally a good practice to add $contentMetaData = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
46
            $technicalMetaData[] = $this->metaDataProvider->getMetaData('technicalaspects');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$technicalMetaData was never initialized. Although not strictly required by PHP, it is generally a good practice to add $technicalMetaData = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
47
48
            ArrayUtility::buildIndexActionArray($seoMetaData, 'seoaspects');
49
            ArrayUtility::buildIndexActionArray($technicalMetaData, 'technicalaspects');
50
            ArrayUtility::buildIndexActionArray($contentMetaData, 'contentaspects');
51
52
53
            $this->view->assignMultiple([
54
                'lastCrawl'         => $this->loader->load('zoom_lastcrawl'),
55
                'seoMetaData'       => $seoMetaData,
56
                'contentMetaData'   => $contentMetaData,
57
                'technicalMetaData' => $technicalMetaData,
58
                'moduleName'        => 'Zoom Module'
59
            ]);
60
        } catch (UnavailableAccessDataException $e) {
61
            return "Bitte tragen Sie Ihre Zugangsdaten ein.";
62
        }
63
    }
64
65
    /**
66
     * Handle the detail pages
67
     *
68
     * @param string $section
69
     * @param string $call
70
     */
71
    public function detailAction($section, $call)
72
    {
73
        /** @var \HDNET\OnpageIntegration\Domain\Model\Configuration $configuration */
74
        $configuration = $this->configurationRepository->findRecord(1);
75
76
        $metaDataProvider = $this->metaDataProvider->getMetaData($section);
77
78
        $showTableKey = $metaDataProvider[$call]['show'];
0 ignored issues
show
Unused Code introduced by
$showTableKey is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
79
        $apiCallTable = 'zoom_' . $section . '_' . $call . '_table';
80
81
        $table = $this->loader->load($apiCallTable);
82
        #$table = ArrayUtility::showTable($this->loader->load($apiCallTable), $showTableKey);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
83
84
        $this->view->assignMultiple([
85
            'moduleName'    => TitleUtility::makeSubTitle($section),
86
            'configuration' => $configuration,
87
            'table'         => $table,
88
        ]);
89
    }
90
91
    /**
92
     * Empty Keyword Page
93
     */
94
    public function keywordAction()
95
    {
96
        $this->view->assignMultiple([
97
            'moduleName' => 'Keyword'
98
        ]);
99
    }
100
}
101