1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | /** |
||
4 | */ |
||
5 | |||
6 | namespace CommerceLeague\ActiveCampaign\Model\ActiveCampaign; |
||
7 | |||
8 | use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface; |
||
9 | use CommerceLeague\ActiveCampaign\Api\Data; |
||
10 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\ActiveCampaign\Customer as CustomerResource; |
||
11 | use Magento\Framework\Exception\CouldNotDeleteException; |
||
12 | use Magento\Framework\Exception\CouldNotSaveException; |
||
13 | use Magento\Framework\Exception\NoSuchEntityException; |
||
14 | use Magento\Framework\Model\AbstractModel; |
||
15 | |||
16 | /** |
||
17 | * Class CustomerRepository |
||
18 | */ |
||
19 | class CustomerRepository implements CustomerRepositoryInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var CustomerResource |
||
23 | */ |
||
24 | private $customerResource; |
||
25 | |||
26 | /** |
||
27 | * @var CustomerFactory |
||
0 ignored issues
–
show
|
|||
28 | */ |
||
29 | private $customerFactory; |
||
30 | |||
31 | /** |
||
32 | * @param CustomerResource $customerResource |
||
33 | * @param CustomerFactory $customerFactory |
||
34 | */ |
||
35 | public function __construct( |
||
36 | CustomerResource $customerResource, |
||
37 | CustomerFactory $customerFactory |
||
38 | ) { |
||
39 | $this->customerResource = $customerResource; |
||
40 | $this->customerFactory = $customerFactory; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @param Data\CustomerInterface|AbstractModel $customer |
||
45 | * @return Data\CustomerInterface |
||
46 | * @throws CouldNotSaveException |
||
47 | */ |
||
48 | public function save(Data\CustomerInterface $customer): Data\CustomerInterface |
||
49 | { |
||
50 | try { |
||
51 | $this->customerResource->save($customer); |
||
52 | } catch (\Exception $e) { |
||
53 | throw new CouldNotSaveException(__($e->getMessage())); |
||
54 | } |
||
55 | |||
56 | return $customer; |
||
0 ignored issues
–
show
|
|||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @inheritDoc |
||
61 | */ |
||
62 | public function getById($entityId): Data\CustomerInterface |
||
63 | { |
||
64 | /** @var Customer $customer */ |
||
65 | $customer = $this->customerFactory->create(); |
||
66 | $this->customerResource->load($customer, $entityId); |
||
67 | |||
68 | return $customer; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @inheritDoc |
||
73 | */ |
||
74 | public function getByMagentoCustomerId($magentoCustomerId): Data\CustomerInterface |
||
75 | { |
||
76 | /** @var Customer $customer */ |
||
77 | $customer = $this->customerFactory->create(); |
||
78 | $this->customerResource->load( |
||
79 | $customer, |
||
80 | $magentoCustomerId, |
||
81 | Data\CustomerInterface::MAGENTO_CUSTOMER_ID |
||
82 | ); |
||
83 | |||
84 | return $customer; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @inheritDoc |
||
89 | */ |
||
90 | public function getOrCreateByMagentoCustomerId($magentoCustomerId): Data\CustomerInterface |
||
91 | { |
||
92 | $customer = $this->getByMagentoCustomerId($magentoCustomerId); |
||
93 | |||
94 | if (!$customer->getId()) { |
||
95 | $customer->setMagentoCustomerId($magentoCustomerId); |
||
96 | $this->save($customer); |
||
97 | } |
||
98 | |||
99 | return $customer; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param Data\CustomerInterface|AbstractModel $customer |
||
104 | * @return bool |
||
105 | * @throws CouldNotDeleteException |
||
106 | */ |
||
107 | public function delete(Data\CustomerInterface $customer): bool |
||
108 | { |
||
109 | try { |
||
110 | $this->customerResource->delete($customer); |
||
111 | } catch (\Exception $e) { |
||
112 | throw new CouldNotDeleteException(__($e->getMessage())); |
||
113 | } |
||
114 | |||
115 | return true; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @inheritDoc |
||
120 | */ |
||
121 | public function deleteById($entityId): bool |
||
122 | { |
||
123 | $customer = $this->getById($entityId); |
||
124 | |||
125 | if (!$customer->getId()) { |
||
126 | throw new NoSuchEntityException( |
||
127 | __('The Customer with the "%1" ID doesn\'t exist', $entityId) |
||
128 | ); |
||
129 | } |
||
130 | |||
131 | return $this->delete($customer); |
||
132 | } |
||
133 | } |
||
134 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths