Skip to content

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

Closed
wants to merge 6 commits into from
Closed

Avoid checking source,target type multiple times #9270

wants to merge 6 commits into from

Conversation

sivajik34
Copy link
Contributor

We can check only one time type of source or target.
Present code we are checking source ,target type for each field unnecessarily.

@@ -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);
Copy link
Contributor

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:

  1. 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() {}

    ...
}
  1. 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.

Copy link
Contributor Author

@sivajik34 sivajik34 Apr 17, 2017

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);
    }

}

@vrann
Copy link
Contributor

vrann commented Apr 17, 2017

@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 vrann added this to the April 2017 milestone Apr 17, 2017
@vrann vrann self-assigned this Apr 17, 2017
@sivajik34
Copy link
Contributor Author

@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.

@orlangur
Copy link
Contributor

orlangur commented Apr 17, 2017

What is the performance benefit of such change? Are there any other benefits besides performance?

/home/travis/build/magento/magento2/lib/internal/Magento/Framework/DataObject/Copy.php:62	
The method copyFieldsetToTarget() has a Cyclomatic Complexity of 86. The configured cyclomatic complexity threshold is 10.
/home/travis/build/magento/magento2/lib/internal/Magento/Framework/DataObject/Copy.php:62	
The method copyFieldsetToTarget() has an NPath complexity of 2106. The configured NPath complexity threshold is 200.

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
Copy link
Contributor Author

@orlangur I agreed.I know its not acceptable.based on @vrann i will try to implement without any PHPMD violations.I don't know PHPMD violations and all.but i try to learn & want contribute something to Magento.
I'm a l just beginner in this area.I always welcome your feedback also.

@orlangur
Copy link
Contributor

@sivajik34 no problem, we all are learning here :) Good luck with making PHPMD happy about your changes.

@vrann
Copy link
Contributor

vrann commented May 8, 2017

@sivajik34 Hi, do you expect to do more changes soon to this PR?

@okorshenko okorshenko modified the milestones: April 2017, May 2017 May 9, 2017
@sivajik34
Copy link
Contributor Author

@vrann Yes,I want but no idea how to move further.

@okorshenko okorshenko modified the milestones: May 2017, June 2017 Jun 1, 2017
@okorshenko okorshenko self-assigned this Jun 9, 2017
@okorshenko
Copy link
Contributor

Closing this PR due to inactivity. @sivajik34 Please create new PR when ready.

@okorshenko okorshenko closed this Jun 9, 2017
magento-devops-reposync-svc pushed a commit that referenced this pull request Oct 8, 2024
…ws-league-flysystem

Update league/flysystem-v3 lib to ^3.0 version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants