Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mage_Api - IDE improvements #677

Closed
wants to merge 11 commits into from
5 changes: 4 additions & 1 deletion app/code/core/Mage/Api/Controller/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@
*/
class Mage_Api_Controller_Action extends Mage_Core_Controller_Front_Action
{
/**
* @return $this
*/
public function preDispatch()
{
$this->getLayout()->setArea('adminhtml');
Mage::app()->setCurrentStore('admin');
$this->setFlag('', self::FLAG_NO_START_SESSION, 1); // Do not start standart session
$this->setFlag('', self::FLAG_NO_START_SESSION, 1); // Do not start standard session
parent::preDispatch();
return $this;
}
Expand Down
11 changes: 8 additions & 3 deletions app/code/core/Mage/Api/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ class Mage_Api_Exception extends Mage_Core_Exception
{
protected $_customMessage = null;

public function __construct($faultCode, $customMessage=null)
/**
* Mage_Api_Exception constructor.
* @param string $faultCode
* @param string|null $customMessage
*/
public function __construct($faultCode, $customMessage = null)
{
parent::__construct($faultCode);
$this->_customMessage = $customMessage;
Expand All @@ -44,10 +49,10 @@ public function __construct($faultCode, $customMessage=null)
/**
* Custom error message, if error is not in api.
*
* @return unknown
* @return string
*/
public function getCustomMessage()
{
return $this->_customMessage;
}
} // Class Mage_Api_Model_Resource_Exception End
}
13 changes: 6 additions & 7 deletions app/code/core/Mage/Api/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function isComplianceWSI()
* Go through a WSI args array and turns it to correct state.
*
* @param Object $obj - Link to Object
* @return Object
*/
public function wsiArrayUnpacker(&$obj)
{
Expand Down Expand Up @@ -89,8 +88,8 @@ public function wsiArrayUnpacker(&$obj)
/**
* Go through an object parameters and unpack associative object to array.
*
* @param Object $obj - Link to Object
* @return Object
* @param Object|array $obj - Link to Object
* @return bool
*/
public function v2AssociativeArrayUnpacker(&$obj)
{
Expand Down Expand Up @@ -167,7 +166,7 @@ public function associativeArrayUnpack(&$mixed)
* Corrects data representation.
*
* @param Object $obj - Link to Object
* @return Object
* @return array
*/
public function clearWsiFootprints(&$obj)
{
Expand Down Expand Up @@ -222,10 +221,10 @@ public function wsiArrayPacker($mixed)
/**
* For response to the WSI, generates an object from array.
*
* @param Array $arr - Link to Object
* @return Object
* @param array $arr - Link to Object
* @return stdClass
*/
public function packArrayToObject(Array $arr)
public function packArrayToObject(array $arr)
{
$obj = new stdClass();
$obj->complexObjectArray = $arr;
Expand Down
10 changes: 10 additions & 0 deletions app/code/core/Mage/Api/Helper/Object/Role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE unrelated change (new code?)

Copy link
Contributor Author

@sreichel sreichel Jun 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposal. See #687. Should not break anything.


/**
* Class Mage_Api_Helper_Object_Role
*
* @method int getTreeLevel()
*/
class Mage_Api_Helper_Object_Role extends Varien_Object
{
}
15 changes: 15 additions & 0 deletions app/code/core/Mage/Api/Helper/Object/Wsdl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE unrelated change (new code)

Copy link
Contributor Author

@sreichel sreichel Jun 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposal. See #687. Should not break anything.


/**
* Class Mage_Api_Object_Wsdl
*
* @method string getName()
* @method $this setName(string $value)
* @method $this setHandler(string $value)
* @method string getUrl()
* @method $this setUrl(string $value)
* @method string getWsdlContent()
*/
class Mage_Api_Helper_Object_Wsdl extends Varien_Object
{
}
4 changes: 2 additions & 2 deletions app/code/core/Mage/Api/Model/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ protected function _getRoleRegistry()
/**
* Add parent to role object
*
* @param Zend_Acl_Role $role
* @param Zend_Acl_Role $parent
* @param Zend_Acl_Role_Interface|string $role
* @param array|Zend_Acl_Role_Interface|string $parent
* @return $this
*/
public function addRoleParent($role, $parent)
Expand Down
9 changes: 6 additions & 3 deletions app/code/core/Mage/Api/Model/Acl/Assert/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Mage_Api_Model_Acl_Assert_Ip implements Zend_Acl_Assert_Interface
/**
* Check whether ip is allowed
*
* @param Zend_Acl $acl
* @param Zend_Acl_Role_Interface $role
* @param Zend_Acl_Resource_Interface $resource
* @param Mage_Api_Model_Acl $acl
* @param Mage_Api_Model_Acl_Role $role
* @param Mage_Api_Model_Acl_Resource $resource
* @param string $privilege
* @return boolean
*/
Expand All @@ -49,6 +49,9 @@ public function assert(Mage_Api_Model_Acl $acl, Mage_Api_Model_Acl_Role $role =
return $this->_isCleanIP(Mage::helper('core/http')->getRemoteAddr());
}

/**
* @param $ip
*/
protected function _isCleanIP($ip)
{
// ...
Expand Down
9 changes: 6 additions & 3 deletions app/code/core/Mage/Api/Model/Acl/Assert/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Mage_Api_Model_Acl_Assert_Time implements Zend_Acl_Assert_Interface
/**
* Assert time
*
* @param Zend_Acl $acl
* @param Zend_Acl_Role_Interface $role
* @param Zend_Acl_Resource_Interface $resource
* @param Mage_Api_Model_Acl $acl
* @param Mage_Api_Model_Acl_Role $role
* @param Mage_Api_Model_Acl_Resource $resource
* @param string $privilege
* @return boolean
*/
Expand All @@ -49,6 +49,9 @@ public function assert(Mage_Api_Model_Acl $acl, Mage_Api_Model_Acl_Role $role =
return $this->_isCleanTime(time());
}

/**
* @param $time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no benefit without type for IDE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method has no content. Just supress PHPStorm warning ;)

*/
protected function _isCleanTime($time)
{
// ...
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Api/Model/Acl/Role/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Mage_Api_Model_Acl_Role_Registry extends Zend_Acl_Role_Registry
*
* @param Zend_Acl_Role_Interface|string $role
* @param array|Zend_Acl_Role_Interface|string $parents
* @return Mage_Auth_Model_Acl_Role_Registry
* @return $this
*/
function addParent($role, $parents)
{
Expand Down
49 changes: 33 additions & 16 deletions app/code/core/Mage/Api/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ class Mage_Api_Model_Config extends Varien_Simplexml_Config
const CACHE_TAG = 'config_api';

/**
* Constructor
*
* @see Varien_Simplexml_Config
* @inheritDoc
*/
public function __construct($sourceData=null)
public function __construct($sourceData = null)
{
$this->setCacheId('config_api');
$this->setCacheTags(array(self::CACHE_TAG));
Expand Down Expand Up @@ -99,7 +97,7 @@ public function getAdapters()
{
$adapters = array();
foreach ($this->getNode('adapters')->children() as $adapterName => $adapter) {
/* @var $adapter Varien_SimpleXml_Element */
/* @var Varien_SimpleXml_Element $adapter */
if (isset($adapter->use)) {
$adapter = $this->getNode('adapters/' . (string) $adapter->use);
}
Expand Down Expand Up @@ -138,7 +136,7 @@ public function getActiveAdapters()
/**
* Retrieve handlers
*
* @return Varien_Simplexml_Element
* @return SimpleXMLElement
*/
public function getHandlers()
{
Expand All @@ -148,7 +146,7 @@ public function getHandlers()
/**
* Retrieve resources
*
* @return Varien_Simplexml_Element
* @return SimpleXMLElement
*/
public function getResources()
{
Expand All @@ -158,7 +156,7 @@ public function getResources()
/**
* Retrieve resources alias
*
* @return Varien_Simplexml_Element
* @return SimpleXMLElement
*/
public function getResourcesAlias()
{
Expand All @@ -174,7 +172,7 @@ public function getResourcesAlias()
* @param string $parentName
* @return $this
*/
public function loadAclResources(Mage_Api_Model_Acl $acl, $resource=null, $parentName=null)
public function loadAclResources(Mage_Api_Model_Acl $acl, $resource = null, $parentName = null)
{
$resourceName = null;
if (is_null($resource)) {
Expand Down Expand Up @@ -202,7 +200,7 @@ public function loadAclResources(Mage_Api_Model_Acl $acl, $resource=null, $paren
* Get acl assert config
*
* @param string $name
* @return Mage_Core_Model_Config_Element|boolean
* @return bool|Mage_Core_Model_Config_Element|SimpleXMLElement
*/
public function getAclAssert($name='')
{
Expand All @@ -222,12 +220,12 @@ public function getAclAssert($name='')
* Retrieve privilege set by name
*
* @param string $name
* @return Mage_Core_Model_Config_Element|boolean
* @return bool|Mage_Core_Model_Config_Element|SimpleXMLElement
*/
public function getAclPrivilegeSet($name='')
public function getAclPrivilegeSet($name = '')
{
$sets = $this->getNode('acl/privilegeSets');
if (''===$name) {
if ('' === $name) {
return $sets;
}

Expand All @@ -238,7 +236,11 @@ public function getAclPrivilegeSet($name='')
return false;
}

public function getFaults($resourceName=null)
/**
* @param string|null $resourceName
* @return array
*/
public function getFaults($resourceName = null)
{
if (is_null($resourceName)
|| !isset($this->getResources()->$resourceName)
Expand All @@ -247,7 +249,7 @@ public function getFaults($resourceName=null)
} else {
$faultsNode = $this->getResources()->$resourceName->faults;
}
/* @var $faultsNode Varien_Simplexml_Element */
/* @var Varien_Simplexml_Element $faultsNode */

$translateModule = 'api';
if (isset($faultsNode['module'])) {
Expand All @@ -268,23 +270,38 @@ public function getFaults($resourceName=null)
/**
* Retrieve cache object
*
* @return Zend_Cache_Frontend_File
* @return Zend_Cache_Core
*/
public function getCache()
{
return Mage::app()->getCache();
}

/**
* @param string $id
* @return bool|mixed
*/
protected function _loadCache($id)
{
return Mage::app()->loadCache($id);
}

/**
* @param string $data
* @param string $id
* @param array $tags
* @param bool $lifetime
* @return bool|Mage_Core_Model_App
*/
protected function _saveCache($data, $id, $tags=array(), $lifetime=false)
{
return Mage::app()->saveCache($data, $id, $tags, $lifetime);
}

/**
* @param string $id
* @return Mage_Core_Model_App
*/
protected function _removeCache($id)
{
return Mage::app()->removeCache($id);
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Api/Model/Resource/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ protected function _getServer()
* Dispatches fault
*
* @param string $code
* @param string|null $customMessage
* @throws Mage_Api_Exception
*/
protected function _fault($code, $customMessage=null)
protected function _fault($code, $customMessage = null)
{
throw new Mage_Api_Exception($code, $customMessage);
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Api/Model/Resource/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public function loadAcl()
* Load roles
*
* @param Mage_Api_Model_Acl $acl
* @param array $rolesArr
* @param array[] $rolesArr
* @return $this
*/
public function loadRoles(Mage_Api_Model_Acl $acl, array $rolesArr)
{
foreach ($rolesArr as $role) {
$parent = $role['parent_id']>0 ? Mage_Api_Model_Acl::ROLE_TYPE_GROUP.$role['parent_id'] : null;
$parent = $role['parent_id']>0 ? Mage_Api_Model_Acl::ROLE_TYPE_GROUP.$role['parent_id'] : '';
switch ($role['role_type']) {
case Mage_Api_Model_Acl::ROLE_TYPE_GROUP:
$roleId = $role['role_type'].$role['role_id'];
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Api/Model/Resource/Acl/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
/**
* ACL role resource
*
* @method $this setCreated(string $value)
*
* @category Mage
* @package Mage_Api
* @author Magento Core Team <core@magentocommerce.com>
Expand Down
9 changes: 2 additions & 7 deletions app/code/core/Mage/Api/Model/Resource/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function _construct()
/**
* Action before save
*
* @param Mage_Core_Model_Abstract $object
* @param Mage_Core_Model_Abstract|Mage_Api_Model_Role $object
* @return $this
*/
protected function _beforeSave(Mage_Core_Model_Abstract $object)
Expand All @@ -59,12 +59,7 @@ protected function _beforeSave(Mage_Core_Model_Abstract $object)
}

/**
* Load an object
*
* @param Mage_Core_Model_Abstract $object
* @param mixed $value
* @param string $field field to load by (defaults to model id)
* @return Mage_Core_Model_Resource_Db_Abstract
* @inheritDoc
*/
public function load(Mage_Core_Model_Abstract $object, $value, $field = null)
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Api/Model/Resource/Role/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function _construct()
/**
* Aet user filter
*
* @param int $userId
* @param int|string $userId
* @return $this
*/
public function setUserFilter($userId)
Expand Down
Loading