Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
61.54% |
16 / 26 |
|
66.67% |
6 / 9 |
CRAP | |
0.00% |
0 / 1 |
SkippedManuscriptPromptCrud | |
61.54% |
16 / 26 |
|
66.67% |
6 / 9 |
13.61 | |
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 | |||
listByUser | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
listByManuscriptPrompt | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getByUserAndManuscriptPrompt | |
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\SkippedManuscriptPrompt; |
13 | |
14 | /** |
15 | * @since 0.1.0 |
16 | */ |
17 | class SkippedManuscriptPromptCrud extends AbstractUuidRdbmsCrud { |
18 | |
19 | /** @var string Name of table in database. */ |
20 | public const TABLE = self::TABLES_PREFIX . 'skipped_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 . 'smp_'; |
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_PROMPT = self::CLASS_COLUMNS_PREFIX . 'manuscript_prompt'; |
39 | private const COLUMN_USER = self::CLASS_COLUMNS_PREFIX . 'user'; |
40 | private const COLUMN_SKIPPED = self::CLASS_COLUMNS_PREFIX . 'skipped'; |
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_PROMPT, |
48 | self::COLUMN_USER, |
49 | self::COLUMN_SKIPPED, |
50 | ]; |
51 | } |
52 | |
53 | public function instanceFactory(): Persistent { |
54 | return new SkippedManuscriptPrompt(); |
55 | } |
56 | |
57 | /** |
58 | * @param SkippedManuscriptPrompt $instance |
59 | * @param array $row |
60 | */ |
61 | protected function deserializeRow( |
62 | $instance, |
63 | array $row |
64 | ): void { |
65 | $instance->setManuscriptPrompt( $this->deserializeUuid( $row, self::COLUMN_MANUSCRIPT_PROMPT ) ); |
66 | $instance->setUser( $this->deserializeUuid( $row, self::COLUMN_USER ) ); |
67 | $instance->setSkipped( $this->deserializeTimestamp( $row, self::COLUMN_SKIPPED ) ); |
68 | } |
69 | |
70 | /** |
71 | * @param SkippedManuscriptPrompt $instance |
72 | * @return array |
73 | */ |
74 | protected function serializeFields( |
75 | $instance |
76 | ): array { |
77 | $array = []; |
78 | $array[ self::COLUMN_MANUSCRIPT_PROMPT ] = $instance->getManuscriptPrompt(); |
79 | $array[ self::COLUMN_USER ] = $instance->getUser(); |
80 | $array[ self::COLUMN_SKIPPED ] = $instance->getSkipped()->getTimestamp( TS_MW ); |
81 | return $array; |
82 | } |
83 | |
84 | /** |
85 | * @param string $user |
86 | * @return SkippedManuscriptPrompt[]|null |
87 | */ |
88 | public function listByUser( |
89 | string $user |
90 | ): ?array { |
91 | // @phan-suppress-next-line PhanTypeMismatchReturn |
92 | return $this->listByConditions( [ |
93 | self::COLUMN_USER => $user |
94 | ] ); |
95 | } |
96 | |
97 | /** |
98 | * @param string $manuscriptPrompt |
99 | * @return SkippedManuscriptPrompt[]|null |
100 | */ |
101 | public function listByManuscriptPrompt( |
102 | string $manuscriptPrompt |
103 | ): ?array { |
104 | // @phan-suppress-next-line PhanTypeMismatchReturn |
105 | return $this->listByConditions( [ |
106 | self::COLUMN_MANUSCRIPT_PROMPT => $manuscriptPrompt |
107 | ] ); |
108 | } |
109 | |
110 | /** |
111 | * @param string $user |
112 | * @param string $manuscriptPrompt |
113 | * @return SkippedManuscriptPrompt|null |
114 | */ |
115 | public function getByUserAndManuscriptPrompt( |
116 | string $user, |
117 | string $manuscriptPrompt |
118 | ): ?Persistent { |
119 | // @phan-suppress-next-line PhanTypeMismatchReturnSuperType |
120 | return $this->getByConditions( [ |
121 | self::COLUMN_USER => $user, |
122 | self::COLUMN_MANUSCRIPT_PROMPT => $manuscriptPrompt |
123 | ] ); |
124 | } |
125 | |
126 | } |