1 | <?php |
||
2 | |||
3 | |||
4 | namespace Pheanstalk\Structure; |
||
5 | |||
6 | class Tube |
||
7 | { |
||
8 | |||
9 | const SCHEDULER_TYPE_DEFAULT = 'default'; |
||
10 | const SCHEDULER_TYPE_FIFO = 'fifo'; |
||
11 | const SCHEDULER_TYPE_PRIO = 'prio'; |
||
12 | |||
13 | const IS_DYNAMIC = 'yes'; |
||
14 | const IS_NOT_DYNAMIC = 'no'; |
||
15 | |||
16 | /** @var int $id */ |
||
17 | private $id; |
||
18 | |||
19 | /** @var int $concurrency */ |
||
20 | private $concurrency; |
||
21 | |||
22 | /** @var string $dynamic */ |
||
23 | private $dynamic; |
||
24 | |||
25 | /** @var string $name */ |
||
26 | private $name; |
||
27 | |||
28 | /** @var string $scheduler */ |
||
29 | private $scheduler; |
||
30 | |||
31 | /** |
||
32 | * Tube constructor. |
||
33 | * |
||
34 | * @param string $name The name of the tube |
||
35 | * @param int $concurrency The number of workflows that can be executed simultaneously |
||
36 | * @param string $scheduler WIP |
||
37 | * @param string|bool $dynamic Wether the tube is dynamic or not |
||
38 | */ |
||
39 | 15 | public function __construct(string $name, int $concurrency, $scheduler = self::SCHEDULER_TYPE_DEFAULT, $dynamic = true) |
|
40 | { |
||
41 | 15 | $this->name = $name; |
|
42 | 15 | $this->concurrency = $concurrency; |
|
43 | 15 | $this->scheduler = $scheduler; |
|
44 | 15 | $this->setDynamic($dynamic); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return int |
||
49 | */ |
||
50 | 4 | public function getId(): int |
|
51 | { |
||
52 | 4 | return $this->id; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param int $id |
||
57 | * |
||
58 | * @return Tube |
||
59 | */ |
||
60 | 11 | public function setId(int $id): Tube |
|
61 | { |
||
62 | 11 | $this->id = $id; |
|
63 | 11 | return $this; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * @return int |
||
68 | */ |
||
69 | 3 | public function getConcurrency(): int |
|
70 | { |
||
71 | 3 | return $this->concurrency; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param int $concurrency |
||
76 | * |
||
77 | * @return Tube |
||
78 | */ |
||
79 | 1 | public function setConcurrency(int $concurrency): Tube |
|
80 | { |
||
81 | 1 | $this->concurrency = $concurrency; |
|
82 | 1 | return $this; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | */ |
||
88 | 3 | public function getDynamic(): string |
|
89 | { |
||
90 | 3 | $dynamic = $this->dynamic ?? true; |
|
91 | 3 | return ($dynamic) ? self::IS_DYNAMIC : self::IS_NOT_DYNAMIC; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param string|bool $dynamic |
||
96 | * |
||
97 | * @return Tube |
||
98 | */ |
||
99 | 15 | public function setDynamic($dynamic): Tube |
|
100 | { |
||
101 | 15 | if (!is_bool($dynamic)) { |
|
102 | 10 | if ($dynamic === self::IS_NOT_DYNAMIC) { |
|
103 | 10 | $dynamic = false; |
|
104 | } else { |
||
105 | 9 | $dynamic = true; |
|
106 | } |
||
107 | } |
||
108 | 15 | $this->dynamic = $dynamic; |
|
0 ignored issues
–
show
|
|||
109 | 15 | return $this; |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | 11 | public function getName(): string |
|
116 | { |
||
117 | 11 | return $this->name; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * @param string $name |
||
122 | * |
||
123 | * @return Tube |
||
124 | */ |
||
125 | 2 | public function setName(string $name): Tube |
|
126 | { |
||
127 | 2 | $this->name = $name; |
|
128 | 2 | return $this; |
|
129 | } |
||
130 | |||
131 | /** |
||
132 | * @return string |
||
133 | */ |
||
134 | 3 | public function getScheduler(): string |
|
135 | { |
||
136 | 3 | return $this->scheduler ?? self::SCHEDULER_TYPE_DEFAULT; |
|
137 | } |
||
138 | |||
139 | /** |
||
140 | * @param string $scheduler |
||
141 | * |
||
142 | * @return Tube |
||
143 | */ |
||
144 | 11 | public function setScheduler(string $scheduler): Tube |
|
145 | { |
||
146 | 11 | $this->scheduler = $scheduler; |
|
147 | 11 | return $this; |
|
148 | } |
||
149 | } |
||
150 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.