Conditions | 15 |
Paths | 67 |
Total Lines | 60 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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 |
||
56 | public function indexAction() |
||
57 | { |
||
58 | // Init |
||
59 | $this->init(); |
||
60 | |||
61 | $link = $this->configurationManager->getContentObject()->data['tx_popup_auto']; |
||
62 | if (!$link) { |
||
63 | return ''; |
||
64 | } |
||
65 | // create the url |
||
66 | $url = $this->configurationManager->getContentObject() |
||
67 | ->getTypoLink_URL($link); |
||
68 | if (!$url) { |
||
69 | return ''; |
||
70 | } |
||
71 | |||
72 | $ts = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); |
||
73 | $conf = $ts['plugin.']['tx_popup_pi1.']; |
||
74 | |||
75 | // get session data |
||
76 | if ($conf['advancedParams.']['once_per_session']) { |
||
77 | $popups = $GLOBALS['TSFE']->fe_user->getKey('ses', $this->prefixId); |
||
78 | if ($conf['advancedParams.']['once_per_link']) { |
||
79 | if ($popups['links'][$link]) { |
||
80 | return ''; |
||
81 | } else { |
||
82 | $popups['links'][$link] = 1; |
||
83 | } |
||
84 | } else { |
||
85 | if ($popups['pages'][$GLOBALS['TSFE']->id]) { // we have been on the current page |
||
86 | return ''; |
||
87 | } else { |
||
88 | $popups['pages'][$GLOBALS['TSFE']->id] = 1; |
||
89 | } |
||
90 | } |
||
91 | $GLOBALS['TSFE']->fe_user->setKey('ses', $this->prefixId, $popups); |
||
92 | } |
||
93 | |||
94 | $cParams = []; |
||
95 | foreach ($this->customParams as $name => $type) { |
||
96 | $v = $conf['advancedParams.'][$name]; |
||
97 | $cParams[$name] = ($v === '1' || $v == 'yes' || $v == 'on') ? true : false; |
||
98 | } |
||
99 | |||
100 | $params = (array)$conf['allowedParams.']; |
||
101 | if ($cParams['maximize']) { |
||
102 | $params['left'] = 0; |
||
103 | $params['top'] = 0; |
||
104 | $params['width'] = '\' + screen.width + \''; |
||
105 | $params['height'] = '\' + screen.height + \''; |
||
106 | } elseif ($cParams['center'] && $params['width'] > 0 && $params['height'] > 0) { |
||
107 | $params['left'] = '\' + ((screen.width - ' . $params['width'] . ') / 2) + \''; |
||
108 | $params['top'] = '\' + ((screen.height - ' . $params['height'] . ') / 2) + \''; |
||
109 | $params['screenX'] = '\' + ((screen.width - ' . $params['width'] . ') / 2) + \''; |
||
110 | $params['screenY'] = '\' + ((screen.height - ' . $params['height'] . ') / 2) + \''; |
||
111 | } |
||
112 | |||
113 | $params = $this->convertArrayToJsParams($params); |
||
114 | return $this->getHtml($url, $params, $cParams); |
||
115 | } |
||
116 | |||
154 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: