Completed
Push — master ( 11f33f...14005b )
by Tim
10:31 queued 07:40
created

BackendController::indexAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 20
Bugs 0 Features 3
Metric Value
c 20
b 0
f 3
dl 0
loc 19
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class BackendController
5
 */
6
7
namespace HDNET\OnpageIntegration\Controller;
8
9
use HDNET\OnpageIntegration\Domain\Repository\ConfigurationRepository;
10
use HDNET\OnpageIntegration\Utility\TitleUtility;
11
use HDNET\OnpageIntegration\Provider\MetaDataProvider;
12
use HDNET\OnpageIntegration\Utility\ArrayUtility;
13
14
use TYPO3\CMS\Extbase\Object\ObjectManager;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
17
18
/**
19
 * Class BackendController
20
 */
21
class BackendController extends ActionController
22
{
23
24
    /**
25
     * @var \HDNET\OnpageIntegration\Loader\ApiResultLoader
26
     * @inject
27
     */
28
    protected $loader;
29
30
    /**
31
     * Represent the index page
32
     */
33
    public function indexAction()
34
    {
35
        $metaDataProvider = GeneralUtility::makeInstance(MetaDataProvider::class);
36
        $seoMetaData[] = $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...
37
        $contentMetaData[] = $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...
38
        $technicalMetaData[] = $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...
39
40
        // todo implement $contentMetaData and check the fourth api call
41
        ArrayUtility::buildIndexActionArray($seoMetaData, 'seoaspects');
42
        ArrayUtility::buildIndexActionArray($technicalMetaData, 'technicalaspects');
43
44
        $this->view->assignMultiple([
45
            'lastCrawl'         => $this->loader->load('zoom_lastcrawl'),
46
            'seoMetaData'       => $seoMetaData,
47
            'contentMetaData'   => $contentMetaData,
48
            'technicalMetaData' => $technicalMetaData,
49
            'moduleName'        => 'Zoom Module'
50
        ]);
51
    }
52
53
    /**
54
     * Handle the detail pages
55
     *
56
     * @param string $section
57
     * @param string $call
58
     */
59
    public function detailAction($section, $call)
60
    {
61
        $objectManager = new ObjectManager();
62
        $configurationRepository = $objectManager->get(ConfigurationRepository::class);
63
64
        /** @var \HDNET\OnpageIntegration\Domain\Model\Configuration $configuration */
65
        $configuration = $configurationRepository->findByUid(1);
66
67
        $apiCallTable = 'zoom_' . $section . '_' . $call . '_table';
68
        $apiCallGraph = 'zoom_' . $section . '_' . $call . '_graph';
69
70
        $this->view->assignMultiple([
71
            'moduleName' => TitleUtility::makeSubTitle($section),
72
            'configuration' => $configuration,
73
            'table'  => $this->loader->load($apiCallTable),
74
            'graph'  => $this->loader->load($apiCallGraph),
75
        ]);
76
    }
77
78
    /**
79
     * Empty Keyword Page
80
     */
81
    public function keywordAction()
82
    {
83
        $this->view->assignMultiple([
84
            'moduleName' => 'Keyword'
85
        ]);
86
    }
87
}
88