-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Avoid checking source,target type multiple times #9270
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
Conversation
@@ -61,28 +61,240 @@ public function __construct( | |||
*/ | |||
public function copyFieldsetToTarget($fieldset, $aspect, $source, $target, $root = 'global') | |||
{ | |||
if (!$this->_isFieldsetInputValid($source, $target)) { | |||
$sourceIsArray = is_array($source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method becomes much more complex than it should be. There is duplication of logic and the complexity of the method increases.
You can do following:
- wrap the information about isDataObject, isExtensible, etc in some simple class, i.e. and pass this object as input to the methods, where currently object is passed.
class DataObjectTypeWrapper {
public function __construct($object) {}
public function getObject() {}
public function isDataObject() {}
...
}
- Move every "if" body to a separate method (and potentially separate class) which accepts the DataOjectTypeWrapper. There are a lot of duplication of logic right now which an be avoided by re-suing those methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vrann
Regarding 2nd point:I'm not getting to avoid duplication.
we need create separate class or method for inner if loop,or outer if loop?
maybe I'm not getting your implementation thoughts on this.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Utility class for checking type of object
*/
namespace Magento\Framework\DataObject;
class DataObjectTypeWrapper {
private $dataObject;
public function __construct($object) {
$this->dataObject = $object;
}
public function getObject() {
return $this->dataObject;
}
public function isArray() {
return is_array($this->dataObject);
}
public function isDataObject() {
return ($this->dataObject instanceof \Magento\Framework\DataObject);
}
public function isExtensible() {
return ($this->dataObject instanceof \Magento\Framework\Api\ExtensibleDataInterface);
}
public function isAbstractSimple() {
return ($this->dataObject instanceof \Magento\Framework\Api\AbstractSimpleObject);
}
}
@sivajik34 Thank you for the contribution. This is a good intent. I have few comments to implementation. Also, would you mind squashing commits and force-pushing the branch? There are a lot of commits under the PR. |
@vrann Thank you for your response.I don't mind squashing commits and force-pushing the branch.I will try my best to refactor using your suggestions. |
What is the performance benefit of such change? Are there any other benefits besides performance?
This does not look like an acceptable refactoring generally, it is better to check builds on Travis CI prior to PR creation and eliminate all PHPMD violations. |
@sivajik34 no problem, we all are learning here :) Good luck with making PHPMD happy about your changes. |
@sivajik34 Hi, do you expect to do more changes soon to this PR? |
@vrann Yes,I want but no idea how to move further. |
Closing this PR due to inactivity. @sivajik34 Please create new PR when ready. |
…ws-league-flysystem Update league/flysystem-v3 lib to ^3.0 version
We can check only one time type of source or target.
Present code we are checking source ,target type for each field unnecessarily.