Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
69.57% |
16 / 23 |
|
75.00% |
6 / 8 |
CRAP | |
0.00% |
0 / 1 |
ManuscriptPromptCrud | |
69.57% |
16 / 23 |
|
75.00% |
6 / 8 |
9.80 | |
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% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
instanceFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
deserializeRow | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
serializeFields | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
listByManuscript | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getByManuscriptAndIndex | |
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\ManuscriptPrompt; |
12 | use MediaWiki\WikispeechSpeechDataCollector\Domain\Persistent; |
13 | |
14 | /** |
15 | * @since 0.1.0 |
16 | */ |
17 | class ManuscriptPromptCrud extends AbstractUuidRdbmsCrud { |
18 | |
19 | /** @var string Name of table in database. */ |
20 | public const TABLE = self::TABLES_PREFIX . 'manuscript_prompt'; |
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 . 'mp_'; |
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_MANUSCRIPT = self::CLASS_COLUMNS_PREFIX . 'manuscript'; |
39 | private const COLUMN_INDEX = self::CLASS_COLUMNS_PREFIX . 'index'; |
40 | private const COLUMN_CONTENT = self::CLASS_COLUMNS_PREFIX . 'content'; |
41 | |
42 | /** |
43 | * @return string[] Columns in table required to deserialize an instance, identity excluded. |
44 | */ |
45 | protected function getColumns(): array { |
46 | return [ |
47 | self::COLUMN_MANUSCRIPT, |
48 | self::COLUMN_INDEX, |
49 | self::COLUMN_CONTENT |
50 | ]; |
51 | } |
52 | |
53 | public function instanceFactory(): Persistent { |
54 | return new ManuscriptPrompt(); |
55 | } |
56 | |
57 | /** |
58 | * @param ManuscriptPrompt $instance |
59 | * @param array $row |
60 | */ |
61 | protected function deserializeRow( |
62 | $instance, |
63 | array $row |
64 | ): void { |
65 | $instance->setManuscript( $this->deserializeUuid( $row, self::COLUMN_MANUSCRIPT ) ); |
66 | $instance->setIndex( $this->deserializeInt( $row, self::COLUMN_INDEX ) ); |
67 | $instance->setContent( $this->deserializeString( $row, self::COLUMN_CONTENT ) ); |
68 | } |
69 | |
70 | /** |
71 | * @param ManuscriptPrompt $instance |
72 | * @return array |
73 | */ |
74 | protected function serializeFields( |
75 | $instance |
76 | ): array { |
77 | $array = []; |
78 | $array[ self::COLUMN_MANUSCRIPT ] = $instance->getManuscript(); |
79 | $array[ self::COLUMN_INDEX ] = $instance->getIndex(); |
80 | $array[ self::COLUMN_CONTENT ] = $instance->getContent(); |
81 | return $array; |
82 | } |
83 | |
84 | /** |
85 | * @param string $manuscript |
86 | * @return ManuscriptPrompt[]|null |
87 | */ |
88 | public function listByManuscript( |
89 | string $manuscript |
90 | ): ?array { |
91 | // @phan-suppress-next-line PhanTypeMismatchReturn |
92 | return $this->listByConditions( [ |
93 | self::COLUMN_MANUSCRIPT => $manuscript |
94 | ] ); |
95 | } |
96 | |
97 | /** |
98 | * @param string $manuscript |
99 | * @param int $index |
100 | * @return ManuscriptPrompt|null |
101 | */ |
102 | public function getByManuscriptAndIndex( |
103 | string $manuscript, |
104 | int $index |
105 | ): ?Persistent { |
106 | // @phan-suppress-next-line PhanTypeMismatchReturnSuperType |
107 | return $this->getByConditions( [ |
108 | self::COLUMN_MANUSCRIPT => $manuscript, |
109 | self::COLUMN_INDEX => $index |
110 | ] ); |
111 | } |
112 | |
113 | } |