Skip to content

Commit 1733af0

Browse files
authored
PHPMD updates (#5)
- closes #4
1 parent 5df3410 commit 1733af0

File tree

10 files changed

+78
-36
lines changed

10 files changed

+78
-36
lines changed

src/app/code/core/Mage/Cms/Controller/Router.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function initControllerRouters($observer)
3939
*
4040
* @param Zend_Controller_Request_Http $request
4141
* @return bool
42+
*
43+
* @SuppressWarnings(PHPMD.ExitExpression)
4244
*/
4345
public function match(Zend_Controller_Request_Http $request)
4446
{

src/app/code/core/Mage/Cms/Helper/Page.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public function renderPage(Mage_Core_Controller_Front_Action $action, $pageId =
4848
* @param string $pageId
4949
* @param bool $renderLayout
5050
* @return bool
51+
*
52+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
53+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
54+
* @SuppressWarnings(PHPMD.NPathComplexity)
5155
*/
5256
protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
5357
{
@@ -137,6 +141,8 @@ protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pag
137141
* @param string $pageId
138142
* @param bool $renderLayout
139143
* @return bool
144+
*
145+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
140146
*/
141147
public function renderPageExtended(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
142148
{

src/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ public function convertPathToId($path)
115115
/**
116116
* Decode HTML element id
117117
*
118-
* @param string $id
118+
* @param string $elementId
119119
* @return string
120120
*/
121-
public function convertIdToPath($id)
121+
public function convertIdToPath($elementId)
122122
{
123-
$path = $this->idDecode($id);
123+
$path = $this->idDecode($elementId);
124124
$storageRoot = realpath($this->getStorageRoot());
125125
if (!strstr($path, $storageRoot)) {
126126
$path = $storageRoot . DS . $path;
@@ -134,6 +134,8 @@ public function convertIdToPath($id)
134134
* @param string $path Original path
135135
* @param bool $trim Trim slashes or not
136136
* @return string
137+
*
138+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
137139
*/
138140
public function correctPath($path, $trim = true)
139141
{
@@ -177,6 +179,8 @@ public function isUsingStaticUrlsAllowed()
177179
* @param string $filename Filename transferred via Ajax
178180
* @param bool $renderAsTag Leave image HTML as is or transform it to controller directive
179181
* @return string
182+
*
183+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
180184
*/
181185
public function getImageHtmlDeclaration($filename, $renderAsTag = false)
182186
{
@@ -214,11 +218,11 @@ public function getCurrentPath()
214218
$currentPath = $path;
215219
}
216220
}
217-
$io = new Varien_Io_File();
218-
if (!$io->isWriteable($currentPath) && !$io->mkdir($currentPath)) {
221+
$file = new Varien_Io_File();
222+
if (!$file->isWriteable($currentPath) && !$file->mkdir($currentPath)) {
219223
$message = Mage::helper('cms')->__(
220224
'The directory %s is not writable by server.',
221-
$io->getFilteredPath($currentPath)
225+
$file->getFilteredPath($currentPath)
222226
);
223227
Mage::throwException($message);
224228
}

src/app/code/core/Mage/Cms/Model/Page.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ class Mage_Cms_Model_Page extends Mage_Core_Model_Abstract
7272
/**
7373
* Page's Statuses
7474
*/
75-
public const STATUS_ENABLED = 1;
75+
public const STATUS_ENABLED = 1;
7676
public const STATUS_DISABLED = 0;
7777

78-
public const CACHE_TAG = 'cms_page';
78+
public const CACHE_TAG = 'cms_page';
7979
protected $_cacheTag = 'cms_page';
8080

8181
/**
@@ -93,12 +93,12 @@ protected function _construct()
9393
/**
9494
* @inheritDoc
9595
*/
96-
public function load($id, $field = null)
96+
public function load($value, $field = null)
9797
{
98-
if (is_null($id)) {
98+
if (is_null($value)) {
9999
return $this->noRoutePage();
100100
}
101-
return parent::load($id, $field);
101+
return parent::load($value, $field);
102102
}
103103

104104
/**

src/app/code/core/Mage/Cms/Model/Resource/Block.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ protected function _getLoadSelect($field, $value, $object)
159159
*
160160
* @param Mage_Core_Model_Abstract $object
161161
* @return bool
162+
*
163+
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
162164
*/
163165
public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object)
164166
{
@@ -191,10 +193,10 @@ public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object)
191193
/**
192194
* Get store ids to which specified item is assigned
193195
*
194-
* @param int $id
196+
* @param int $blockId
195197
* @return array
196198
*/
197-
public function lookupStoreIds($id)
199+
public function lookupStoreIds($blockId)
198200
{
199201
$adapter = $this->_getReadAdapter();
200202

@@ -203,7 +205,7 @@ public function lookupStoreIds($id)
203205
->where('block_id = :block_id');
204206

205207
$binds = [
206-
':block_id' => (int) $id
208+
':block_id' => (int) $blockId
207209
];
208210

209211
return $adapter->fetchCol($select, $binds);

src/app/code/core/Mage/Cms/Model/Resource/Block/Collection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function toOptionArray()
4747
* @param int|Mage_Core_Model_Store $store
4848
* @param bool $withAdmin
4949
* @return $this
50+
*
51+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
5052
*/
5153
public function addStoreFilter($store, $withAdmin = true)
5254
{

src/app/code/core/Mage/Cms/Model/Resource/Page.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ protected function _getLoadByIdentifierSelect($identifier, $store, $isActive = n
215215
*
216216
* @param Mage_Core_Model_Abstract|Mage_Cms_Model_Page $object
217217
* @return bool
218+
*
219+
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
218220
*/
219221
public function getIsUniquePageToStores(Mage_Core_Model_Abstract $object)
220222
{
@@ -306,10 +308,10 @@ public function getCmsPageTitleByIdentifier($identifier)
306308
/**
307309
* Retrieves cms page title from DB by passed id.
308310
*
309-
* @param string $id
311+
* @param string $pageId
310312
* @return string
311313
*/
312-
public function getCmsPageTitleById($id)
314+
public function getCmsPageTitleById($pageId)
313315
{
314316
$adapter = $this->_getReadAdapter();
315317

@@ -318,7 +320,7 @@ public function getCmsPageTitleById($id)
318320
->where('page_id = :page_id');
319321

320322
$binds = [
321-
'page_id' => (int) $id
323+
'page_id' => (int) $pageId
322324
];
323325

324326
return $adapter->fetchOne($select, $binds);
@@ -327,10 +329,10 @@ public function getCmsPageTitleById($id)
327329
/**
328330
* Retrieves cms page identifier from DB by passed id.
329331
*
330-
* @param string $id
332+
* @param string $pageId
331333
* @return string|false
332334
*/
333-
public function getCmsPageIdentifierById($id)
335+
public function getCmsPageIdentifierById($pageId)
334336
{
335337
$adapter = $this->_getReadAdapter();
336338

@@ -339,7 +341,7 @@ public function getCmsPageIdentifierById($id)
339341
->where('page_id = :page_id');
340342

341343
$binds = [
342-
'page_id' => (int) $id
344+
'page_id' => (int) $pageId
343345
];
344346

345347
return $adapter->fetchOne($select, $binds);

src/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function toOptionIdArray()
6262
foreach ($this as $item) {
6363
$identifier = $item->getData('identifier');
6464

65+
$data = [];
6566
$data['value'] = $identifier;
6667
$data['label'] = $item->getData('title');
6768

@@ -82,6 +83,8 @@ public function toOptionIdArray()
8283
*
8384
* @param bool $flag
8485
* @return $this
86+
*
87+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
8588
*/
8689
public function setFirstStoreFlag($flag = false)
8790
{
@@ -131,6 +134,8 @@ protected function _afterLoad()
131134
* @param int|Mage_Core_Model_Store $store
132135
* @param bool $withAdmin
133136
* @return $this
137+
*
138+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
134139
*/
135140
public function addStoreFilter($store, $withAdmin = true)
136141
{

src/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*
1919
* @category Mage
2020
* @package Mage_Cms
21+
*
22+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2123
*/
2224
class Mage_Cms_Model_Wysiwyg_Images_Storage extends Varien_Object
2325
{
@@ -44,6 +46,9 @@ class Mage_Cms_Model_Wysiwyg_Images_Storage extends Varien_Object
4446
*
4547
* @param string $path Parent directory path
4648
* @return Varien_Data_Collection_Filesystem
49+
*
50+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
51+
* @SuppressWarnings(PHPMD.NPathComplexity)
4752
*/
4853
public function getDirsCollection($path)
4954
{
@@ -190,8 +195,8 @@ public function createDirectory($name, $path)
190195
Mage::throwException(Mage::helper('cms')->__('A directory with the same name already exists. Please try another folder name.'));
191196
}
192197

193-
$io = new Varien_Io_File();
194-
if ($io->mkdir($newPath)) {
198+
$file = new Varien_Io_File();
199+
if ($file->mkdir($newPath)) {
195200
if (Mage::helper('core/file_storage_database')->checkDbUsage()) {
196201
$relativePath = Mage::helper('core/file_storage_database')->getMediaRelativePath($newPath);
197202
Mage::getModel('core/file_storage_directory_database')->createRecursive($relativePath);
@@ -218,12 +223,12 @@ public function deleteDirectory($path)
218223
$rootCmp = rtrim($this->getHelper()->getStorageRoot(), DS);
219224
$pathCmp = rtrim($path, DS);
220225

221-
$io = new Varien_Io_File();
226+
$file = new Varien_Io_File();
222227

223228
if ($rootCmp == $pathCmp) {
224229
Mage::throwException(Mage::helper('cms')->__(
225230
'Cannot delete root directory %s.',
226-
$io->getFilteredPath($path)
231+
$file->getFilteredPath($path)
227232
));
228233
}
229234
if (str_contains($pathCmp, chr(0))
@@ -235,12 +240,12 @@ public function deleteDirectory($path)
235240
if (Mage::helper('core/file_storage_database')->checkDbUsage()) {
236241
Mage::getModel('core/file_storage_directory_database')->deleteDirectory($path);
237242
}
238-
if (!$io->rmdir($path, true)) {
239-
Mage::throwException(Mage::helper('cms')->__('Cannot delete directory %s.', $io->getFilteredPath($path)));
243+
if (!$file->rmdir($path, true)) {
244+
Mage::throwException(Mage::helper('cms')->__('Cannot delete directory %s.', $file->getFilteredPath($path)));
240245
}
241246

242247
if (str_starts_with($pathCmp, $rootCmp)) {
243-
$io->rmdir($this->getThumbnailRoot() . DS . ltrim(substr($pathCmp, strlen($rootCmp)), '\\/'), true);
248+
$file->rmdir($this->getThumbnailRoot() . DS . ltrim(substr($pathCmp, strlen($rootCmp)), '\\/'), true);
244249
}
245250
}
246251

@@ -252,13 +257,13 @@ public function deleteDirectory($path)
252257
*/
253258
public function deleteFile($target)
254259
{
255-
$io = new Varien_Io_File();
256-
$io->rm($target);
260+
$file = new Varien_Io_File();
261+
$file->rm($target);
257262
Mage::helper('core/file_storage_database')->deleteFile($target);
258263

259264
$thumb = $this->getThumbnailPath($target, true);
260265
if ($thumb) {
261-
$io->rm($thumb);
266+
$file->rm($thumb);
262267
Mage::helper('core/file_storage_database')->deleteFile($thumb);
263268
}
264269
return $this;
@@ -311,9 +316,11 @@ public function uploadFile($targetPath, $type = null)
311316
/**
312317
* Thumbnail path getter
313318
*
314-
* @param string $filePath original file path
319+
* @param string $filePath original file path
315320
* @param bool $checkFile OPTIONAL is it necessary to check file availability
316321
* @return string | false
322+
*
323+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
317324
*/
318325
public function getThumbnailPath($filePath, $checkFile = false)
319326
{
@@ -333,9 +340,11 @@ public function getThumbnailPath($filePath, $checkFile = false)
333340
/**
334341
* Thumbnail URL getter
335342
*
336-
* @param string $filePath original file path
343+
* @param string $filePath original file path
337344
* @param bool $checkFile OPTIONAL is it necessary to check file availability
338345
* @return string|false
346+
*
347+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
339348
*/
340349
public function getThumbnailUrl($filePath, $checkFile = false)
341350
{
@@ -358,6 +367,8 @@ public function getThumbnailUrl($filePath, $checkFile = false)
358367
* @param string $source Image path to be resized
359368
* @param bool $keepRation Keep aspect ratio or not
360369
* @return bool|string Resized filepath or false if errors were occurred
370+
*
371+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
361372
*/
362373
public function resizeFile($source, $keepRation = true)
363374
{
@@ -366,11 +377,11 @@ public function resizeFile($source, $keepRation = true)
366377
}
367378

368379
$targetDir = $this->getThumbsPath($source);
369-
$io = new Varien_Io_File();
370-
if (!$io->isWriteable($targetDir)) {
371-
$io->mkdir($targetDir);
380+
$file = new Varien_Io_File();
381+
if (!$file->isWriteable($targetDir)) {
382+
$file->mkdir($targetDir);
372383
}
373-
if (!$io->isWriteable($targetDir)) {
384+
if (!$file->isWriteable($targetDir)) {
374385
return false;
375386
}
376387
$image = Varien_Image_Adapter::factory('GD2');
@@ -414,6 +425,8 @@ public function resizeOnTheFly($filename)
414425
*
415426
* @param false|string $filePath Path to the file
416427
* @return string
428+
*
429+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
417430
*/
418431
public function getThumbsPath($filePath = false)
419432
{
@@ -480,6 +493,8 @@ public function getConfigAsArray()
480493
* @param string $key
481494
* @param mixed $default
482495
* @return mixed
496+
*
497+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
483498
*/
484499
public function getConfigData($key, $default = false)
485500
{

src/app/code/core/Mage/Cms/controllers/IndexController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class Mage_Cms_IndexController extends Mage_Core_Controller_Front_Action
2525
* Renders CMS Home page
2626
*
2727
* @param string $coreRoute
28+
*
29+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2830
*/
2931
public function indexAction($coreRoute = null)
3032
{
@@ -52,6 +54,8 @@ public function defaultIndexAction()
5254
* Render CMS 404 Not found page
5355
*
5456
* @param string $coreRoute
57+
*
58+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5559
*/
5660
public function noRouteAction($coreRoute = null)
5761
{

0 commit comments

Comments
 (0)