Skip to content

Commit

Permalink
PHPMD updates (#5)
Browse files Browse the repository at this point in the history
- closes #4
  • Loading branch information
sreichel authored Nov 30, 2023
1 parent 5df3410 commit 1733af0
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 36 deletions.
2 changes: 2 additions & 0 deletions src/app/code/core/Mage/Cms/Controller/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function initControllerRouters($observer)
*
* @param Zend_Controller_Request_Http $request
* @return bool
*
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function match(Zend_Controller_Request_Http $request)
{
Expand Down
6 changes: 6 additions & 0 deletions src/app/code/core/Mage/Cms/Helper/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function renderPage(Mage_Core_Controller_Front_Action $action, $pageId =
* @param string $pageId
* @param bool $renderLayout
* @return bool
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
{
Expand Down Expand Up @@ -137,6 +141,8 @@ protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pag
* @param string $pageId
* @param bool $renderLayout
* @return bool
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function renderPageExtended(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true)
{
Expand Down
16 changes: 10 additions & 6 deletions src/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ public function convertPathToId($path)
/**
* Decode HTML element id
*
* @param string $id
* @param string $elementId
* @return string
*/
public function convertIdToPath($id)
public function convertIdToPath($elementId)
{
$path = $this->idDecode($id);
$path = $this->idDecode($elementId);
$storageRoot = realpath($this->getStorageRoot());
if (!strstr($path, $storageRoot)) {
$path = $storageRoot . DS . $path;
Expand All @@ -134,6 +134,8 @@ public function convertIdToPath($id)
* @param string $path Original path
* @param bool $trim Trim slashes or not
* @return string
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function correctPath($path, $trim = true)
{
Expand Down Expand Up @@ -177,6 +179,8 @@ public function isUsingStaticUrlsAllowed()
* @param string $filename Filename transferred via Ajax
* @param bool $renderAsTag Leave image HTML as is or transform it to controller directive
* @return string
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getImageHtmlDeclaration($filename, $renderAsTag = false)
{
Expand Down Expand Up @@ -214,11 +218,11 @@ public function getCurrentPath()
$currentPath = $path;
}
}
$io = new Varien_Io_File();
if (!$io->isWriteable($currentPath) && !$io->mkdir($currentPath)) {
$file = new Varien_Io_File();
if (!$file->isWriteable($currentPath) && !$file->mkdir($currentPath)) {
$message = Mage::helper('cms')->__(
'The directory %s is not writable by server.',
$io->getFilteredPath($currentPath)
$file->getFilteredPath($currentPath)
);
Mage::throwException($message);
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/code/core/Mage/Cms/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class Mage_Cms_Model_Page extends Mage_Core_Model_Abstract
/**
* Page's Statuses
*/
public const STATUS_ENABLED = 1;
public const STATUS_ENABLED = 1;
public const STATUS_DISABLED = 0;

public const CACHE_TAG = 'cms_page';
public const CACHE_TAG = 'cms_page';
protected $_cacheTag = 'cms_page';

/**
Expand All @@ -93,12 +93,12 @@ protected function _construct()
/**
* @inheritDoc
*/
public function load($id, $field = null)
public function load($value, $field = null)
{
if (is_null($id)) {
if (is_null($value)) {
return $this->noRoutePage();
}
return parent::load($id, $field);
return parent::load($value, $field);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/app/code/core/Mage/Cms/Model/Resource/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ protected function _getLoadSelect($field, $value, $object)
*
* @param Mage_Core_Model_Abstract $object
* @return bool
*
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object)
{
Expand Down Expand Up @@ -191,10 +193,10 @@ public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object)
/**
* Get store ids to which specified item is assigned
*
* @param int $id
* @param int $blockId
* @return array
*/
public function lookupStoreIds($id)
public function lookupStoreIds($blockId)
{
$adapter = $this->_getReadAdapter();

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

$binds = [
':block_id' => (int) $id
':block_id' => (int) $blockId
];

return $adapter->fetchCol($select, $binds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function toOptionArray()
* @param int|Mage_Core_Model_Store $store
* @param bool $withAdmin
* @return $this
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function addStoreFilter($store, $withAdmin = true)
{
Expand Down
14 changes: 8 additions & 6 deletions src/app/code/core/Mage/Cms/Model/Resource/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ protected function _getLoadByIdentifierSelect($identifier, $store, $isActive = n
*
* @param Mage_Core_Model_Abstract|Mage_Cms_Model_Page $object
* @return bool
*
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getIsUniquePageToStores(Mage_Core_Model_Abstract $object)
{
Expand Down Expand Up @@ -306,10 +308,10 @@ public function getCmsPageTitleByIdentifier($identifier)
/**
* Retrieves cms page title from DB by passed id.
*
* @param string $id
* @param string $pageId
* @return string
*/
public function getCmsPageTitleById($id)
public function getCmsPageTitleById($pageId)
{
$adapter = $this->_getReadAdapter();

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

$binds = [
'page_id' => (int) $id
'page_id' => (int) $pageId
];

return $adapter->fetchOne($select, $binds);
Expand All @@ -327,10 +329,10 @@ public function getCmsPageTitleById($id)
/**
* Retrieves cms page identifier from DB by passed id.
*
* @param string $id
* @param string $pageId
* @return string|false
*/
public function getCmsPageIdentifierById($id)
public function getCmsPageIdentifierById($pageId)
{
$adapter = $this->_getReadAdapter();

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

$binds = [
'page_id' => (int) $id
'page_id' => (int) $pageId
];

return $adapter->fetchOne($select, $binds);
Expand Down
5 changes: 5 additions & 0 deletions src/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function toOptionIdArray()
foreach ($this as $item) {
$identifier = $item->getData('identifier');

$data = [];
$data['value'] = $identifier;
$data['label'] = $item->getData('title');

Expand All @@ -82,6 +83,8 @@ public function toOptionIdArray()
*
* @param bool $flag
* @return $this
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function setFirstStoreFlag($flag = false)
{
Expand Down Expand Up @@ -131,6 +134,8 @@ protected function _afterLoad()
* @param int|Mage_Core_Model_Store $store
* @param bool $withAdmin
* @return $this
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function addStoreFilter($store, $withAdmin = true)
{
Expand Down
47 changes: 31 additions & 16 deletions src/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
* @category Mage
* @package Mage_Cms
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Mage_Cms_Model_Wysiwyg_Images_Storage extends Varien_Object
{
Expand All @@ -44,6 +46,9 @@ class Mage_Cms_Model_Wysiwyg_Images_Storage extends Varien_Object
*
* @param string $path Parent directory path
* @return Varien_Data_Collection_Filesystem
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function getDirsCollection($path)
{
Expand Down Expand Up @@ -190,8 +195,8 @@ public function createDirectory($name, $path)
Mage::throwException(Mage::helper('cms')->__('A directory with the same name already exists. Please try another folder name.'));
}

$io = new Varien_Io_File();
if ($io->mkdir($newPath)) {
$file = new Varien_Io_File();
if ($file->mkdir($newPath)) {
if (Mage::helper('core/file_storage_database')->checkDbUsage()) {
$relativePath = Mage::helper('core/file_storage_database')->getMediaRelativePath($newPath);
Mage::getModel('core/file_storage_directory_database')->createRecursive($relativePath);
Expand All @@ -218,12 +223,12 @@ public function deleteDirectory($path)
$rootCmp = rtrim($this->getHelper()->getStorageRoot(), DS);
$pathCmp = rtrim($path, DS);

$io = new Varien_Io_File();
$file = new Varien_Io_File();

if ($rootCmp == $pathCmp) {
Mage::throwException(Mage::helper('cms')->__(
'Cannot delete root directory %s.',
$io->getFilteredPath($path)
$file->getFilteredPath($path)
));
}
if (str_contains($pathCmp, chr(0))
Expand All @@ -235,12 +240,12 @@ public function deleteDirectory($path)
if (Mage::helper('core/file_storage_database')->checkDbUsage()) {
Mage::getModel('core/file_storage_directory_database')->deleteDirectory($path);
}
if (!$io->rmdir($path, true)) {
Mage::throwException(Mage::helper('cms')->__('Cannot delete directory %s.', $io->getFilteredPath($path)));
if (!$file->rmdir($path, true)) {
Mage::throwException(Mage::helper('cms')->__('Cannot delete directory %s.', $file->getFilteredPath($path)));
}

if (str_starts_with($pathCmp, $rootCmp)) {
$io->rmdir($this->getThumbnailRoot() . DS . ltrim(substr($pathCmp, strlen($rootCmp)), '\\/'), true);
$file->rmdir($this->getThumbnailRoot() . DS . ltrim(substr($pathCmp, strlen($rootCmp)), '\\/'), true);
}
}

Expand All @@ -252,13 +257,13 @@ public function deleteDirectory($path)
*/
public function deleteFile($target)
{
$io = new Varien_Io_File();
$io->rm($target);
$file = new Varien_Io_File();
$file->rm($target);
Mage::helper('core/file_storage_database')->deleteFile($target);

$thumb = $this->getThumbnailPath($target, true);
if ($thumb) {
$io->rm($thumb);
$file->rm($thumb);
Mage::helper('core/file_storage_database')->deleteFile($thumb);
}
return $this;
Expand Down Expand Up @@ -311,9 +316,11 @@ public function uploadFile($targetPath, $type = null)
/**
* Thumbnail path getter
*
* @param string $filePath original file path
* @param string $filePath original file path
* @param bool $checkFile OPTIONAL is it necessary to check file availability
* @return string | false
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getThumbnailPath($filePath, $checkFile = false)
{
Expand All @@ -333,9 +340,11 @@ public function getThumbnailPath($filePath, $checkFile = false)
/**
* Thumbnail URL getter
*
* @param string $filePath original file path
* @param string $filePath original file path
* @param bool $checkFile OPTIONAL is it necessary to check file availability
* @return string|false
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getThumbnailUrl($filePath, $checkFile = false)
{
Expand All @@ -358,6 +367,8 @@ public function getThumbnailUrl($filePath, $checkFile = false)
* @param string $source Image path to be resized
* @param bool $keepRation Keep aspect ratio or not
* @return bool|string Resized filepath or false if errors were occurred
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function resizeFile($source, $keepRation = true)
{
Expand All @@ -366,11 +377,11 @@ public function resizeFile($source, $keepRation = true)
}

$targetDir = $this->getThumbsPath($source);
$io = new Varien_Io_File();
if (!$io->isWriteable($targetDir)) {
$io->mkdir($targetDir);
$file = new Varien_Io_File();
if (!$file->isWriteable($targetDir)) {
$file->mkdir($targetDir);
}
if (!$io->isWriteable($targetDir)) {
if (!$file->isWriteable($targetDir)) {
return false;
}
$image = Varien_Image_Adapter::factory('GD2');
Expand Down Expand Up @@ -414,6 +425,8 @@ public function resizeOnTheFly($filename)
*
* @param false|string $filePath Path to the file
* @return string
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getThumbsPath($filePath = false)
{
Expand Down Expand Up @@ -480,6 +493,8 @@ public function getConfigAsArray()
* @param string $key
* @param mixed $default
* @return mixed
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getConfigData($key, $default = false)
{
Expand Down
4 changes: 4 additions & 0 deletions src/app/code/core/Mage/Cms/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Mage_Cms_IndexController extends Mage_Core_Controller_Front_Action
* Renders CMS Home page
*
* @param string $coreRoute
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function indexAction($coreRoute = null)
{
Expand Down Expand Up @@ -52,6 +54,8 @@ public function defaultIndexAction()
* Render CMS 404 Not found page
*
* @param string $coreRoute
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function noRouteAction($coreRoute = null)
{
Expand Down

0 comments on commit 1733af0

Please sign in to comment.