Conditions | 2 |
Paths | 2 |
Total Lines | 90 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
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'); |
||
|
|||
37 | $contentMetaData[] = $metaDataProvider->getMetaData('contentaspects'); |
||
38 | $technicalMetaData[] = $metaDataProvider->getMetaData('technicalaspects'); |
||
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 |
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:
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 thebar
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.