Completed
Push — master ( 9eb95c...c4f41c )
by Joachim
21:07 queued 06:06
created

QueueItem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Loevgaard\DandomainFoundation\Entity;
4
5
use Assert\Assert;
6
use Doctrine\ORM\Mapping as ORM;
7
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
8
use Loevgaard\DandomainFoundation\Entity\Generated\QueueItemInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...ated\QueueItemInterface 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...
9
use Loevgaard\DandomainFoundation\Entity\Generated\QueueItemTrait;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...enerated\QueueItemTrait 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...
10
11
/**
12
 * This entity represent a queue item which is queued for synchronization
13
 *
14
 * @ORM\Entity()
15
 * @ORM\Table(name="ldf_queue", indexes={@ORM\Index(columns={"type"})})
16
 * @ORM\HasLifecycleCallbacks()
17
 */
18
class QueueItem implements QueueItemInterface
19
{
20
    use QueueItemTrait;
21
    use Timestampable;
22
23
    const TYPE_ORDER = 'order';
24
    const TYPE_PRODUCT = 'product';
25
26
    const STATUS_PENDING = 'pending';
27
    const STATUS_ERROR = 'error';
28
    const STATUS_SUCCESS = 'success';
29
30
    /**
31
     * @var int
32
     *
33
     * @ORM\Id
34
     * @ORM\GeneratedValue
35
     * @ORM\Column(type="integer")
36
     **/
37
    protected $id;
38
39
    /**
40
     * @var string
41
     *
42
     * @ORM\Column(type="string", length=191)
43
     */
44
    protected $identifier;
45
46
    /**
47
     * @var string
48
     *
49
     * @ORM\Column(name="`type`", type="string", length=191)
50
     */
51
    protected $type;
52
53
    /**
54
     * @var string
55
     *
56
     * @ORM\Column(type="string", length=191)
57
     */
58
    protected $status;
59
60
    public function __construct()
61
    {
62
        $this->status = self::STATUS_PENDING;
63
    }
64
65
    /**
66
     * @ORM\PrePersist()
67
     * @ORM\PreUpdate()
68
     */
69
    public function validate()
70
    {
71
        Assert::that($this->identifier)->string()->minLength(1)->maxLength(191);
72
        Assert::that($this->type)->choice(self::getTypes());
73
        Assert::that($this->status)->choice(self::getStatuses());
74
    }
75
76
    public static function getTypes() : array
77
    {
78
        return [
79
            self::TYPE_ORDER => self::TYPE_ORDER,
80
            self::TYPE_PRODUCT => self::TYPE_PRODUCT,
81
        ];
82
    }
83
84
    public static function getStatuses() : array
85
    {
86
        return [
87
            self::STATUS_PENDING => self::STATUS_PENDING,
88
            self::STATUS_ERROR => self::STATUS_ERROR,
89
            self::STATUS_SUCCESS => self::STATUS_SUCCESS,
90
        ];
91
    }
92
93
    /**
94
     * The create method creates a valid queue item object
95
     *
96
     * @param string $identifier
97
     * @param string $type
98
     * @return QueueItemInterface
99
     */
100
    public static function create(string $identifier, string $type) : QueueItemInterface
101
    {
102
        $queueItem = new QueueItem();
103
        $queueItem
104
            ->setIdentifier($identifier)
105
            ->setType($type);
106
107
        return $queueItem;
108
    }
109
110
    /**
111
     * @return int
112
     */
113
    public function getId(): int
114
    {
115
        return (int)$this->id;
116
    }
117
118
    /**
119
     * @param int $id
120
     * @return QueueItem
121
     */
122
    public function setId(int $id)
123
    {
124
        $this->id = $id;
125
        return $this;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function getIdentifier(): string
132
    {
133
        return (string)$this->identifier;
134
    }
135
136
    /**
137
     * @param string $identifier
138
     * @return QueueItem
139
     */
140
    public function setIdentifier(string $identifier)
141
    {
142
        $this->identifier = $identifier;
143
        return $this;
144
    }
145
146
    /**
147
     * @return string
148
     */
149
    public function getType(): string
150
    {
151
        return (string)$this->type;
152
    }
153
154
    /**
155
     * @param string $type
156
     * @return QueueItem
157
     */
158
    public function setType(string $type)
159
    {
160
        $this->type = $type;
161
        return $this;
162
    }
163
164
    /**
165
     * @return string
166
     */
167
    public function getStatus(): string
168
    {
169
        return (string)$this->status;
170
    }
171
172
    /**
173
     * @param string $status
174
     * @return QueueItem
175
     */
176
    public function setStatus(string $status)
177
    {
178
        $this->status = $status;
179
        return $this;
180
    }
181
}
182