Passed
Push — master ( 6c42be...776013 )
by Igor
02:03
created

ActionResult::incrementCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * PHP version 5.4 and 7
4
 *
5
 * @package   Payever\ThirdParty
6
 * @author    Hennadii.Shymanskyi <[email protected]>
7
 * @copyright 2017-2019 payever GmbH
8
 * @license   MIT <https://opensource.org/licenses/MIT>
9
 */
10
11
namespace Payever\ExternalIntegration\ThirdParty\Action;
12
13
use Payever\ExternalIntegration\Core\Base\MessageEntity;
14
15
/**
16
 * Class ActionResult
17
 *
18
 * PHP version 5.4 and 7
19
 *
20
 * @package   Payever\ThirdParty
21
 * @author    Hennadii.Shymanskyi <[email protected]>
22
 * @copyright 2017-2019 payever GmbH
23
 * @license   MIT <https://opensource.org/licenses/MIT>
24
 *
25
 * @method int getCreatedCount()
26
 * @method int getUpdatedCount()
27
 * @method int getDeletedCount()
28
 * @method int getSkippedCount()
29
 * @method string[] getErrors();
30
 */
31
class ActionResult extends MessageEntity
32
{
33
    protected $createdCount = 0;
34
35
    protected $updatedCount = 0;
36
37
    protected $deletedCount = 0;
38
39
    protected $skippedCount = 0;
40
41
    protected $errors = array();
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 $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
    public function toString()
124
    {
125
        return sprintf(
126
            "%s: [created=%d] [updated=%d] [deleted=%d] [skipped=%d] [errors=%d]",
127
            'Result',
128
            $this->getCreatedCount(),
129
            $this->getUpdatedCount(),
130
            $this->getDeletedCount(),
131
            $this->getSkippedCount(),
132
            $this->getErrorsCount()
133
        );
134
    }
135
}
136