Failed Conditions
Pull Request — master (#229)
by
unknown
02:57
created

RemoveAddressHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 10 1
A assertOrderWithAddressNotExists() 0 8 1
A assertCurrentUserIsOwner() 0 4 1
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Handler;
4
5
use Sylius\Component\Core\Model\AddressInterface;
6
use Sylius\Component\Core\Model\OrderInterface;
7
use Sylius\Component\Core\Model\ShopUserInterface;
8
use Sylius\Component\Core\Repository\AddressRepositoryInterface;
9
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
10
use Sylius\ShopApiPlugin\Command\RemoveAddress;
11
use Webmozart\Assert\Assert;
12
13
class RemoveAddressHandler
14
{
15
    /**
16
     * @var AddressRepositoryInterface
17
     */
18
    private $addressRepository;
19
20
    /**
21
     * @var OrderRepositoryInterface
22
     */
23
    private $orderRepository;
24
25
    public function __construct(AddressRepositoryInterface $addressRepository, OrderRepositoryInterface $orderRepository)
26
    {
27
        $this->addressRepository = $addressRepository;
28
        $this->orderRepository = $orderRepository;
29
    }
30
31
    public function handle(RemoveAddress $removeAddress)
32
    {
33
        /** @var AddressInterface $address */
34
        $address = $this->addressRepository->findOneBy(["id" => $removeAddress->id]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal id does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
35
36
        $this->assertCurrentUserIsOwner($address, $removeAddress->user);
37
        $this->assertOrderWithAddressNotExists($address);
38
39
        $this->addressRepository->remove($address);
40
    }
41
42
    private function assertOrderWithAddressNotExists($address)
43
    {
44
        /** @var OrderInterface $orderShippingAddress */
45
        $orderShippingAddress = $this->orderRepository->findBy(["billingAddress" => $address]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal billingAddress does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
46
        /** @var OrderInterface $orderBillingAddress */
47
        $orderBillingAddress = $this->orderRepository->findBy(["shippingAddress" => $address]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal shippingAddress does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
48
        Assert::allIsEmpty([$orderShippingAddress, $orderBillingAddress], 'Cant delete address because it is associated with one or more orders');
49
    }
50
51
    private function assertCurrentUserIsOwner(AddressInterface $address, ShopUserInterface $user)
52
    {
53
        Assert::eq($address->getCustomer()->getId(), $user->getId(), "User is not owner of this address");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal User is not owner of this address does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
54
    }
55
}