Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
65.52% |
19 / 29 |
|
66.67% |
6 / 9 |
CRAP | |
0.00% |
0 / 1 |
RecordingReviewCrud | |
65.52% |
19 / 29 |
|
66.67% |
6 / 9 |
12.32 | |
0.00% |
0 / 1 |
getTable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getClassColumnsPrefix | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getColumns | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
instanceFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
deserializeRow | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
serializeFields | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
listByReviewer | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
listByRecording | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getByRecordingAndReviewer | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\WikispeechSpeechDataCollector\Crud\Rdbms; |
4 | |
5 | /** |
6 | * @file |
7 | * @ingroup Extensions |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | |
11 | use MediaWiki\WikispeechSpeechDataCollector\Domain\Persistent; |
12 | use MediaWiki\WikispeechSpeechDataCollector\Domain\RecordingReview; |
13 | |
14 | /** |
15 | * @since 0.1.0 |
16 | */ |
17 | class RecordingReviewCrud extends AbstractUuidRdbmsCrud { |
18 | |
19 | /** @var string Name of table in database. */ |
20 | public const TABLE = self::TABLES_PREFIX . 'recording_review'; |
21 | |
22 | /** |
23 | * @return string Name of database table representing this class. |
24 | */ |
25 | protected function getTable(): string { |
26 | return self::TABLE; |
27 | } |
28 | |
29 | private const CLASS_COLUMNS_PREFIX = self::COLUMNS_PREFIX . 'rr_'; |
30 | |
31 | /** |
32 | * @return string COLUMNS_PREFIX . 'class prefix' . '_' |
33 | */ |
34 | protected function getClassColumnsPrefix(): string { |
35 | return self::CLASS_COLUMNS_PREFIX; |
36 | } |
37 | |
38 | private const COLUMN_CREATED = self::CLASS_COLUMNS_PREFIX . 'created'; |
39 | private const COLUMN_VALUE = self::CLASS_COLUMNS_PREFIX . 'value'; |
40 | private const COLUMN_REVIEWER = self::CLASS_COLUMNS_PREFIX . 'reviewer'; |
41 | private const COLUMN_RECORDING = self::CLASS_COLUMNS_PREFIX . 'recording'; |
42 | |
43 | /** |
44 | * @return string[] Columns in table required to deserialize an instance, identity excluded. |
45 | */ |
46 | protected function getColumns(): array { |
47 | return [ |
48 | self::COLUMN_CREATED, |
49 | self::COLUMN_VALUE, |
50 | self::COLUMN_REVIEWER, |
51 | self::COLUMN_RECORDING |
52 | ]; |
53 | } |
54 | |
55 | public function instanceFactory(): Persistent { |
56 | return new RecordingReview(); |
57 | } |
58 | |
59 | /** |
60 | * @param RecordingReview $instance |
61 | * @param array $row |
62 | */ |
63 | protected function deserializeRow( |
64 | $instance, |
65 | array $row |
66 | ): void { |
67 | $instance->setCreated( $this->deserializeTimestamp( $row, self::COLUMN_CREATED ) ); |
68 | $instance->setValue( $this->deserializeInt( $row, self::COLUMN_VALUE ) ); |
69 | $instance->setReviewer( $this->deserializeUuid( $row, self::COLUMN_REVIEWER ) ); |
70 | $instance->setRecording( $this->deserializeUuid( $row, self::COLUMN_RECORDING ) ); |
71 | } |
72 | |
73 | /** |
74 | * @param RecordingReview $instance |
75 | * @return array |
76 | */ |
77 | protected function serializeFields( |
78 | $instance |
79 | ): array { |
80 | $array = []; |
81 | $array[ self::COLUMN_CREATED ] = $instance->getCreated()->getTimestamp( TS_MW ); |
82 | $array[ self::COLUMN_VALUE ] = $instance->getValue(); |
83 | $array[ self::COLUMN_REVIEWER ] = $instance->getReviewer(); |
84 | $array[ self::COLUMN_RECORDING ] = $instance->getRecording(); |
85 | return $array; |
86 | } |
87 | |
88 | /** |
89 | * @param string $reviewer |
90 | * @return RecordingReview[]|null |
91 | */ |
92 | public function listByReviewer( |
93 | string $reviewer |
94 | ): ?array { |
95 | // @phan-suppress-next-line PhanTypeMismatchReturn |
96 | return $this->listByConditions( [ |
97 | self::COLUMN_REVIEWER => $reviewer |
98 | ] ); |
99 | } |
100 | |
101 | /** |
102 | * @param string $recording |
103 | * @return RecordingReview[]|null |
104 | */ |
105 | public function listByRecording( |
106 | string $recording |
107 | ): ?array { |
108 | // @phan-suppress-next-line PhanTypeMismatchReturn |
109 | return $this->listByConditions( [ |
110 | self::COLUMN_RECORDING => $recording |
111 | ] ); |
112 | } |
113 | |
114 | /** |
115 | * @param string $recording |
116 | * @param string $reviewer |
117 | * @return RecordingReview|null |
118 | */ |
119 | public function getByRecordingAndReviewer( |
120 | string $recording, |
121 | string $reviewer |
122 | ): ?Persistent { |
123 | // @phan-suppress-next-line PhanTypeMismatchReturnSuperType |
124 | return $this->getByConditions( [ |
125 | self::COLUMN_RECORDING => $recording, |
126 | self::COLUMN_REVIEWER => $reviewer, |
127 | ] ); |
128 | } |
129 | } |