Passed
Push — trunk ( 9b0a66...54d57b )
by Christian
27:18 queued 11:16
created

CustomerAccountRecoverRequestEvent::getValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Customer\Event;
4
5
use Shopware\Core\Checkout\Customer\Aggregate\CustomerRecovery\CustomerRecoveryDefinition;
6
use Shopware\Core\Checkout\Customer\Aggregate\CustomerRecovery\CustomerRecoveryEntity;
0 ignored issues
show
Bug introduced by
The type Shopware\Core\Checkout\C...\CustomerRecoveryEntity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Shopware\Core\Checkout\Customer\CustomerDefinition;
8
use Shopware\Core\Checkout\Customer\CustomerEntity;
0 ignored issues
show
Bug introduced by
The type Shopware\Core\Checkout\Customer\CustomerEntity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Shopware\Core\Content\Flow\Dispatching\Action\FlowMailVariables;
10
use Shopware\Core\Content\Flow\Dispatching\Aware\CustomerRecoveryAware;
11
use Shopware\Core\Content\Flow\Dispatching\Aware\ResetUrlAware;
12
use Shopware\Core\Content\Flow\Dispatching\Aware\ScalarValuesAware;
13
use Shopware\Core\Content\Flow\Dispatching\Aware\ShopNameAware;
14
use Shopware\Core\Framework\Context;
15
use Shopware\Core\Framework\Event\CustomerAware;
16
use Shopware\Core\Framework\Event\EventData\EntityType;
17
use Shopware\Core\Framework\Event\EventData\EventDataCollection;
18
use Shopware\Core\Framework\Event\EventData\MailRecipientStruct;
19
use Shopware\Core\Framework\Event\EventData\ScalarValueType;
20
use Shopware\Core\Framework\Event\MailAware;
21
use Shopware\Core\Framework\Event\SalesChannelAware;
22
use Shopware\Core\Framework\Event\ShopwareSalesChannelEvent;
23
use Shopware\Core\Framework\Log\Package;
24
use Shopware\Core\System\SalesChannel\SalesChannelContext;
25
use Symfony\Contracts\EventDispatcher\Event;
26
27
/**
28
 * @deprecated tag:v6.6.0 - reason:class-hierarchy-change - ResetUrlAware and ShopNameAware are deprecated and will be removed in v6.6.0
29
 */
30
#[Package('customer-order')]
31
class CustomerAccountRecoverRequestEvent extends Event implements SalesChannelAware, ShopwareSalesChannelEvent, CustomerAware, MailAware, CustomerRecoveryAware, ResetUrlAware, ShopNameAware, ScalarValuesAware
0 ignored issues
show
Deprecated Code introduced by
The interface Shopware\Core\Content\Fl...ing\Aware\ResetUrlAware has been deprecated: tag:v6.6.0 - Will be removed, use ScalarValuesStorer/ScalarValuesAware instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

31
class CustomerAccountRecoverRequestEvent extends Event implements SalesChannelAware, ShopwareSalesChannelEvent, CustomerAware, MailAware, CustomerRecoveryAware, /** @scrutinizer ignore-deprecated */ ResetUrlAware, ShopNameAware, ScalarValuesAware

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
Deprecated Code introduced by
The interface Shopware\Core\Content\Fl...ing\Aware\ShopNameAware has been deprecated: tag:v6.6.0 - Will be removed, use ScalarValuesStorer/ScalarValuesAware instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

31
class CustomerAccountRecoverRequestEvent extends Event implements SalesChannelAware, ShopwareSalesChannelEvent, CustomerAware, MailAware, CustomerRecoveryAware, ResetUrlAware, /** @scrutinizer ignore-deprecated */ ShopNameAware, ScalarValuesAware

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
32
{
33
    public const EVENT_NAME = 'customer.recovery.request';
34
35
    /**
36
     * @var CustomerRecoveryEntity
37
     */
38
    private $customerRecovery;
39
40
    /**
41
     * @var SalesChannelContext
42
     */
43
    private $salesChannelContext;
44
45
    /**
46
     * @var string
47
     */
48
    private $resetUrl;
49
50
    /**
51
     * @var string
52
     */
53
    private $shopName;
54
55
    /**
56
     * @var MailRecipientStruct
57
     */
58
    private $mailRecipientStruct;
59
60
    public function __construct(
61
        SalesChannelContext $salesChannelContext,
62
        CustomerRecoveryEntity $customerRecovery,
63
        string $resetUrl
64
    ) {
65
        $this->salesChannelContext = $salesChannelContext;
66
        $this->customerRecovery = $customerRecovery;
67
        $this->resetUrl = $resetUrl;
68
        $this->shopName = $salesChannelContext->getSalesChannel()->getTranslation('name');
69
    }
70
71
    /**
72
     * @return array<string, scalar|array<mixed>|null>
73
     */
74
    public function getValues(): array
75
    {
76
        return [
77
            FlowMailVariables::RESET_URL => $this->resetUrl,
78
            FlowMailVariables::SHOP_NAME => $this->shopName,
79
        ];
80
    }
81
82
    public function getName(): string
83
    {
84
        return self::EVENT_NAME;
85
    }
86
87
    public function getCustomerRecovery(): CustomerRecoveryEntity
88
    {
89
        return $this->customerRecovery;
90
    }
91
92
    public function getSalesChannelContext(): SalesChannelContext
93
    {
94
        return $this->salesChannelContext;
95
    }
96
97
    public function getContext(): Context
98
    {
99
        return $this->salesChannelContext->getContext();
100
    }
101
102
    public static function getAvailableData(): EventDataCollection
103
    {
104
        return (new EventDataCollection())
105
            ->add('customerRecovery', new EntityType(CustomerRecoveryDefinition::class))
106
            ->add('customer', new EntityType(CustomerDefinition::class))
107
            ->add('resetUrl', new ScalarValueType(ScalarValueType::TYPE_STRING))
108
            ->add('shopName', new ScalarValueType(ScalarValueType::TYPE_STRING));
109
    }
110
111
    public function getMailStruct(): MailRecipientStruct
112
    {
113
        if (!$this->mailRecipientStruct instanceof MailRecipientStruct) {
0 ignored issues
show
introduced by
$this->mailRecipientStruct is always a sub-type of Shopware\Core\Framework\...ata\MailRecipientStruct.
Loading history...
114
            /** @var CustomerEntity $customer */
115
            $customer = $this->customerRecovery->getCustomer();
116
117
            $this->mailRecipientStruct = new MailRecipientStruct([
118
                $customer->getEmail() => $customer->getFirstName() . ' ' . $customer->getLastName(),
119
            ]);
120
        }
121
122
        return $this->mailRecipientStruct;
123
    }
124
125
    public function getSalesChannelId(): string
126
    {
127
        return $this->salesChannelContext->getSalesChannel()->getId();
128
    }
129
130
    public function getResetUrl(): string
131
    {
132
        return $this->resetUrl;
133
    }
134
135
    public function getShopName(): string
136
    {
137
        return $this->shopName;
138
    }
139
140
    public function getCustomer(): ?CustomerEntity
141
    {
142
        return $this->customerRecovery->getCustomer();
143
    }
144
145
    public function getCustomerId(): string
146
    {
147
        return $this->getCustomerRecovery()->getCustomerId();
148
    }
149
150
    public function getCustomerRecoveryId(): string
151
    {
152
        return $this->customerRecovery->getId();
153
    }
154
}
155