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

CustomerDoubleOptInRegistrationEvent::getValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\CustomerDefinition;
6
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...
7
use Shopware\Core\Content\Flow\Dispatching\Action\FlowMailVariables;
8
use Shopware\Core\Content\Flow\Dispatching\Aware\ConfirmUrlAware;
9
use Shopware\Core\Content\Flow\Dispatching\Aware\ScalarValuesAware;
10
use Shopware\Core\Framework\Context;
11
use Shopware\Core\Framework\Event\CustomerAware;
12
use Shopware\Core\Framework\Event\EventData\EntityType;
13
use Shopware\Core\Framework\Event\EventData\EventDataCollection;
14
use Shopware\Core\Framework\Event\EventData\MailRecipientStruct;
15
use Shopware\Core\Framework\Event\EventData\ScalarValueType;
16
use Shopware\Core\Framework\Event\MailAware;
17
use Shopware\Core\Framework\Event\SalesChannelAware;
18
use Shopware\Core\Framework\Log\Package;
19
use Shopware\Core\System\SalesChannel\SalesChannelContext;
20
use Symfony\Contracts\EventDispatcher\Event;
21
22
/**
23
 * @deprecated tag:v6.6.0 - reason:class-hierarchy-change - ConfirmUrlAware is deprecated and will be removed in v6.6.0
24
 */
25
#[Package('customer-order')]
26
class CustomerDoubleOptInRegistrationEvent extends Event implements SalesChannelAware, CustomerAware, MailAware, ConfirmUrlAware, ScalarValuesAware
0 ignored issues
show
Deprecated Code introduced by
The interface Shopware\Core\Content\Fl...g\Aware\ConfirmUrlAware 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

26
class CustomerDoubleOptInRegistrationEvent extends Event implements SalesChannelAware, CustomerAware, MailAware, /** @scrutinizer ignore-deprecated */ ConfirmUrlAware, 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...
27
{
28
    final public const EVENT_NAME = 'checkout.customer.double_opt_in_registration';
29
30
    private ?MailRecipientStruct $mailRecipientStruct = null;
31
32
    public function __construct(
33
        private readonly CustomerEntity $customer,
34
        private readonly SalesChannelContext $salesChannelContext,
35
        private readonly string $confirmUrl
36
    ) {
37
    }
38
39
    public static function getAvailableData(): EventDataCollection
40
    {
41
        return (new EventDataCollection())
42
            ->add('customer', new EntityType(CustomerDefinition::class))
43
            ->add('confirmUrl', new ScalarValueType(ScalarValueType::TYPE_STRING));
44
    }
45
46
    public function getName(): string
47
    {
48
        return self::EVENT_NAME;
49
    }
50
51
    public function getMailStruct(): MailRecipientStruct
52
    {
53
        if (!$this->mailRecipientStruct instanceof MailRecipientStruct) {
54
            $this->mailRecipientStruct = new MailRecipientStruct([
55
                $this->customer->getEmail() => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(),
56
            ]);
57
        }
58
59
        return $this->mailRecipientStruct;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->mailRecipientStruct could return the type null which is incompatible with the type-hinted return Shopware\Core\Framework\...ata\MailRecipientStruct. Consider adding an additional type-check to rule them out.
Loading history...
60
    }
61
62
    /**
63
     * @return array<string, scalar|array<mixed>|null>
64
     */
65
    public function getValues(): array
66
    {
67
        return [FlowMailVariables::CONFIRM_URL => $this->confirmUrl];
68
    }
69
70
    public function getCustomer(): CustomerEntity
71
    {
72
        return $this->customer;
73
    }
74
75
    public function getConfirmUrl(): string
76
    {
77
        return $this->confirmUrl;
78
    }
79
80
    public function getSalesChannelId(): string
81
    {
82
        return $this->salesChannelContext->getSalesChannel()->getId();
83
    }
84
85
    public function getContext(): Context
86
    {
87
        return $this->salesChannelContext->getContext();
88
    }
89
90
    public function getCustomerId(): string
91
    {
92
        return $this->getCustomer()->getId();
93
    }
94
}
95