This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Resolve coupling between objects in \Magento\QuoteGraphQl\Model\Cart\SetBillingAddressOnCart
#488
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b3280d0
magento/graphql-ce:#468 - Resolve coupling between objects in `\Mage…
799f37e
magento/graphql-ce:#468 - Fix codestyle issue
ace616f
Merge remote-tracking branch 'origin/2.3-develop' into issue/468
naydav 5b03488
GraphQL-468: Resolve coupling between objects in `\Magento\QuoteGraph…
naydav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
app/code/Magento/QuoteGraphQl/Model/Cart/CreateQuoteAddressByCustomerAddress.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress; | ||
use Magento\CustomerGraphQl\Model\Customer\GetCustomer; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Quote\Model\Quote\Address; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
|
||
/** | ||
* Creates a quote address based on given context, customer address ID and customer address | ||
*/ | ||
class CreateQuoteAddressByCustomerAddress | ||
{ | ||
/** | ||
* @var QuoteAddressFactory | ||
*/ | ||
private $quoteAddressFactory; | ||
|
||
/** | ||
* @var GetCustomer | ||
*/ | ||
private $getCustomer; | ||
|
||
/** | ||
* @var GetCustomerAddress | ||
*/ | ||
private $getCustomerAddress; | ||
|
||
/** | ||
* @param QuoteAddressFactory $quoteAddressFactory | ||
* @param GetCustomer $getCustomer | ||
* @param GetCustomerAddress $getCustomerAddress | ||
*/ | ||
public function __construct( | ||
QuoteAddressFactory $quoteAddressFactory, | ||
GetCustomer $getCustomer, | ||
GetCustomerAddress $getCustomerAddress | ||
) { | ||
$this->quoteAddressFactory = $quoteAddressFactory; | ||
$this->getCustomer = $getCustomer; | ||
$this->getCustomerAddress = $getCustomerAddress; | ||
} | ||
|
||
/** | ||
* @param ContextInterface $context | ||
* @param int|string|null $customerAddressId | ||
* @param array|null $customerAddress | ||
* @return Address | ||
* @throws GraphQlAuthenticationException | ||
* @throws GraphQlAuthorizationException | ||
* @throws GraphQlInputException | ||
* @throws GraphQlNoSuchEntityException | ||
*/ | ||
public function execute( | ||
ContextInterface $context, | ||
$customerAddressId, | ||
$customerAddress | ||
): Address { | ||
if (null === $customerAddressId) { | ||
return $this->quoteAddressFactory->createBasedOnInputData($customerAddress); | ||
} | ||
|
||
$customer = $this->getCustomer->execute($context); | ||
$customerAddress = $this->getCustomerAddress->execute((int)$customerAddressId, (int)$customer->getId()); | ||
|
||
return $this->quoteAddressFactory->createBasedOnCustomerAddress($customerAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Usually
@throws
annotation tags are added only when exception is thrown explicitly in the function. Any other exceptions from parent methods are implicit and not annotated. "Missing@throws
tag(s)" can be turned off in PHPStorm Inspections->PHP->PHPDocThere 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.
Thanks for mentioning, @TomashKhamlai. I've added requested changes. Thank you!
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 little disagree with this statement. If I work with some API I will prefer to know which of exception could be thrown without submerging in implementation (does not matter will be thrown in current method or in some child classes)
Generally, it's about readability.