Skip to content

Conversation

bartekszymanski
Copy link
Contributor

Description

Fixed Issues (if relevant)

  1. magento/magento2#<issue_number>: Issue title
  2. ...

Manual testing scenarios

  1. ...
  2. ...

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)

Copy link
Member

@larsroettig larsroettig Sep 17, 2017

Choose a reason for hiding this comment

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

if ($stockId=== null) {
$this->messageManager->addErrorMessage(__('Wrong request.'));
$resultRedirect->setPath('*/*');
return $resultRedirect;

it is shorter and better maintainable @see https://phpmd.org/rules/cleancode.html#elseexpression

Copy link
Member

Choose a reason for hiding this comment

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

You can also simplify with

if ($this->getRequest()->isPost() !== true) {
    $this->messageManager->addErrorMessage(__('Wrong request.'));
    return $this->resultRedirectFactory->create()->setPath('*/*');
}

Then you don't nee the else  @see https://phpmd.org/rules/cleancode.html#elseexpression 

@bartekszymanski
Copy link
Contributor Author

app/code/Magento/Inventory/Controller/Adminhtml/Stock/Delete.php and
app/code/Magento/Inventory/Controller/Adminhtml/Stock/MassDelete.php refactoring according to @larsroettig comments

Copy link
Contributor

Choose a reason for hiding this comment

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

Please, don't use such alignments
just make a space after type before the variable declaration

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 try to make the fancy alignment.
It's hard to read and in any case it would be broken along the code evolution

Copy link
Contributor

Choose a reason for hiding this comment

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

It's preferable to use explicit Extension Points than Registry.
Because usage of Registry is forbidden for newly created code
as it introduces mutable global state

Copy link
Contributor

Choose a reason for hiding this comment

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

please fix the formatting

Copy link
Contributor

Choose a reason for hiding this comment

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

Please provide a description for all public methods

Copy link
Contributor

Choose a reason for hiding this comment

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

please fix the author PHP Doc Block

Copy link
Contributor

Choose a reason for hiding this comment

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

please fix formatting

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to use next syntax :

array_map(function(\Magento\Framework\Api\Search\DocumentInterface $item) {
    return $item->getId();
}, $searchResult->getItems());

Doing that way you can ensure the type validation of the array returned

Copy link
Contributor

Choose a reason for hiding this comment

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

wan't -> want

Copy link
Contributor

Choose a reason for hiding this comment

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

was -> would be

Copy link
Contributor

Choose a reason for hiding this comment

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

dependency on Context is not recommended. As Context is a container for other objects.

Use dependencies on the precise components you are dependent on

Copy link
Contributor

Choose a reason for hiding this comment

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

This code
$this->context->getRequest()->getParam(StockInterface::STOCK_ID)
violates the Law of Demeter https://en.wikipedia.org/wiki/Law_of_Demeter
which is one of the good design guidelince for developing Object Oriented software

Copy link
Contributor

Choose a reason for hiding this comment

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

it's preferable to use Composition over Inheritance,
so try to not inherit from GenericButton, but just inject it as Constructor Dependency

Copy link
Contributor

Choose a reason for hiding this comment

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

I see a violation of encapsulation and Law of Demeter here.
Because current code is equivalent to
$this->filter->getComponent()->getContext()->getDataProvider()->getSearchResult()

@naydav is it really recommended way of applying Filtering?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub issue number magento/magento2#10988

Copy link
Contributor

Choose a reason for hiding this comment

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

in both Delete and MassDelete we have a duplication of this constant, that means that it should be declared in another place.
Because currently, such code violates DRY

} catch (CouldNotDeleteException $e) {
$errorMessage = __('[ID: %1] ', $id) . $e->getMessage();
$this->messageManager->addErrorMessage($errorMessage);
}
Copy link

Choose a reason for hiding this comment

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

What about NoSuchEntityException?

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 think that it is not necessary because deleteById method throw CouldNotDeleteException and this scenario is served. See Magento\InventoryApi\Api\StockRepositoryInterface.

Copy link
Contributor

Choose a reason for hiding this comment

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

@naydav naydav merged commit 0cc081f into develop Sep 27, 2017
@maghamed maghamed deleted the delete-stock branch December 11, 2018 18:13
magento-cicd2 pushed a commit that referenced this pull request Apr 1, 2021
[Sidecar] MQE-2528: Create automated test for: [MSI] "Tables data updated when SKU of Simple product has been changed from Admin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants