Stack.php
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace WPML\TM\ATE\TranslateEverything\TranslatableData;
class Stack {
/** @var string $type */
private $type;
/** @var string $name */
private $name;
/** @var int $count */
private $count;
/** @var int|float $words */
private $words = 0;
/** @var bool $completed */
private $completed = false;
/** @var array $labels */
private $labels;
/**
* @param string $type
* @param string $name
* @param int $count
* @param int|float $words
* @param array<singular: string, plural: string> $labels
*
* @return void
*
* @throws \InvalidArgumentException When $type or $name is empty.
*/
public function __construct( $type, $name, $count = 0, $words = 0, $labels = [] ) {
if ( empty( $type ) || empty( $name ) ) {
throw new \InvalidArgumentException(
'Stack "type" and "name" should not be empty.'
);
}
$this->type = $type;
$this->name = $name;
$this->count = $count;
$this->words = $words;
$this->labels = $labels;
}
/** @return string */
public function type() {
return $this->type;
}
/** @return string */
public function name() {
return $this->name;
}
/** @return int */
public function count() {
return $this->count;
}
/**
* @param int|float $words
*
* @return self
*/
public function addWords( $words ) {
$this->words += $words;
return $this;
}
/**
* @param int $count
*
* @return self
*/
public function addCount( $count ) {
$this->count += $count;
return $this;
}
public function completed() {
$this->completed = true;
}
public function toArray() {
return [
'type' => $this->type,
'name' => $this->name,
'labels' => $this->labels,
'count' => $this->count,
'words' => $this->words,
'completed' => $this->completed,
];
}
}