Completed
Push — master ( b9ade7...9eb95c )
by Joachim
11:47
created

QueueItem::getType()   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
     * @return int
95
     */
96
    public function getId(): int
97
    {
98
        return (int)$this->id;
99
    }
100
101
    /**
102
     * @param int $id
103
     * @return QueueItem
104
     */
105
    public function setId(int $id)
106
    {
107
        $this->id = $id;
108
        return $this;
109
    }
110
111
    /**
112
     * @return string
113
     */
114
    public function getIdentifier(): string
115
    {
116
        return (string)$this->identifier;
117
    }
118
119
    /**
120
     * @param string $identifier
121
     * @return QueueItem
122
     */
123
    public function setIdentifier(string $identifier)
124
    {
125
        $this->identifier = $identifier;
126
        return $this;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getType(): string
133
    {
134
        return (string)$this->type;
135
    }
136
137
    /**
138
     * @param string $type
139
     * @return QueueItem
140
     */
141
    public function setType(string $type)
142
    {
143
        $this->type = $type;
144
        return $this;
145
    }
146
147
    /**
148
     * @return string
149
     */
150
    public function getStatus(): string
151
    {
152
        return (string)$this->status;
153
    }
154
155
    /**
156
     * @param string $status
157
     * @return QueueItem
158
     */
159
    public function setStatus(string $status)
160
    {
161
        $this->status = $status;
162
        return $this;
163
    }
164
}
165