Completed
Pull Request — master (#3)
by Oleksandr
32:39 queued 22:11
created

AbstractCustomerMapper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 26
dl 0
loc 78
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocaleShortName() 0 3 1
A __construct() 0 4 1
A getLocale() 0 9 4
A getMailingId() 0 3 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\Episerver\Business\Mapper\Customer;
9
10
use Generated\Shared\Transfer\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer 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...
11
use Generated\Shared\Transfer\MailTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\MailTransfer 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...
12
use Spryker\Shared\Kernel\Store;
13
use SprykerEco\Zed\Episerver\Dependency\Facade\EpiserverToLocaleFacadeInterface;
14
use SprykerEco\Zed\Episerver\EpiserverConfig;
15
16
abstract class AbstractCustomerMapper implements CustomerMapperInterface
17
{
18
    protected const URL_LOGIN = '/login';
19
    protected const KEY_EMAIL = 'bmRecipientId';
20
    protected const KEY_OPT_IN_ID = 'bmOptInId';
21
    protected const KEY_MAILING_ID = 'bmMailingId';
22
    protected const KEY_SALUTATION = 'salutation';
23
    protected const KEY_FIRST_NAME = 'firstname';
24
    protected const KEY_LAST_NAME = 'lastname';
25
    protected const KEY_SPRYKER_ID = 'spryker_id';
26
    protected const KEY_CUSTOMER_SHOP_LOCALE = 'customer_shop_locale';
27
    protected const KEY_CUSTOMER_SHOP_URL = 'customer_shop_url';
28
    protected const KEY_CUSTOMER_LOGIN_URL = 'customer_login_url';
29
    protected const KEY_CUSTOMER_RESET_LINK = 'customer_reset_link';
30
    protected const KEY_CUSTOMER_SUBSCRIBER_KEY = 'subscriber_key';
31
    protected const KEY_REMOVE_ID = 'bmRemoveId';
32
33
    /**
34
     * @var \SprykerEco\Zed\Episerver\EpiserverConfig
35
     */
36
    protected $config;
37
38
    /**
39
     * @var \SprykerEco\Zed\Episerver\Dependency\Facade\EpiserverToLocaleFacadeInterface
40
     */
41
    protected $localeFacade;
42
43
    /**
44
     * @param \SprykerEco\Zed\Episerver\EpiserverConfig $config
45
     * @param \SprykerEco\Zed\Episerver\Dependency\Facade\EpiserverToLocaleFacadeInterface $localeFacade
46
     */
47
    public function __construct(EpiserverConfig $config, EpiserverToLocaleFacadeInterface $localeFacade)
48
    {
49
        $this->config = $config;
50
        $this->localeFacade = $localeFacade;
51
    }
52
53
    /**
54
     * @param \Generated\Shared\Transfer\MailTransfer $mailTransfer
55
     *
56
     * @return array
57
     */
58
    abstract protected function buildPayload(MailTransfer $mailTransfer): array;
59
60
    /**
61
     * @param string $mailTypeName
62
     *
63
     * @return string|null
64
     */
65
    protected function getMailingId(string $mailTypeName): ?string
66
    {
67
        return $this->config->getMailingIdByMailingTypeName($mailTypeName);
68
    }
69
70
    /**
71
     * @param \Generated\Shared\Transfer\CustomerTransfer|null $customerTransfer
72
     *
73
     * @return string
74
     */
75
    protected function getLocale(?CustomerTransfer $customerTransfer): string
76
    {
77
        if ($customerTransfer !== null &&
78
            $customerTransfer->getLocale() !== null &&
79
            $customerTransfer->getLocale()->getLocaleName() !== null) {
80
            return $this->getLocaleShortName($customerTransfer->getLocale()->getLocaleName());
81
        }
82
83
        return $this->getLocaleShortName($this->localeFacade->getCurrentLocaleName());
84
    }
85
86
    /**
87
     * @param string $localeName
88
     *
89
     * @return string
90
     */
91
    protected function getLocaleShortName(string $localeName): string
92
    {
93
        return (string)array_search($localeName, Store::getInstance()->getLocales());
94
    }
95
}
96