GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 08f33b...54b06f )
by Andreas
03:24
created

CustomerRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Model;
7
8
use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Api\Data;
10
use CommerceLeague\ActiveCampaign\Model\ResourceModel\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
Bug introduced by
The type CommerceLeague\ActiveCam...n\Model\CustomerFactory 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...
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
Bug Best Practice introduced by
The expression return $customer returns the type Magento\Framework\Model\AbstractModel which is incompatible with the type-hinted return CommerceLeague\ActiveCam...\Data\CustomerInterface.
Loading history...
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 getByEmail($email): Data\CustomerInterface
75
    {
76
        /** @var Customer $customer */
77
        $customer = $this->customerFactory->create();
78
        $this->customerResource->load($customer, $email, Data\ContactInterface::EMAIL);
79
80
        return $customer;
81
    }
82
83
    /**
84
     * @param Data\CustomerInterface|AbstractModel $customer
85
     * @return bool
86
     * @throws CouldNotDeleteException
87
     */
88
    public function delete(Data\CustomerInterface $customer): bool
89
    {
90
        try {
91
            $this->customerResource->delete($customer);
92
        } catch (\Exception $e) {
93
            throw new CouldNotDeleteException(__($e->getMessage()));
94
        }
95
96
        return true;
97
    }
98
99
    /**
100
     * @inheritDoc
101
     */
102
    public function deleteById($entityId): bool
103
    {
104
        $customer = $this->getById($entityId);
105
106
        if (!$customer->getId()) {
107
            throw new NoSuchEntityException(
108
                __('The Customer with the "%1" ID doesn\'t exist', $entityId)
109
            );
110
        }
111
112
        return $this->delete($customer);
113
    }
114
}
115