Passed
Push — master ( 302660...3652f8 )
by payever
04:19 queued 01:32
created

ActionResult   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 28
c 1
b 0
f 0
dl 0
loc 110
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getErrorsCount() 0 3 1
A incrementDeleted() 0 5 1
A addError() 0 5 1
A addException() 0 5 1
A incrementUpdated() 0 5 1
A incrementCreated() 0 5 1
A hasErrors() 0 3 1
A incrementSkipped() 0 5 1
A toString() 0 10 1
1
<?php
2
3
/**
4
 * PHP version 5.4 and 8
5
 *
6
 * @category  Action
7
 * @package   Payever\ThirdParty
8
 * @author    payever GmbH <[email protected]>
9
 * @author    Hennadii.Shymanskyi <[email protected]>
10
 * @copyright 2017-2021 payever GmbH
11
 * @license   MIT <https://opensource.org/licenses/MIT>
12
 * @link      https://docs.payever.org/shopsystems/api/getting-started
13
 */
14
15
namespace Payever\ExternalIntegration\ThirdParty\Action;
16
17
use Payever\ExternalIntegration\Core\Base\MessageEntity;
18
19
/**
20
 * @method int getCreatedCount()
21
 * @method int getUpdatedCount()
22
 * @method int getDeletedCount()
23
 * @method int getSkippedCount()
24
 * @method string[] getErrors();
25
 */
26
class ActionResult extends MessageEntity
27
{
28
    /** @var int */
29
    protected $createdCount = 0;
30
31
    /** @var int */
32
    protected $updatedCount = 0;
33
34
    /** @var int */
35
    protected $deletedCount = 0;
36
37
    /** @var int */
38
    protected $skippedCount = 0;
39
40
    /** @var string[] */
41
    protected $errors = [];
42
43
    /**
44
     * @return static
45
     */
46
    public function incrementCreated()
47
    {
48
        $this->createdCount++;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @return static
55
     */
56
    public function incrementUpdated()
57
    {
58
        $this->updatedCount++;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @return static
65
     */
66
    public function incrementDeleted()
67
    {
68
        $this->deletedCount++;
69
70
        return $this;
71
    }
72
73
    /**
74
     * @return $this
75
     */
76
    public function incrementSkipped()
77
    {
78
        $this->skippedCount++;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @return int
85
     */
86
    public function getErrorsCount()
87
    {
88
        return count($this->errors);
89
    }
90
91
    /**
92
     * @param string $error
93
     *
94
     * @return static
95
     */
96
    public function addError($error)
97
    {
98
        $this->errors[] = $error;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @return bool
105
     */
106
    public function hasErrors()
107
    {
108
        return !empty($this->errors);
109
    }
110
111
    /**
112
     * @param \Exception $exception
113
     *
114
     * @return static
115
     */
116
    public function addException(\Exception $exception)
117
    {
118
        $this->addError($exception->getMessage());
119
120
        return $this;
121
    }
122
123
    /**
124
     * @inheritDoc
125
     */
126
    public function toString()
127
    {
128
        return sprintf(
129
            "%s: [created=%d] [updated=%d] [deleted=%d] [skipped=%d] [errors=%d]",
130
            'Result',
131
            $this->getCreatedCount(),
132
            $this->getUpdatedCount(),
133
            $this->getDeletedCount(),
134
            $this->getSkippedCount(),
135
            $this->getErrorsCount()
136
        );
137
    }
138
}
139