Conditions | 19 |
Paths | 384 |
Total Lines | 97 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
57 | public function indexAction() |
||
58 | { |
||
59 | // Init |
||
60 | $this->init(); |
||
61 | |||
62 | $link = $this->configurationManager->getContentObject()->data['tx_popup_auto']; |
||
63 | if (!$link) { |
||
64 | GeneralUtility::devLog('No link defined', $this->extKey); |
||
65 | return ''; |
||
66 | } |
||
67 | |||
68 | $ts = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); |
||
69 | $conf = $ts['plugin.']['tx_popup_pi1.']; |
||
70 | |||
71 | // get session data |
||
72 | if ($conf['advancedParams.']['once_per_session']) { |
||
73 | $popups = $GLOBALS['TSFE']->fe_user->getKey('ses', $this->prefixId); |
||
74 | if ($conf['advancedParams.']['once_per_link']) { |
||
75 | if ($popups['links'][$link]) { |
||
76 | GeneralUtility::devLog('Pop-up link "' . $link . '" already shown.', $this->extKey); |
||
77 | return ''; |
||
78 | } else { |
||
79 | $popups['links'][$link] = 1; |
||
80 | } |
||
81 | } else { |
||
82 | if ($popups['pages'][$GLOBALS['TSFE']->id]) { // we have been on the current page |
||
83 | GeneralUtility::devLog('Pop-up already shown on this page.', $this->extKey); |
||
84 | return ''; |
||
85 | } else { |
||
86 | $popups['pages'][$GLOBALS['TSFE']->id] = 1; |
||
87 | } |
||
88 | } |
||
89 | $GLOBALS['TSFE']->fe_user->setKey('ses', $this->prefixId, $popups); |
||
90 | } |
||
91 | |||
92 | // create the url |
||
93 | $url = $this->configurationManager->getContentObject() |
||
94 | ->getTypoLink_URL($link); |
||
95 | if (!$url) { |
||
96 | GeneralUtility::devLog('No valid pop-up (e.g. a hidden page):' . $link, $this->extKey); |
||
97 | return ''; |
||
98 | } |
||
99 | |||
100 | // get the JS window parameters directly (protect from errors in TS?) |
||
101 | $params = $conf['allowedParams.']; |
||
102 | |||
103 | // get the custom parameters |
||
104 | $cParams = []; |
||
105 | foreach ($this->customParams as $name => $type) { |
||
106 | $v = $conf['advancedParams.'][$name]; |
||
107 | $cParams[$name] = ($v === '1' || $v == 'yes' || $v == 'on') ? true : false; |
||
108 | } |
||
109 | |||
110 | |||
111 | // thanks to Alex Widschwendter |
||
112 | if ($cParams['maximize']) { |
||
113 | $params['left'] = 0; |
||
114 | $params['top'] = 0; |
||
115 | $params['width'] = '\' + screen.width + \''; |
||
116 | $params['height'] = '\' + screen.height + \''; |
||
117 | } // thanks to Daniel Rampanelli |
||
118 | elseif ($cParams['center'] && $params['width'] > 0 && $params['height'] > 0) { |
||
119 | $params['left'] = '\' + ((screen.width - ' . $params['width'] . ') / 2) + \''; |
||
120 | $params['top'] = '\' + ((screen.height - ' . $params['height'] . ') / 2) + \''; |
||
121 | $params['screenX'] = '\' + ((screen.width - ' . $params['width'] . ') / 2) + \''; |
||
122 | $params['screenY'] = '\' + ((screen.height - ' . $params['height'] . ') / 2) + \''; |
||
123 | } |
||
124 | |||
125 | $tmp_params = []; |
||
126 | while (list($key, $val) = each($params)) { |
||
127 | if (isset($val) && $val != '') { |
||
128 | $tmp_params[] = $key . '=' . $val; |
||
129 | } |
||
130 | } |
||
131 | $params = implode(",", $tmp_params); |
||
132 | |||
133 | |||
134 | // Build Javascript |
||
135 | $content = '<script type="text/javascript"> |
||
136 | /*<![CDATA[*/ |
||
137 | <!-- |
||
138 | '; |
||
139 | $window = uniqid('_popup_'); |
||
140 | |||
141 | $content .= "var $window = window.open('$url', 'Window', '$params');\n"; |
||
142 | |||
143 | // thanks to Tom Binder for the timeout |
||
144 | if ($cParams['popunder']) { |
||
145 | $content .= "if ($window) { window.setTimeout('$window.blur()',500); window.focus(); }"; |
||
146 | } else { |
||
147 | $content .= "if ($window) { window.setTimeout('$window.focus()',500); }"; |
||
148 | } |
||
149 | |||
150 | $content .= "\n// -->\n/*]]>*/</script>\n"; |
||
151 | |||
152 | return $content; |
||
153 | } |
||
154 | } |
||
155 |
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: