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.
Completed
Push — master ( ea09f8...f51f95 )
by Andreas
03:33
created

AbandonedRepository::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Model;
7
8
use CommerceLeague\ActiveCampaign\Api\AbandonedRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Api\Data;
10
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Abandoned as AbandonedResource;
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 AbandonedRepository
18
 */
19
class AbandonedRepository implements AbandonedRepositoryInterface
20
{
21
    /**
22
     * @var AbandonedResource
23
     */
24
    private $abandonedResource;
25
26
    /**
27
     * @var AbandonedFactory
0 ignored issues
show
Bug introduced by
The type CommerceLeague\ActiveCam...\Model\AbandonedFactory 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 $abandonedFactory;
30
31
    /**
32
     * @param AbandonedResource $abandonedResource
33
     * @param AbandonedFactory $abandonedFactory
34
     */
35
    public function __construct(
36
        AbandonedResource $abandonedResource,
37
        AbandonedFactory $abandonedFactory
38
    ) {
39
        $this->abandonedResource = $abandonedResource;
40
        $this->abandonedFactory = $abandonedFactory;
41
    }
42
43
    /**
44
     * @param Data\AbandonedInterface|AbstractModel $abandoned
45
     * @return Data\AbandonedInterface
46
     * @throws CouldNotSaveException
47
     */
48
    public function save(Data\AbandonedInterface $abandoned): Data\AbandonedInterface
49
    {
50
        try {
51
            $this->abandonedResource->save($abandoned);
52
        } catch (\Exception $e) {
53
            throw new CouldNotSaveException(__($e->getMessage()));
54
        }
55
56
        return $abandoned;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $abandoned returns the type Magento\Framework\Model\AbstractModel which is incompatible with the type-hinted return CommerceLeague\ActiveCam...Data\AbandonedInterface.
Loading history...
57
    }
58
59
    /**
60
     * @inheritDoc
61
     */
62
    public function getById($entityId): Data\AbandonedInterface
63
    {
64
        /** @var Abandoned $abandoned */
65
        $abandoned = $this->abandonedFactory->create();
66
        $this->abandonedResource->load($abandoned, $entityId);
67
68
        return $abandoned;
69
    }
70
71
    /**
72
     * @inheritDoc
73
     */
74
    public function getByQuoteId($quoteId): Data\AbandonedInterface
75
    {
76
        /** @var Abandoned $abandoned */
77
        $abandoned = $this->abandonedFactory->create();
78
        $this->abandonedResource->load(
79
            $abandoned,
80
            $quoteId,
81
            Data\AbandonedInterface::QUOTE_ID
82
        );
83
84
        return $abandoned;
85
    }
86
87
    /**
88
     * @inheritDoc
89
     */
90
    public function getOrCreateByQuoteId($quoteId): Data\AbandonedInterface
91
    {
92
        $abandoned = $this->getByQuoteId($quoteId);
93
94
        if (!$abandoned->getId()) {
95
            $abandoned->setQuoteId($quoteId);
96
            $this->save($abandoned);
97
        }
98
99
        return $abandoned;
100
    }
101
102
    /**
103
     * @param Data\AbandonedInterface|AbstractModel $abandoned
104
     * @return bool
105
     * @throws CouldNotDeleteException
106
     */
107
    public function delete(Data\AbandonedInterface $abandoned): bool
108
    {
109
        try {
110
            $this->abandonedResource->delete($abandoned);
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
        $abandoned = $this->getById($entityId);
124
125
        if (!$abandoned->getId()) {
126
            throw new NoSuchEntityException(
127
                __('The Abandoned Cart with the "%1" ID doesn\'t exist', $entityId)
128
            );
129
        }
130
131
        return $this->delete($abandoned);
132
    }
133
}
134