Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
86.96% |
20 / 23 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
UserDialectCrud | |
86.96% |
20 / 23 |
|
85.71% |
6 / 7 |
7.11 | |
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% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
serializeFields | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
listByUser | |
0.00% |
0 / 3 |
|
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\UserDialect; |
13 | |
14 | /** |
15 | * @since 0.1.0 |
16 | */ |
17 | class UserDialectCrud extends AbstractUuidRdbmsCrud { |
18 | |
19 | /** @var string Name of table in database. */ |
20 | public const TABLE = self::TABLES_PREFIX . 'user_dialect'; |
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 . 'ud_'; |
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_USER = self::CLASS_COLUMNS_PREFIX . 'user'; |
39 | private const COLUMN_LANGUAGE = self::CLASS_COLUMNS_PREFIX . 'language'; |
40 | private const COLUMN_SPOKEN_PROFICIENCY_LEVEL = |
41 | self::CLASS_COLUMNS_PREFIX . 'spoken_proficiency_level'; |
42 | private const COLUMN_LOCATION = self::CLASS_COLUMNS_PREFIX . 'location'; |
43 | |
44 | /** |
45 | * @return string[] Columns in table required to deserialize an instance, identity excluded. |
46 | */ |
47 | protected function getColumns(): array { |
48 | return [ |
49 | self::COLUMN_USER, |
50 | self::COLUMN_LANGUAGE, |
51 | self::COLUMN_SPOKEN_PROFICIENCY_LEVEL, |
52 | self::COLUMN_LOCATION |
53 | ]; |
54 | } |
55 | |
56 | public function instanceFactory(): Persistent { |
57 | return new UserDialect(); |
58 | } |
59 | |
60 | /** |
61 | * @param UserDialect $instance |
62 | * @param array $row |
63 | */ |
64 | protected function deserializeRow( |
65 | $instance, |
66 | array $row |
67 | ): void { |
68 | $instance->setUser( $this->deserializeUuid( $row, self::COLUMN_USER ) ); |
69 | $instance->setLanguage( $this->deserializeUuid( $row, self::COLUMN_LANGUAGE ) ); |
70 | $instance->setSpokenProficiencyLevel( |
71 | $this->deserializeInt( $row, self::COLUMN_SPOKEN_PROFICIENCY_LEVEL ) ); |
72 | $instance->setLocation( $this->deserializeString( $row, self::COLUMN_LOCATION ) ); |
73 | } |
74 | |
75 | /** |
76 | * @param UserDialect $instance |
77 | * @return array |
78 | */ |
79 | protected function serializeFields( |
80 | $instance |
81 | ): array { |
82 | $array = []; |
83 | $array[ self::COLUMN_USER ] = $instance->getUser(); |
84 | $array[ self::COLUMN_LANGUAGE ] = $instance->getLanguage(); |
85 | $array[ self::COLUMN_SPOKEN_PROFICIENCY_LEVEL ] = $instance->getSpokenProficiencyLevel(); |
86 | $array[ self::COLUMN_LOCATION ] = $instance->getLocation(); |
87 | return $array; |
88 | } |
89 | |
90 | /** |
91 | * @param string $user |
92 | * @return UserDialect[]|null |
93 | */ |
94 | public function listByUser( |
95 | string $user |
96 | ): ?array { |
97 | // @phan-suppress-next-line PhanTypeMismatchReturn |
98 | return $this->listByConditions( [ |
99 | self::COLUMN_USER => $user |
100 | ] ); |
101 | } |
102 | } |