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.

ContactRepository::getByEmail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
namespace CommerceLeague\ActiveCampaign\Model\ActiveCampaign;
6
7
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface;
8
use CommerceLeague\ActiveCampaign\Api\Data;
9
use CommerceLeague\ActiveCampaign\Model\ResourceModel\ActiveCampaign\Contact as ContactResource;
10
use Magento\Framework\Exception\CouldNotDeleteException;
11
use Magento\Framework\Exception\CouldNotSaveException;
12
use Magento\Framework\Exception\NoSuchEntityException;
13
use Magento\Framework\Model\AbstractModel;
14
15
/**
16
 * Class ContactRepository
17
 */
18
class ContactRepository implements ContactRepositoryInterface
19
{
20
    /**
21
     * @var ContactResource
22
     */
23
    private $contactResource;
24
25
    /**
26
     * @var ContactFactory
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...Campaign\ContactFactory 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...
27
     */
28
    private $contactFactory;
29
30
    /**
31
     * @param ContactResource $contactResource
32
     * @param ContactFactory $contactFactory
33
     */
34
    public function __construct(
35
        ContactResource $contactResource,
36
        ContactFactory $contactFactory
37
    ) {
38
        $this->contactResource = $contactResource;
39
        $this->contactFactory = $contactFactory;
40
    }
41
42
    /**
43
     * @param Data\ContactInterface|AbstractModel $contact
44
     * @return Data\ContactInterface
45
     * @throws CouldNotSaveException
46
     */
47
    public function save(Data\ContactInterface $contact): Data\ContactInterface
48
    {
49
        try {
50
            $this->contactResource->save($contact);
51
        } catch (\Exception $e) {
52
            throw new CouldNotSaveException(__($e->getMessage()));
53
        }
54
55
        return $contact;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $contact returns the type Magento\Framework\Model\AbstractModel which is incompatible with the type-hinted return CommerceLeague\ActiveCam...i\Data\ContactInterface.
Loading history...
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    public function getById($entityId): Data\ContactInterface
62
    {
63
        /** @var Contact $contact */
64
        $contact = $this->contactFactory->create();
65
        $this->contactResource->load($contact, $entityId);
66
67
        return $contact;
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73
    public function getByEmail($email): Data\ContactInterface
74
    {
75
        /** @var Contact $contact */
76
        $contact = $this->contactFactory->create();
77
        $this->contactResource->load($contact, $email, Data\ContactInterface::EMAIL);
78
79
        return $contact;
80
    }
81
82
    /**
83
     * @inheritDoc
84
     */
85
    public function getOrCreateByEmail($email): Data\ContactInterface
86
    {
87
        $contact = $this->getByEmail($email);
88
89
        if (!$contact->getId()) {
90
            $contact->setEmail($email);
91
            $this->save($contact);
92
        }
93
94
        return $contact;
95
    }
96
97
    /**
98
     * @param Data\ContactInterface|AbstractModel $contact
99
     * @return bool
100
     * @throws CouldNotDeleteException
101
     */
102
    public function delete(Data\ContactInterface $contact): bool
103
    {
104
        try {
105
            $this->contactResource->delete($contact);
106
        } catch (\Exception $e) {
107
            throw new CouldNotDeleteException(__($e->getMessage()));
108
        }
109
110
        return true;
111
    }
112
113
    /**
114
     * @inheritDoc
115
     */
116
    public function deleteById($entityId): bool
117
    {
118
        $contact = $this->getById($entityId);
119
120
        if (!$contact->getId()) {
121
            throw new NoSuchEntityException(
122
                __('The Contact with the "%1" ID doesn\'t exist', $entityId)
123
            );
124
        }
125
126
        return $this->delete($contact);
127
    }
128
}
129