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

Fix #10583: Checkout place order exception when using a new address #11556

Merged
merged 1 commit into from Nov 7, 2017

Conversation

joni-jones
Copy link
Contributor

Fixed Issues

  1. Checkout place order exception when using a new address #10583: Checkout place order exception when using a new address

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@@ -25,6 +27,12 @@ class TypeProcessorTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
$this->_typeProcessor = new \Magento\Framework\Reflection\TypeProcessor();
$loader = new ClassLoader();
$loader->addPsr4(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to hack autoloader instead of placing fixtures accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To do not use _files word in the class namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to use _files and do manual include. Just place fixtures in something like lib/internal/Magento/Framework/Reflection/Test/Unit/TypeProcessorTest/Fixture/TSample.php.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you open integration or unit tests you will see all fixtures located in _files directory. I don't want to change such "standard".

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no such standard. I remember such cases in integration tests just because there is no class usually.

When we can make our code PSR-4 compliant we should do so. Please remove unnecessary ClassLoader complication, other _files occurrences containing PHP classes should be considered as technical debt.

class TSample implements TSampleInterface
{
/**
* {@inheritdoc}
Copy link
Contributor

@orlangur orlangur Oct 19, 2017

Choose a reason for hiding this comment

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

Such syntax only inherits method description, not type hints for parameters and return value.

See https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md#61-making-inheritance-explicit-using-the-inheritdoc-tag

Please change implementation in such a way that we do not allow misuse of syntax with curly braces and only inherit return/param in case of @inheritdoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to Magento internal guidelines, this annotation should look like {@inheritdoc}.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From internal Magento wiki but I agree with @inheritdoc usage, even I think it's better to use it.
screenshot from 2017-10-19 15-38-51

Copy link
Contributor

Choose a reason for hiding this comment

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

Great 👍 Yeah, seems to be some outdated documentation, please change/remove it or delegate this to whoever is in charge of it.

@@ -393,7 +393,7 @@ protected function _getCustomerDataArray()
\Magento\Customer\Model\Data\Customer::DOB => '2014-02-03 00:00:00',
\Magento\Customer\Model\Data\Customer::EMAIL => 'qa@example.com',
\Magento\Customer\Model\Data\Customer::FIRSTNAME => 'Joe',
\Magento\Customer\Model\Data\Customer::GENDER => 'Male',
\Magento\Customer\Model\Data\Customer::GENDER => 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed fixture implementation according to interface doc block annotation https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Customer/Api/Data/CustomerInterface.php#L269. After replacing get_class by namespace this fixture breaks test.

@joni-jones
Copy link
Contributor Author

joni-jones commented Oct 20, 2017

The class complexity is 103 but Codacy configured complexity threshold is 50.

@orlangur
Copy link
Contributor

@joni-jones I don't think we should any suppressions when testCodeMess is passed but Codacy complains.

@joni-jones
Copy link
Contributor Author

joni-jones commented Oct 20, 2017

@orlangur, this class has 7 deprecated methods, which increase complexity, I can't them remove because it will be BIC. Magento class complexity configured as 100 (https://github.com/magento/magento2/blob/2.2-develop/dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml#L24) but codacy complexity is 50. So without full refactoring, the codacy test for this class will never be green.

@orlangur
Copy link
Contributor

@joni-jones do you mean green in Travis or green in Codacy? The latter is pretty odd, like forbidding else usage, contains TooLongVariable rule which was intentionally removed from Magento PHPMD ruleset.

@joni-jones
Copy link
Contributor Author

I mean green Codacy. Removing deprecated methods will decrease complexity, but the class also requires refactoring like the composition usage, unit tests. I think it should be done in some release but not in a patch release and not during this bug fix.

$parentClassReflection->getMethod($methodName)
);

break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently logic of this cycle is not so easy to understand. I suggest something like

foreach (...) {
    if ($parent...->hasMethod()) {
        $returnAnnotations = ...;
        break;
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't see it :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please, see a list of changed files, I amended commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I was answering to next thread actually O.o

$methodDocBlock = $methodReflection->getDocBlock();
if (!$methodDocBlock) {
throw new \InvalidArgumentException(
"Each getter must have dock block. "
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo dock -> doc. "have a doc block"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@orlangur orlangur Oct 20, 2017

Choose a reason for hiding this comment

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

  •            "Each getter must have a dock block. "
    

I meant don't see this changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

"dock" is correct spelling? I was not certain regarding "a" but "dock" seems to be not correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure. Fixed.

}

/**
* @inheritdoc
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be really nice to add test case with {@inheritdoc} to make it explicit such syntax is not supposed to work. I do not insist though, this PR is already excellent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but a lot of Magento code has such annotation. The current unit test covers such case for parsing return tag because the behavior just checks if a method has @return annotation.

Copy link
Contributor

Choose a reason for hiding this comment

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

a lot of Magento code has such annotation

We should fix it anyway. Not saying it must be a scope of this PR, but it could be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely agree, even more, I think there should be a static test which won't allow adding this annotation.

@orlangur
Copy link
Contributor

@joni-jones ok, thanks. According to my understanding we should ignore invalid Codacy complaints but I'm not sure if we have a requirement to make it green (especially when "making green" is just adding suppression).

Please remove this suppression if it is not mandatory to make Codacy green.

@joni-jones
Copy link
Contributor Author

This suppress needed for Travis and Bamboo builds because the class has complexity 103, after small refactoring, without changing functionality I've got - 101. To reduce it need to remove deprecated methods and do deep refactoring.

@orlangur
Copy link
Contributor

Aaah, ok. So green Bamboo actually, thanks. I'll raise a topic regarding Codacy in Slack, we should do something to it.

 - Added doc block parsing for interceptors
@okorshenko okorshenko modified the milestones: October 2017, November 2017 Nov 1, 2017
@okorshenko okorshenko merged commit fea77c7 into magento:2.2-develop Nov 7, 2017
okorshenko pushed a commit that referenced this pull request Nov 7, 2017
@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Nov 7, 2017
Copy link

@VoidWalker VoidWalker left a comment

Choose a reason for hiding this comment

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

Missing inheridocs from extended classes

$returnAnnotations = $this->getReturnFromDocBlock($methodReflection);
if (empty($returnAnnotations)) {
// method can inherit doc block from implemented interface, like for interceptors
$implemented = $methodReflection->getDeclaringClass()->getInterfaces();

Choose a reason for hiding this comment

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

Sir, you're missing docs from extended class here. $methodReflection->getDeclaringClass()->getParentClass() should be included in this array

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @VoidWalker, please report an issue using a template consisting of full steps to reproduce.

@joni-jones joni-jones deleted the G#10583 branch July 2, 2018 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report bugfix Fixed in 2.2.x The issue has been fixed in 2.2 release line Release Line: 2.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants