Conditions | 15 |
Paths | 86 |
Total Lines | 87 |
Code Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
58 | public function getBlockAction() { |
||
59 | $resp = $this->getResponse(); |
||
60 | $cacheFlag = false; |
||
61 | if (Mage::helper('turpentine/esi')->shouldResponseUseEsi()) { |
||
62 | $req = $this->getRequest(); |
||
63 | $esiHelper = Mage::helper('turpentine/esi'); |
||
64 | $dataHelper = Mage::helper('turpentine/data'); |
||
65 | $debugHelper = Mage::helper('turpentine/debug'); |
||
66 | $esiDataHmac = $req->getParam($esiHelper->getEsiHmacParam()); |
||
67 | $esiDataParamValue = $req->getParam($esiHelper->getEsiDataParam()); |
||
68 | if ($esiDataHmac !== ($hmac = $dataHelper->getHmac($esiDataParamValue))) { |
||
69 | $debugHelper->logWarn('ESI data HMAC mismatch, expected (%s) but received (%s)', |
||
70 | $hmac, $esiDataHmac); |
||
71 | $resp->setHttpResponseCode(500); |
||
72 | $resp->setBody('ESI data is not valid'); |
||
73 | } elseif ( ! ($esiDataArray = $dataHelper->thaw($esiDataParamValue))) { |
||
74 | $debugHelper->logWarn('Invalid ESI data in URL: %s', |
||
75 | $esiDataParamValue); |
||
76 | $resp->setHttpResponseCode(500); |
||
77 | $resp->setBody('ESI data is not valid'); |
||
78 | } elseif ( ! $esiHelper->getEsiDebugEnabled() && |
||
79 | $esiDataArray['esi_method'] !== |
||
80 | $req->getParam($esiHelper->getEsiMethodParam())) { |
||
81 | $resp->setHttpResponseCode(403); |
||
82 | $resp->setBody('ESI method mismatch'); |
||
83 | $debugHelper->logWarn('Blocking change of ESI method: %s -> %s', |
||
84 | $esiDataArray['esi_method'], |
||
85 | $req->getParam($esiHelper->getEsiMethodParam())); |
||
86 | } else { |
||
87 | $esiData = new Varien_Object($esiDataArray); |
||
88 | $origRequest = Mage::app()->getRequest(); |
||
89 | Mage::app()->setCurrentStore( |
||
90 | Mage::app()->getStore($esiData->getStoreId()) ); |
||
91 | $appShim = Mage::getModel('turpentine/shim_mage_core_app'); |
||
92 | if ($referer = $this->_getRefererUrl()) { |
||
93 | $referer = htmlspecialchars_decode($referer); |
||
94 | $dummyRequest = Mage::helper('turpentine/esi') |
||
95 | ->getDummyRequest($referer); |
||
96 | } else { |
||
97 | $dummyRequest = Mage::helper('turpentine/esi') |
||
98 | ->getDummyRequest(); |
||
99 | } |
||
100 | $appShim->shim_setRequest($dummyRequest); |
||
101 | $block = $this->_getEsiBlock($esiData); |
||
102 | if ($block) { |
||
103 | $blockEsiOptions = $block->getEsiOptions(); |
||
104 | $block->setEsiOptions(false); |
||
105 | $resp->setBody($block->toHtml()); |
||
106 | if ((int) $req->getParam($esiHelper->getEsiTtlParam()) > 0) { |
||
107 | $cacheFlag = true; |
||
108 | if (isset($blockEsiOptions['only_cache_if'])) { |
||
109 | switch ($blockEsiOptions['only_cache_if']) { |
||
110 | case 'empty': |
||
111 | $cacheFlag = ('' === $resp->getBody()); |
||
112 | break; |
||
113 | case 'no_text': |
||
114 | $cacheFlag = ('' === trim(strip_tags($resp->getBody()))); |
||
115 | break; |
||
116 | default: |
||
117 | $cacheFlag = false; |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | if ($esiData->getEsiMethod() == 'ajax') { |
||
122 | $resp->setHeader('Access-Control-Allow-Origin', |
||
123 | $esiHelper->getCorsOrigin()); |
||
124 | } |
||
125 | if ( ! is_null($flushEvents = $esiData->getFlushEvents())) { |
||
126 | $resp->setHeader('X-Turpentine-Flush-Events', |
||
127 | implode(',', $flushEvents)); |
||
128 | } |
||
129 | if ($esiHelper->getEsiDebugEnabled()) { |
||
130 | $resp->setHeader('X-Turpentine-Block', |
||
131 | $block->getNameInLayout()); |
||
132 | } |
||
133 | } else { |
||
134 | $resp->setHttpResponseCode(404); |
||
135 | $resp->setBody('ESI block not found'); |
||
136 | } |
||
137 | $appShim->shim_setRequest($origRequest); |
||
138 | } |
||
139 | } else { |
||
140 | $resp->setHttpResponseCode(403); |
||
141 | $resp->setBody('ESI includes are not enabled'); |
||
142 | } |
||
143 | Mage::register('turpentine_nocache_flag', ! $cacheFlag, true); |
||
144 | } |
||
145 | |||
292 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.