Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
39 / 39 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
LexemePatchAccess | |
100.00% |
39 / 39 |
|
100.00% |
11 / 11 |
20 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
5 | |||
addForm | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
increaseNextFormIdTo | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
addSense | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
increaseNextSenseIdTo | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
close | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getForms | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getNextFormId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSenses | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getNextSenseId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
assertIsNotClosed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\Domain\Model; |
4 | |
5 | /** |
6 | * @license GPL-2.0-or-later |
7 | */ |
8 | class LexemePatchAccess { |
9 | |
10 | /** |
11 | * @var int |
12 | */ |
13 | private $nextFormId; |
14 | |
15 | /** |
16 | * @var FormSet |
17 | */ |
18 | private $forms; |
19 | |
20 | /** |
21 | * @var int |
22 | */ |
23 | private $nextSenseId; |
24 | |
25 | /** |
26 | * @var SenseSet |
27 | */ |
28 | private $senses; |
29 | |
30 | private $isClosed = false; |
31 | |
32 | /** |
33 | * @param int $nextFormId |
34 | * @param FormSet $forms |
35 | * @param int $nextSenseId |
36 | * @param SenseSet $senses |
37 | */ |
38 | public function __construct( $nextFormId, FormSet $forms, $nextSenseId, SenseSet $senses ) { |
39 | if ( !is_int( $nextFormId ) || $nextFormId < 1 ) { |
40 | throw new \InvalidArgumentException( |
41 | "nextFormId should be positive integer. Given: {$nextFormId}" |
42 | ); |
43 | } |
44 | if ( !is_int( $nextSenseId ) || $nextSenseId < 1 ) { |
45 | throw new \InvalidArgumentException( |
46 | "nextSenseId should be positive integer. Given: {$nextSenseId}" |
47 | ); |
48 | } |
49 | |
50 | $this->nextFormId = $nextFormId; |
51 | $this->forms = clone $forms; |
52 | $this->nextSenseId = $nextSenseId; |
53 | $this->senses = clone $senses; |
54 | } |
55 | |
56 | public function addForm( Form $form ) { |
57 | $this->assertIsNotClosed(); |
58 | |
59 | $this->forms->add( $form ); |
60 | } |
61 | |
62 | /** |
63 | * @param int $number |
64 | */ |
65 | public function increaseNextFormIdTo( $number ) { |
66 | if ( !is_int( $number ) ) { |
67 | throw new \InvalidArgumentException( '$number` must be integer' ); |
68 | } |
69 | |
70 | if ( $number < $this->nextFormId ) { |
71 | throw new \LogicException( |
72 | "Cannot increase `nextFormId` because given number is less than counter value " . |
73 | "of this Lexeme. Current=`{$this->nextFormId}`, given=`{$number}`" |
74 | ); |
75 | } |
76 | |
77 | $this->nextFormId = $number; |
78 | } |
79 | |
80 | public function addSense( Sense $sense ) { |
81 | $this->assertIsNotClosed(); |
82 | |
83 | $this->senses->add( $sense ); |
84 | } |
85 | |
86 | public function increaseNextSenseIdTo( $number ) { |
87 | if ( !is_int( $number ) ) { |
88 | throw new \InvalidArgumentException( '$number` must be integer' ); |
89 | } |
90 | |
91 | if ( $number < $this->nextSenseId ) { |
92 | throw new \LogicException( |
93 | "Cannot increase `nextSenseId` because given number is less than counter value " . |
94 | "of this Lexeme. Current=`{$this->nextSenseId}`, given=`{$number}`" |
95 | ); |
96 | } |
97 | |
98 | $this->nextSenseId = $number; |
99 | } |
100 | |
101 | public function close() { |
102 | $this->isClosed = true; |
103 | } |
104 | |
105 | /** |
106 | * @return FormSet |
107 | */ |
108 | public function getForms() { |
109 | return $this->forms; |
110 | } |
111 | |
112 | /** |
113 | * @return int |
114 | */ |
115 | public function getNextFormId() { |
116 | return $this->nextFormId; |
117 | } |
118 | |
119 | /** |
120 | * @return SenseSet |
121 | */ |
122 | public function getSenses() { |
123 | return $this->senses; |
124 | } |
125 | |
126 | /** |
127 | * @return int |
128 | */ |
129 | public function getNextSenseId() { |
130 | return $this->nextSenseId; |
131 | } |
132 | |
133 | private function assertIsNotClosed() { |
134 | if ( $this->isClosed ) { |
135 | throw new \LogicException( "Cannot modify closed LexemePatchAccess" ); |
136 | } |
137 | } |
138 | |
139 | } |