From 08bb71c79e3717e70de6a5dd488d654625af009b Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Sat, 15 Feb 2020 11:18:49 -0600 Subject: [PATCH 01/11] Disable show ObjectManager internals with var_dump --- .../Magento/Framework/ObjectManager/ObjectManager.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php index 08a3f9939d851..dd91d1cdac6ab 100644 --- a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php +++ b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php @@ -83,4 +83,15 @@ public function configure(array $configuration) { $this->_config->extend($configuration); } + + /** + * Disable show ObjectManager internals with var_dump + * + * @see https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo + * @return array + */ + public function __debugInfo() + { + return []; + } } From 965039184a10efd974ac25d4f8b8cf38ef98aa00 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Sat, 15 Feb 2020 12:52:02 -0600 Subject: [PATCH 02/11] Export scalar/array properties for var_dump --- lib/internal/Magento/Framework/Data/Collection.php | 10 ++++++++++ lib/internal/Magento/Framework/DataObject.php | 10 ++++++++++ .../Framework/Interception/PluginList/PluginList.php | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index c497c4de5a5e4..c0e2c09e8d899 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -913,4 +913,14 @@ public function __wakeup() $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $this->_entityFactory = $objectManager->get(EntityFactoryInterface::class); } + + /** + * Export only scalar and arrays properties for var_dump + * + * @return array + */ + public function __debugInfo() + { + return array_filter(get_object_vars($this), function($v) { return is_scalar($v) || is_array($v); }); + } } diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index 6ecbca133e22a..16acc924079ff 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -540,4 +540,14 @@ public function offsetGet($offset) } return null; } + + /** + * Export only scalar and arrays properties for var_dump + * + * @return array + */ + public function __debugInfo() + { + return array_filter(get_object_vars($this), function($v) { return is_scalar($v) || is_array($v); }); + } } diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index bf1372dc007a1..3484c2c8e1497 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -408,4 +408,15 @@ private function getLogger() } return $this->logger; } + + /** + * Disable show PluginList internals with var_dump + * + * @see https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo + * @return array + */ + public function __debugInfo() + { + return []; + } } From 03f41a9c61788913e642cc433f2cabac3fe97197 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Sun, 16 Feb 2020 11:39:15 -0600 Subject: [PATCH 03/11] Fix static test --- lib/internal/Magento/Framework/Data/Collection.php | 4 +++- lib/internal/Magento/Framework/DataObject.php | 4 +++- .../Magento/Framework/ObjectManager/ObjectManager.php | 8 +++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index c0e2c09e8d899..4cdccf081de17 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -921,6 +921,8 @@ public function __wakeup() */ public function __debugInfo() { - return array_filter(get_object_vars($this), function($v) { return is_scalar($v) || is_array($v); }); + return array_filter(get_object_vars($this), function ($v) { + return is_scalar($v) || is_array($v); + }); } } diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index 16acc924079ff..1f730d81ef6a0 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -548,6 +548,8 @@ public function offsetGet($offset) */ public function __debugInfo() { - return array_filter(get_object_vars($this), function($v) { return is_scalar($v) || is_array($v); }); + return array_filter(get_object_vars($this), function ($v) { + return is_scalar($v) || is_array($v); + }); } } diff --git a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php index dd91d1cdac6ab..727a231751bc6 100644 --- a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php +++ b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php @@ -12,7 +12,9 @@ */ namespace Magento\Framework\ObjectManager; -class ObjectManager implements \Magento\Framework\ObjectManagerInterface +use Magento\Framework\ObjectManagerInterface; + +class ObjectManager implements ObjectManagerInterface { /** * @var \Magento\Framework\ObjectManager\FactoryInterface @@ -34,14 +36,14 @@ class ObjectManager implements \Magento\Framework\ObjectManagerInterface /** * @param FactoryInterface $factory * @param ConfigInterface $config - * @param array &$sharedInstances + * @param array $sharedInstances */ public function __construct(FactoryInterface $factory, ConfigInterface $config, &$sharedInstances = []) { $this->_config = $config; $this->_factory = $factory; $this->_sharedInstances = &$sharedInstances; - $this->_sharedInstances[\Magento\Framework\ObjectManagerInterface::class] = $this; + $this->_sharedInstances[ObjectManagerInterface::class] = $this; } /** From e9f51e61485ff5bf8f5b50e17e00b1255f1e8352 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Tue, 18 Feb 2020 19:45:07 -0600 Subject: [PATCH 04/11] fix static test --- .../Magento/Framework/Data/Collection.php | 20 ++++++++--------- lib/internal/Magento/Framework/DataObject.php | 22 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index 4cdccf081de17..880a1392577a0 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -163,9 +163,9 @@ public function addFilter($field, $value, $type = 'and') * * @param string|array $field * @param string|int|array $condition - * @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected. * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected. */ public function addFieldToFilter($field, $condition) { @@ -234,7 +234,7 @@ protected function _setIsLoaded($flag = true) /** * Get current collection page * - * @param int $displacement + * @param int $displacement * @return int */ public function getCurPage($displacement = 0) @@ -336,8 +336,8 @@ public function getItems() /** * Retrieve field values from all items * - * @param string $colName - * @return array + * @param string $colName + * @return array */ public function getColumnValues($colName) { @@ -353,9 +353,9 @@ public function getColumnValues($colName) /** * Search all items by field value * - * @param string $column - * @param mixed $value - * @return array + * @param string $column + * @param mixed $value + * @return array */ public function getItemsByColumnValue($column, $value) { @@ -373,9 +373,9 @@ public function getItemsByColumnValue($column, $value) /** * Search first item by field value * - * @param string $column - * @param mixed $value - * @return \Magento\Framework\DataObject || null + * @param string $column + * @param mixed $value + * @return \Magento\Framework\DataObject || null */ public function getItemByColumnValue($column, $value) { diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index 1f730d81ef6a0..861e82a118bb3 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework; /** @@ -182,8 +183,8 @@ public function getDataByKey($key) /** * Get value from _data array without parse key * - * @param string $key - * @return mixed + * @param string $key + * @return mixed */ protected function _getData($key) { @@ -262,7 +263,7 @@ public function toArray(array $keys = []) /** * The "__" style wrapper for toArray method * - * @param array $keys + * @param array $keys * @return array */ public function convertToArray(array $keys = []) @@ -318,7 +319,8 @@ public function convertToXml( $rootName = 'item', $addOpenTag = false, $addCdata = true - ) { + ) + { return $this->toXml($arrAttributes, $rootName, $addOpenTag, $addCdata); } @@ -372,8 +374,8 @@ public function toString($format = '') /** * Set/Get attribute wrapper * - * @param string $method - * @param array $args + * @param string $method + * @param array $args * @return mixed * @throws \Magento\Framework\Exception\LocalizedException */ @@ -437,10 +439,10 @@ protected function _underscore($name) * * Example: key1="value1" key2="value2" ... * - * @param array $keys array of accepted keys - * @param string $valueSeparator separator between key and value - * @param string $fieldSeparator separator between key/value pairs - * @param string $quote quoting sign + * @param array $keys array of accepted keys + * @param string $valueSeparator separator between key and value + * @param string $fieldSeparator separator between key/value pairs + * @param string $quote quoting sign * @return string */ public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"') From 8f28a8735d6d6f575c75f21696a1b4f8e8a88b12 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Tue, 18 Feb 2020 21:36:37 -0600 Subject: [PATCH 05/11] fix static test --- lib/internal/Magento/Framework/DataObject.php | 133 +++++++++--------- .../Framework/ObjectManager/ObjectManager.php | 14 +- 2 files changed, 74 insertions(+), 73 deletions(-) diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index 861e82a118bb3..023c0ca0f974a 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -46,7 +46,7 @@ public function __construct(array $data = []) * * Retains previous data in the object. * - * @param array $arr + * @param array $arr * @return $this */ public function addData(array $arr) @@ -65,8 +65,8 @@ public function addData(array $arr) * * If $key is an array, it will overwrite all the data in the object. * - * @param string|array $key - * @param mixed $value + * @param string|array $key + * @param mixed $value * @return $this */ public function setData($key, $value = null) @@ -82,7 +82,7 @@ public function setData($key, $value = null) /** * Unset data from the object. * - * @param null|string|array $key + * @param null|string|array $key * @return $this */ public function unsetData($key = null) @@ -112,8 +112,8 @@ public function unsetData($key = null) * and retrieve corresponding member. If data is the string - it will be explode * by new line character and converted to array. * - * @param string $key - * @param string|int $index + * @param string $key + * @param string|int $index * @return mixed */ public function getData($key = '', $index = null) @@ -149,7 +149,7 @@ public function getData($key = '', $index = null) * * Method consider the path as chain of keys: a/b/c => ['a']['b']['c'] * - * @param string $path + * @param string $path * @return mixed */ public function getDataByPath($path) @@ -172,7 +172,7 @@ public function getDataByPath($path) /** * Get object data by particular key * - * @param string $key + * @param string $key * @return mixed */ public function getDataByKey($key) @@ -183,7 +183,7 @@ public function getDataByKey($key) /** * Get value from _data array without parse key * - * @param string $key + * @param string $key * @return mixed */ protected function _getData($key) @@ -197,8 +197,8 @@ protected function _getData($key) /** * Set object data with calling setter method * - * @param string $key - * @param mixed $args + * @param string $key + * @param mixed $args * @return $this */ public function setDataUsingMethod($key, $args = []) @@ -211,8 +211,8 @@ public function setDataUsingMethod($key, $args = []) /** * Get object data by key with calling getter method * - * @param string $key - * @param mixed $args + * @param string $key + * @param mixed $args * @return mixed */ public function getDataUsingMethod($key, $args = null) @@ -226,7 +226,7 @@ public function getDataUsingMethod($key, $args = null) * * Otherwise checks if the specified attribute is set. * - * @param string $key + * @param string $key * @return bool */ public function hasData($key = '') @@ -240,7 +240,7 @@ public function hasData($key = '') /** * Convert array of object data with to array with keys requested in $keys array * - * @param array $keys array of required keys + * @param array $keys array of required keys * @return array */ public function toArray(array $keys = []) @@ -263,7 +263,7 @@ public function toArray(array $keys = []) /** * The "__" style wrapper for toArray method * - * @param array $keys + * @param array $keys * @return array */ public function convertToArray(array $keys = []) @@ -274,10 +274,10 @@ public function convertToArray(array $keys = []) /** * Convert object data into XML string * - * @param array $keys array of keys that must be represented - * @param string $rootName root node name - * @param bool $addOpenTag flag that allow to add initial xml node - * @param bool $addCdata flag that require wrap all values in CDATA + * @param array $keys array of keys that must be represented + * @param string $rootName root node name + * @param bool $addOpenTag flag that allow to add initial xml node + * @param bool $addCdata flag that require wrap all values in CDATA * @return string */ public function toXml(array $keys = [], $rootName = 'item', $addOpenTag = false, $addCdata = true) @@ -308,10 +308,10 @@ public function toXml(array $keys = [], $rootName = 'item', $addOpenTag = false, /** * The "__" style wrapper for toXml method * - * @param array $arrAttributes array of keys that must be represented - * @param string $rootName root node name - * @param bool $addOpenTag flag that allow to add initial xml node - * @param bool $addCdata flag that require wrap all values in CDATA + * @param array $arrAttributes array of keys that must be represented + * @param string $rootName root node name + * @param bool $addOpenTag flag that allow to add initial xml node + * @param bool $addCdata flag that require wrap all values in CDATA * @return string */ public function convertToXml( @@ -319,15 +319,14 @@ public function convertToXml( $rootName = 'item', $addOpenTag = false, $addCdata = true - ) - { + ) { return $this->toXml($arrAttributes, $rootName, $addOpenTag, $addCdata); } /** * Convert object data to JSON * - * @param array $keys array of required keys + * @param array $keys array of required keys * @return bool|string * @throws \InvalidArgumentException */ @@ -340,7 +339,7 @@ public function toJson(array $keys = []) /** * The "__" style wrapper for toJson * - * @param array $keys + * @param array $keys * @return bool|string * @throws \InvalidArgumentException */ @@ -354,7 +353,7 @@ public function convertToJson(array $keys = []) * * Will use $format as an template and substitute {{key}} for attributes * - * @param string $format + * @param string $format * @return string */ public function toString($format = '') @@ -374,28 +373,28 @@ public function toString($format = '') /** * Set/Get attribute wrapper * - * @param string $method - * @param array $args - * @return mixed + * @param string $method + * @param array $args + * @return mixed * @throws \Magento\Framework\Exception\LocalizedException */ public function __call($method, $args) { switch (substr($method, 0, 3)) { - case 'get': - $key = $this->_underscore(substr($method, 3)); - $index = isset($args[0]) ? $args[0] : null; - return $this->getData($key, $index); - case 'set': - $key = $this->_underscore(substr($method, 3)); - $value = isset($args[0]) ? $args[0] : null; - return $this->setData($key, $value); - case 'uns': - $key = $this->_underscore(substr($method, 3)); - return $this->unsetData($key); - case 'has': - $key = $this->_underscore(substr($method, 3)); - return isset($this->_data[$key]); + case 'get': + $key = $this->_underscore(substr($method, 3)); + $index = isset($args[0]) ? $args[0] : null; + return $this->getData($key, $index); + case 'set': + $key = $this->_underscore(substr($method, 3)); + $value = isset($args[0]) ? $args[0] : null; + return $this->setData($key, $value); + case 'uns': + $key = $this->_underscore(substr($method, 3)); + return $this->unsetData($key); + case 'has': + $key = $this->_underscore(substr($method, 3)); + return isset($this->_data[$key]); } throw new \Magento\Framework\Exception\LocalizedException( new \Magento\Framework\Phrase('Invalid method %1::%2', [get_class($this), $method]) @@ -421,7 +420,7 @@ public function isEmpty() * $this->setMyField($value) === $this->setData('my_field', $value) * Uses cache to eliminate unnecessary preg_replace * - * @param string $name + * @param string $name * @return string */ protected function _underscore($name) @@ -439,11 +438,11 @@ protected function _underscore($name) * * Example: key1="value1" key2="value2" ... * - * @param array $keys array of accepted keys - * @param string $valueSeparator separator between key and value - * @param string $fieldSeparator separator between key/value pairs - * @param string $quote quoting sign - * @return string + * @param array $keys array of accepted keys + * @param string $valueSeparator separator between key and value + * @param string $fieldSeparator separator between key/value pairs + * @param string $quote quoting sign + * @return string */ public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"') { @@ -464,8 +463,8 @@ public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' /** * Present object data as string in debug mode * - * @param mixed $data - * @param array &$objects + * @param mixed $data + * @param array &$objects * @return array */ public function debug($data = null, &$objects = []) @@ -494,10 +493,10 @@ public function debug($data = null, &$objects = []) /** * Implementation of \ArrayAccess::offsetSet() * - * @param string $offset - * @param mixed $value + * @param string $offset + * @param mixed $value * @return void - * @link http://www.php.net/manual/en/arrayaccess.offsetset.php + * @link http://www.php.net/manual/en/arrayaccess.offsetset.php */ public function offsetSet($offset, $value) { @@ -507,9 +506,9 @@ public function offsetSet($offset, $value) /** * Implementation of \ArrayAccess::offsetExists() * - * @param string $offset + * @param string $offset * @return bool - * @link http://www.php.net/manual/en/arrayaccess.offsetexists.php + * @link http://www.php.net/manual/en/arrayaccess.offsetexists.php */ public function offsetExists($offset) { @@ -519,9 +518,9 @@ public function offsetExists($offset) /** * Implementation of \ArrayAccess::offsetUnset() * - * @param string $offset + * @param string $offset * @return void - * @link http://www.php.net/manual/en/arrayaccess.offsetunset.php + * @link http://www.php.net/manual/en/arrayaccess.offsetunset.php */ public function offsetUnset($offset) { @@ -531,9 +530,9 @@ public function offsetUnset($offset) /** * Implementation of \ArrayAccess::offsetGet() * - * @param string $offset + * @param string $offset * @return mixed - * @link http://www.php.net/manual/en/arrayaccess.offsetget.php + * @link http://www.php.net/manual/en/arrayaccess.offsetget.php */ public function offsetGet($offset) { @@ -550,8 +549,10 @@ public function offsetGet($offset) */ public function __debugInfo() { - return array_filter(get_object_vars($this), function ($v) { - return is_scalar($v) || is_array($v); - }); + return array_filter( + get_object_vars($this), function ($v) { + return is_scalar($v) || is_array($v); + } + ); } } diff --git a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php index 727a231751bc6..1a11f29afe955 100644 --- a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php +++ b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php @@ -35,8 +35,8 @@ class ObjectManager implements ObjectManagerInterface /** * @param FactoryInterface $factory - * @param ConfigInterface $config - * @param array $sharedInstances + * @param ConfigInterface $config + * @param array $sharedInstances */ public function __construct(FactoryInterface $factory, ConfigInterface $config, &$sharedInstances = []) { @@ -49,8 +49,8 @@ public function __construct(FactoryInterface $factory, ConfigInterface $config, /** * Create new object instance * - * @param string $type - * @param array $arguments + * @param string $type + * @param array $arguments * @return mixed */ public function create($type, array $arguments = []) @@ -61,7 +61,7 @@ public function create($type, array $arguments = []) /** * Retrieve cached object instance * - * @param string $type + * @param string $type * @return mixed */ public function get($type) @@ -78,7 +78,7 @@ public function get($type) * Configure di instance * Note: All arguments should be pre-processed (sort order, translations, etc) before passing to method configure. * - * @param array $configuration + * @param array $configuration * @return void */ public function configure(array $configuration) @@ -89,7 +89,7 @@ public function configure(array $configuration) /** * Disable show ObjectManager internals with var_dump * - * @see https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo + * @see https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo * @return array */ public function __debugInfo() From 7b3296540f122a084a6eeae0ff726a9b1249bdd8 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Tue, 18 Feb 2020 21:41:49 -0600 Subject: [PATCH 06/11] fix static test --- lib/internal/Magento/Framework/DataObject.php | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index 023c0ca0f974a..570605af4333a 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -381,20 +381,20 @@ public function toString($format = '') public function __call($method, $args) { switch (substr($method, 0, 3)) { - case 'get': - $key = $this->_underscore(substr($method, 3)); - $index = isset($args[0]) ? $args[0] : null; - return $this->getData($key, $index); - case 'set': - $key = $this->_underscore(substr($method, 3)); - $value = isset($args[0]) ? $args[0] : null; - return $this->setData($key, $value); - case 'uns': - $key = $this->_underscore(substr($method, 3)); - return $this->unsetData($key); - case 'has': - $key = $this->_underscore(substr($method, 3)); - return isset($this->_data[$key]); + case 'get': + $key = $this->_underscore(substr($method, 3)); + $index = isset($args[0]) ? $args[0] : null; + return $this->getData($key, $index); + case 'set': + $key = $this->_underscore(substr($method, 3)); + $value = isset($args[0]) ? $args[0] : null; + return $this->setData($key, $value); + case 'uns': + $key = $this->_underscore(substr($method, 3)); + return $this->unsetData($key); + case 'has': + $key = $this->_underscore(substr($method, 3)); + return isset($this->_data[$key]); } throw new \Magento\Framework\Exception\LocalizedException( new \Magento\Framework\Phrase('Invalid method %1::%2', [get_class($this), $method]) @@ -550,7 +550,8 @@ public function offsetGet($offset) public function __debugInfo() { return array_filter( - get_object_vars($this), function ($v) { + get_object_vars($this), + function ($v) { return is_scalar($v) || is_array($v); } ); From 5b4d5ad2d2878366d8795d1b5ac6ad7d828c025f Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Thu, 20 Feb 2020 11:33:52 -0600 Subject: [PATCH 07/11] Fix static test test massage --- lib/internal/Magento/Framework/Data/Collection.php | 2 ++ lib/internal/Magento/Framework/DataObject.php | 2 +- .../Magento/Framework/ObjectManager/ObjectManager.php | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index 880a1392577a0..3824fee04816d 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -15,6 +15,8 @@ * TODO: Refactor use of \Magento\Framework\Option\ArrayInterface in library. * * @api + * @SuppressWarnings(PHPMD.NumberOfChildren) + * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, CollectionDataSourceInterface { diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index 570605af4333a..de036f47b2afc 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -464,7 +464,7 @@ public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' * Present object data as string in debug mode * * @param mixed $data - * @param array &$objects + * @param array $objects * @return array */ public function debug($data = null, &$objects = []) diff --git a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php index 1a11f29afe955..49d9221840ba8 100644 --- a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php +++ b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php @@ -14,6 +14,9 @@ use Magento\Framework\ObjectManagerInterface; +/** + * Base implementation Object Manager + */ class ObjectManager implements ObjectManagerInterface { /** @@ -76,6 +79,7 @@ public function get($type) /** * Configure di instance + * * Note: All arguments should be pre-processed (sort order, translations, etc) before passing to method configure. * * @param array $configuration From ae0bc66b3bd8097897e4651f25a370097252e612 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Thu, 20 Feb 2020 14:41:24 -0600 Subject: [PATCH 08/11] Fix static test test massage --- lib/internal/Magento/Framework/Data/Collection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index 3824fee04816d..facfc87f0ab90 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -15,6 +15,7 @@ * TODO: Refactor use of \Magento\Framework\Option\ArrayInterface in library. * * @api + * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.NumberOfChildren) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ From 442e3ed2a37be20d1b2b3cb523a07c5e5b39a685 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Thu, 20 Feb 2020 16:01:38 -0600 Subject: [PATCH 09/11] Fix static test test massage --- lib/internal/Magento/Framework/Data/Collection.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index facfc87f0ab90..4963358f653bf 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -15,9 +15,7 @@ * TODO: Refactor use of \Magento\Framework\Option\ArrayInterface in library. * * @api - * @SuppressWarnings(PHPMD.TooManyFields) - * @SuppressWarnings(PHPMD.NumberOfChildren) - * @SuppressWarnings(PHPMD.TooManyPublicMethods) + * @SuppressWarnings(PHPMD.ExcessivePublicCount) */ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, CollectionDataSourceInterface { From b3c8cef8c536d8435acbdd4f621b9fb07d0d965a Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Fri, 2 Oct 2020 15:04:49 -0500 Subject: [PATCH 10/11] Static test --- .../Magento/Framework/Data/Collection.php | 7 +- lib/internal/Magento/Framework/DataObject.php | 92 +++++++++---------- .../Framework/ObjectManager/ObjectManager.php | 14 +-- 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index ec49f26d958a8..ae378bbf4cc4b 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -9,8 +9,6 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\Data\Collection\EntityFactoryInterface; use Magento\Framework\DataObject; -use Magento\Framework\Exception\AlreadyExistsException; -use Magento\Framework\Option\ArrayInterface; /** * Data collection @@ -19,8 +17,10 @@ * * @api * @since 100.0.2 + * + * @SuppressWarnings(PHPMD.ExcessivePublicCount) */ -class Collection implements \IteratorAggregate, \Countable, ArrayInterface, CollectionDataSourceInterface +class Collection implements \IteratorAggregate, \Countable, OptionSourceInterface, CollectionDataSourceInterface { const SORT_ORDER_ASC = 'ASC'; @@ -767,6 +767,7 @@ protected function _toOptionArray($valueField = 'id', $labelField = 'name', $add $additional['label'] = $labelField; foreach ($this as $item) { + $data = []; foreach ($additional as $code => $field) { $data[$code] = $item->getData($field); } diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index 8cc5fa39ef6cf..c6bcc5d146af5 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Framework; /** @@ -11,7 +10,6 @@ * * @api * @SuppressWarnings(PHPMD.NumberOfChildren) - * @since 100.0.2 */ class DataObject implements \ArrayAccess { @@ -47,7 +45,7 @@ public function __construct(array $data = []) * * Retains previous data in the object. * - * @param array $arr + * @param array $arr * @return $this */ public function addData(array $arr) @@ -66,8 +64,8 @@ public function addData(array $arr) * * If $key is an array, it will overwrite all the data in the object. * - * @param string|array $key - * @param mixed $value + * @param string|array $key + * @param mixed $value * @return $this */ public function setData($key, $value = null) @@ -83,7 +81,7 @@ public function setData($key, $value = null) /** * Unset data from the object. * - * @param null|string|array $key + * @param null|string|array $key * @return $this */ public function unsetData($key = null) @@ -113,8 +111,8 @@ public function unsetData($key = null) * and retrieve corresponding member. If data is the string - it will be explode * by new line character and converted to array. * - * @param string $key - * @param string|int $index + * @param string $key + * @param string|int $index * @return mixed */ public function getData($key = '', $index = null) @@ -150,7 +148,7 @@ public function getData($key = '', $index = null) * * Method consider the path as chain of keys: a/b/c => ['a']['b']['c'] * - * @param string $path + * @param string $path * @return mixed */ public function getDataByPath($path) @@ -173,7 +171,7 @@ public function getDataByPath($path) /** * Get object data by particular key * - * @param string $key + * @param string $key * @return mixed */ public function getDataByKey($key) @@ -184,7 +182,7 @@ public function getDataByKey($key) /** * Get value from _data array without parse key * - * @param string $key + * @param string $key * @return mixed */ protected function _getData($key) @@ -198,8 +196,8 @@ protected function _getData($key) /** * Set object data with calling setter method * - * @param string $key - * @param mixed $args + * @param string $key + * @param mixed $args * @return $this */ public function setDataUsingMethod($key, $args = []) @@ -212,8 +210,8 @@ public function setDataUsingMethod($key, $args = []) /** * Get object data by key with calling getter method * - * @param string $key - * @param mixed $args + * @param string $key + * @param mixed $args * @return mixed */ public function getDataUsingMethod($key, $args = null) @@ -227,7 +225,7 @@ public function getDataUsingMethod($key, $args = null) * * Otherwise checks if the specified attribute is set. * - * @param string $key + * @param string $key * @return bool */ public function hasData($key = '') @@ -241,7 +239,7 @@ public function hasData($key = '') /** * Convert array of object data with to array with keys requested in $keys array * - * @param array $keys array of required keys + * @param array $keys array of required keys * @return array */ public function toArray(array $keys = []) @@ -264,7 +262,7 @@ public function toArray(array $keys = []) /** * The "__" style wrapper for toArray method * - * @param array $keys + * @param array $keys * @return array */ public function convertToArray(array $keys = []) @@ -275,10 +273,10 @@ public function convertToArray(array $keys = []) /** * Convert object data into XML string * - * @param array $keys array of keys that must be represented - * @param string $rootName root node name - * @param bool $addOpenTag flag that allow to add initial xml node - * @param bool $addCdata flag that require wrap all values in CDATA + * @param array $keys array of keys that must be represented + * @param string $rootName root node name + * @param bool $addOpenTag flag that allow to add initial xml node + * @param bool $addCdata flag that require wrap all values in CDATA * @return string */ public function toXml(array $keys = [], $rootName = 'item', $addOpenTag = false, $addCdata = true) @@ -309,10 +307,10 @@ public function toXml(array $keys = [], $rootName = 'item', $addOpenTag = false, /** * The "__" style wrapper for toXml method * - * @param array $arrAttributes array of keys that must be represented - * @param string $rootName root node name - * @param bool $addOpenTag flag that allow to add initial xml node - * @param bool $addCdata flag that require wrap all values in CDATA + * @param array $arrAttributes array of keys that must be represented + * @param string $rootName root node name + * @param bool $addOpenTag flag that allow to add initial xml node + * @param bool $addCdata flag that require wrap all values in CDATA * @return string */ public function convertToXml( @@ -327,7 +325,7 @@ public function convertToXml( /** * Convert object data to JSON * - * @param array $keys array of required keys + * @param array $keys array of required keys * @return bool|string * @throws \InvalidArgumentException */ @@ -340,7 +338,7 @@ public function toJson(array $keys = []) /** * The "__" style wrapper for toJson * - * @param array $keys + * @param array $keys * @return bool|string * @throws \InvalidArgumentException */ @@ -354,7 +352,7 @@ public function convertToJson(array $keys = []) * * Will use $format as an template and substitute {{key}} for attributes * - * @param string $format + * @param string $format * @return string */ public function toString($format = '') @@ -374,8 +372,8 @@ public function toString($format = '') /** * Set/Get attribute wrapper * - * @param string $method - * @param array $args + * @param string $method + * @param array $args * @return mixed * @throws \Magento\Framework\Exception\LocalizedException */ @@ -421,7 +419,7 @@ public function isEmpty() * $this->setMyField($value) === $this->setData('my_field', $value) * Uses cache to eliminate unnecessary preg_replace * - * @param string $name + * @param string $name * @return string */ protected function _underscore($name) @@ -439,10 +437,10 @@ protected function _underscore($name) * * Example: key1="value1" key2="value2" ... * - * @param array $keys array of accepted keys - * @param string $valueSeparator separator between key and value - * @param string $fieldSeparator separator between key/value pairs - * @param string $quote quoting sign + * @param array $keys array of accepted keys + * @param string $valueSeparator separator between key and value + * @param string $fieldSeparator separator between key/value pairs + * @param string $quote quoting sign * @return string */ public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"') @@ -464,8 +462,8 @@ public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' /** * Present object data as string in debug mode * - * @param mixed $data - * @param array $objects + * @param mixed $data + * @param array $objects * @return array */ public function debug($data = null, &$objects = []) @@ -494,10 +492,10 @@ public function debug($data = null, &$objects = []) /** * Implementation of \ArrayAccess::offsetSet() * - * @param string $offset - * @param mixed $value + * @param string $offset + * @param mixed $value * @return void - * @link http://www.php.net/manual/en/arrayaccess.offsetset.php + * @link http://www.php.net/manual/en/arrayaccess.offsetset.php */ public function offsetSet($offset, $value) { @@ -507,9 +505,9 @@ public function offsetSet($offset, $value) /** * Implementation of \ArrayAccess::offsetExists() * - * @param string $offset + * @param string $offset * @return bool - * @link http://www.php.net/manual/en/arrayaccess.offsetexists.php + * @link http://www.php.net/manual/en/arrayaccess.offsetexists.php */ public function offsetExists($offset) { @@ -519,9 +517,9 @@ public function offsetExists($offset) /** * Implementation of \ArrayAccess::offsetUnset() * - * @param string $offset + * @param string $offset * @return void - * @link http://www.php.net/manual/en/arrayaccess.offsetunset.php + * @link http://www.php.net/manual/en/arrayaccess.offsetunset.php */ public function offsetUnset($offset) { @@ -531,9 +529,9 @@ public function offsetUnset($offset) /** * Implementation of \ArrayAccess::offsetGet() * - * @param string $offset + * @param string $offset * @return mixed - * @link http://www.php.net/manual/en/arrayaccess.offsetget.php + * @link http://www.php.net/manual/en/arrayaccess.offsetget.php */ public function offsetGet($offset) { diff --git a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php index 49d9221840ba8..5d19a87053d69 100644 --- a/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php +++ b/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php @@ -38,8 +38,8 @@ class ObjectManager implements ObjectManagerInterface /** * @param FactoryInterface $factory - * @param ConfigInterface $config - * @param array $sharedInstances + * @param ConfigInterface $config + * @param array $sharedInstances */ public function __construct(FactoryInterface $factory, ConfigInterface $config, &$sharedInstances = []) { @@ -52,8 +52,8 @@ public function __construct(FactoryInterface $factory, ConfigInterface $config, /** * Create new object instance * - * @param string $type - * @param array $arguments + * @param string $type + * @param array $arguments * @return mixed */ public function create($type, array $arguments = []) @@ -64,7 +64,7 @@ public function create($type, array $arguments = []) /** * Retrieve cached object instance * - * @param string $type + * @param string $type * @return mixed */ public function get($type) @@ -82,7 +82,7 @@ public function get($type) * * Note: All arguments should be pre-processed (sort order, translations, etc) before passing to method configure. * - * @param array $configuration + * @param array $configuration * @return void */ public function configure(array $configuration) @@ -93,7 +93,7 @@ public function configure(array $configuration) /** * Disable show ObjectManager internals with var_dump * - * @see https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo + * @see https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo * @return array */ public function __debugInfo() From adc8ff47103849fb379c02e34032396185350256 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Wed, 7 Oct 2020 11:02:42 -0500 Subject: [PATCH 11/11] Return annotation --- lib/internal/Magento/Framework/DataObject.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/Magento/Framework/DataObject.php b/lib/internal/Magento/Framework/DataObject.php index c6bcc5d146af5..87e8830aeab0f 100644 --- a/lib/internal/Magento/Framework/DataObject.php +++ b/lib/internal/Magento/Framework/DataObject.php @@ -10,6 +10,7 @@ * * @api * @SuppressWarnings(PHPMD.NumberOfChildren) + * @since 100.0.2 */ class DataObject implements \ArrayAccess {