Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
35 / 35
100.00% covered (success)
100.00%
11 / 11
CRAP
100.00% covered (success)
100.00%
1 / 1
LexemePatchAccess
100.00% covered (success)
100.00%
35 / 35
100.00% covered (success)
100.00%
11 / 11
16
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
 addForm
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 increaseNextFormIdTo
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 addSense
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 increaseNextSenseIdTo
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 close
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getForms
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNextFormId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSenses
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNextSenseId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 assertIsNotClosed
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare( strict_types = 1 );
4
5namespace Wikibase\Lexeme\Domain\Model;
6
7/**
8 * @license GPL-2.0-or-later
9 */
10class LexemePatchAccess {
11
12    private int $nextFormId;
13
14    private FormSet $forms;
15
16    private int $nextSenseId;
17
18    private SenseSet $senses;
19
20    private bool $isClosed = false;
21
22    public function __construct( int $nextFormId, FormSet $forms, int $nextSenseId, SenseSet $senses ) {
23        if ( $nextFormId < 1 ) {
24            throw new \InvalidArgumentException(
25                "nextFormId should be positive integer. Given: {$nextFormId}"
26            );
27        }
28        if ( $nextSenseId < 1 ) {
29            throw new \InvalidArgumentException(
30                "nextSenseId should be positive integer. Given: {$nextSenseId}"
31            );
32        }
33
34        $this->nextFormId = $nextFormId;
35        $this->forms = clone $forms;
36        $this->nextSenseId = $nextSenseId;
37        $this->senses = clone $senses;
38    }
39
40    public function addForm( Form $form ): void {
41        $this->assertIsNotClosed();
42
43        $this->forms->add( $form );
44    }
45
46    public function increaseNextFormIdTo( int $number ): void {
47        if ( $number < $this->nextFormId ) {
48            throw new \LogicException(
49                "Cannot increase `nextFormId` because given number is less than counter value " .
50                "of this Lexeme. Current=`{$this->nextFormId}`, given=`{$number}`"
51            );
52        }
53
54        $this->nextFormId = $number;
55    }
56
57    public function addSense( Sense $sense ): void {
58        $this->assertIsNotClosed();
59
60        $this->senses->add( $sense );
61    }
62
63    public function increaseNextSenseIdTo( int $number ): void {
64        if ( $number < $this->nextSenseId ) {
65            throw new \LogicException(
66                "Cannot increase `nextSenseId` because given number is less than counter value " .
67                "of this Lexeme. Current=`{$this->nextSenseId}`, given=`{$number}`"
68            );
69        }
70
71        $this->nextSenseId = $number;
72    }
73
74    public function close(): void {
75        $this->isClosed = true;
76    }
77
78    public function getForms(): FormSet {
79        return $this->forms;
80    }
81
82    public function getNextFormId(): int {
83        return $this->nextFormId;
84    }
85
86    public function getSenses(): SenseSet {
87        return $this->senses;
88    }
89
90    public function getNextSenseId(): int {
91        return $this->nextSenseId;
92    }
93
94    private function assertIsNotClosed(): void {
95        if ( $this->isClosed ) {
96            throw new \LogicException( "Cannot modify closed LexemePatchAccess" );
97        }
98    }
99
100}