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

Mage_Api - DOC block update #693

Merged
merged 2 commits into from
May 6, 2020
Merged

Mage_Api - DOC block update #693

merged 2 commits into from
May 6, 2020

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented Jun 2, 2019

Cleaned #677

@kkrieger85 kkrieger85 added code change requested For Tickets where changes in code are needed, but seem mostly fine review needed Problem should be verified labels Jun 3, 2019
@sreichel sreichel added the Cleanup: DOC blocks Related to DOC block updates and fixes. label Jun 16, 2019
@sreichel sreichel removed review needed Problem should be verified code change requested For Tickets where changes in code are needed, but seem mostly fine labels Jun 23, 2019
@@ -46,7 +46,7 @@ protected function _construct()
/**
* Retrieve rules by role
*
* @param int $id
* @param string $id
Copy link
Contributor

Choose a reason for hiding this comment

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

int was correct, its even castet to (int)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it was not.

$id comes from $rid = Mage::app()->getRequest()->getParam('rid', false); what should be a string.

getByRoles

Copy link
Member

Choose a reason for hiding this comment

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

This is closely related to an issue that I think is going to cause a ton of headache. The PDO library used by Magento returns all values from the database as strings even when they are numeric columns in the database. So while we all think of things like primary key ids as "int" in PHP because they are represented by an int column in MySQL, PHP is actually operating on string values. So for example:

$product = Mage::getModel('catalog/product')->load(1);
$product2 = Mage::getModel('catalog/product')->load($product->getId());

On the first line, load() is receiving an int but on the second line it is receiving a string. So should the @param for this method be an int or a string?

Copy link
Contributor

Choose a reason for hiding this comment

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

it should be closest to what is expected, and as it specificly converts the parameter to int $this->getSelect()->where("role_id = ?", (int)$id);

I could extend it a bit to crazy edge cases...
string would maybe also support objects which implement the __toString() method(?), which will cause a notice and a wrong value of (1) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the first line, load() is receiving an int but on the second line it is receiving a string. So should the @param for this method be an int or a string?

IMHO .... for now the doc blocks should reflect the current state. Even if it is unintentional. So, i would use string here, b/c it either comes from request parameter or db object (not from hardcoded ID).

To fix it "at all" you have to ...

  • add setter/getter methods for all entities/properties with correct type casting ... dont ask what time it tooks to just add @method annotaion to all that classes?
  • enable strict types to ensure consistent code (we already dropped php5^^)

Even in M2 same properties on several entities were handled different ... magento/magento2#18079

Again ... this PRs should be doc-only fixes. I agree, a lot of things could be "fixed", but its out of scope (of thes PRs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pushing this, BUT .... i have splitted the complete PR just into different classes and smaller PRs, but they depend on each other. Skipping this line will (maybe) break other static tests ...

If the others are okay with this, i'll update during next days.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that, to move things forward (and I would love to do it quickly) we need:

  1. merge all nobrainer changes to doc comments
  2. handle few cases where we need also to fix the code (e.g. add some casting)
  3. add static code analysys to github actions

So until we reach point 3 I accept that the static code analysis will still be red.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with moving ahead and merging these "DOC block update" PRs as-is (barring some actual errors that break execution if there are any) and then figuring out later a long-term solution. It is just much more pleasant to code when all of the methods have proper vardocs and while some of the finer points are debatable (e.g. string vs int), this is a huge step in the right direction and I'm sure it was no small effort.

I used a project recently that used PHP CS-Fixer and it was a very nice experience and super easy to add to Travis.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just dont want the effort we put into the topic to detect places where api is inconsistent (expected type is different the really returned in some cases) to get lost. So I think that at least the issues should be added for such cases if we are gojng to merge this patch as is.

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 just dont want the effort we put into the topic to detect places where api is inconsistent (expected type is different the really returned in some cases) to get lost.

There should not be any inconsistencies. This is what static analysis is for?

It is just much more pleasant to code when all of the methods have proper vardocs and while some of the finer points are debatable (e.g. string vs int), this is a huge step in the right direction and I'm sure it was no small effort.

💯

THANK YOU VERY MUCH!

I have added/fixed thousends DOC blocks, added tons of @methods to make work easier. I have reverted code/logical changes as requested, to make it easier to review. No, really NO, i'll not change minor things as mentioned so far.

Take it or leave it :(

I'll update for conflicts, but no further changes, please.

@tmotyl tmotyl merged commit b88b230 into OpenMage:1.9.4.x May 6, 2020
@sreichel sreichel deleted the cleanup/docs/Api branch May 9, 2020 20:24
@sreichel sreichel added the Component: Api PageRelates to Mage_Api label Jun 5, 2020
@sreichel sreichel mentioned this pull request Jun 27, 2020
@sreichel sreichel added this to the Release 19.4.3 milestone Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup: DOC blocks Related to DOC block updates and fixes. Component: Api PageRelates to Mage_Api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants