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
Conversation
@@ -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( |
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.
Why do we need to hack autoloader instead of placing fixtures accordingly?
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.
To do not use _files
word in the class namespace.
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.
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
.
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.
If you open integration or unit tests you will see all fixtures located in _files
directory. I don't want to change such "standard".
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.
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} |
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.
Such syntax only inherits method description, not type hints for parameters and return value.
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
.
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.
According to Magento internal guidelines, this annotation should look like {@inheritdoc}
.
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.
Where do you see it? http://devdocs.magento.com/guides/v2.2/coding-standards/docblock-standard-general.html#inheritdoc is compliant with what I'm saying.
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.
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.
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, |
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.
Why need this change?
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.
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.
The class complexity is 103 but Codacy configured complexity threshold is 50. |
@joni-jones I don't think we should any suppressions when |
@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. |
@joni-jones do you mean green in Travis or green in Codacy? The latter is pretty odd, like forbidding |
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; |
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.
Currently logic of this cycle is not so easy to understand. I suggest something like
foreach (...) {
if ($parent...->hasMethod()) {
$returnAnnotations = ...;
break;
}
}
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.
Done
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.
Don't see it :(
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.
Please, see a list of changed files, I amended commit.
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.
Hm, I was answering to next thread actually O.o
$methodDocBlock = $methodReflection->getDocBlock(); | ||
if (!$methodDocBlock) { | ||
throw new \InvalidArgumentException( | ||
"Each getter must have dock block. " |
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.
Typo dock -> doc. "have a doc block"?
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.
Done
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.
"Each getter must have a dock block. "
I meant don't see this changed.
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.
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.
"dock" is correct spelling? I was not certain regarding "a" but "dock" seems to be not correct.
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.
Yes, sure. Fixed.
} | ||
|
||
/** | ||
* @inheritdoc |
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.
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.
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.
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.
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.
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.
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.
Absolutely agree, even more, I think there should be a static test which won't allow adding this annotation.
@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. |
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. |
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
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.
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(); |
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.
Sir, you're missing docs from extended class here. $methodReflection->getDeclaringClass()->getParentClass() should be included in this array
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.
Hi @VoidWalker, please report an issue using a template consisting of full steps to reproduce.
Fixed Issues
Contribution checklist