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
|
14 |
|
public function __construct(string $name, int $concurrency, $scheduler = self::SCHEDULER_TYPE_DEFAULT, $dynamic = true) |
40
|
|
|
{ |
41
|
14 |
|
$this->name = $name; |
42
|
14 |
|
$this->concurrency = $concurrency; |
43
|
14 |
|
$this->scheduler = $scheduler; |
44
|
14 |
|
$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
|
10 |
|
public function setId(int $id): Tube |
61
|
|
|
{ |
62
|
10 |
|
$this->id = $id; |
63
|
10 |
|
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
|
14 |
|
public function setDynamic($dynamic): Tube |
100
|
|
|
{ |
101
|
14 |
|
if (!is_bool($dynamic)) { |
102
|
9 |
|
if ($dynamic === self::IS_NOT_DYNAMIC) { |
103
|
9 |
|
$dynamic = false; |
104
|
|
|
} else { |
105
|
8 |
|
$dynamic = true; |
106
|
|
|
} |
107
|
|
|
} |
108
|
14 |
|
$this->dynamic = $dynamic; |
|
|
|
|
109
|
14 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
10 |
|
public function getName(): string |
116
|
|
|
{ |
117
|
10 |
|
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
|
10 |
|
public function setScheduler(string $scheduler): Tube |
145
|
|
|
{ |
146
|
10 |
|
$this->scheduler = $scheduler; |
147
|
10 |
|
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.