Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
81.25% |
13 / 16 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
ManuscriptDomainCrud | |
81.25% |
13 / 16 |
|
85.71% |
6 / 7 |
7.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% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
instanceFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
deserializeRow | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
serializeFields | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
listByParent | |
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\ManuscriptDomain; |
12 | use MediaWiki\WikispeechSpeechDataCollector\Domain\Persistent; |
13 | |
14 | /** |
15 | * @since 0.1.0 |
16 | */ |
17 | class ManuscriptDomainCrud extends AbstractUuidRdbmsCrud { |
18 | |
19 | /** @var string Name of table in database. */ |
20 | public const TABLE = self::TABLES_PREFIX . 'manuscript_domain'; |
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 . 'md_'; |
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_NAME = self::CLASS_COLUMNS_PREFIX . 'name'; |
39 | private const COLUMN_PARENT = self::CLASS_COLUMNS_PREFIX . 'parent'; |
40 | |
41 | /** |
42 | * @return string[] Columns in table required to deserialize an instance, identity excluded. |
43 | */ |
44 | protected function getColumns(): array { |
45 | return [ |
46 | self::COLUMN_NAME, |
47 | self::COLUMN_PARENT |
48 | ]; |
49 | } |
50 | |
51 | public function instanceFactory(): Persistent { |
52 | return new ManuscriptDomain(); |
53 | } |
54 | |
55 | /** |
56 | * @param ManuscriptDomain $instance |
57 | * @param array $row |
58 | */ |
59 | protected function deserializeRow( |
60 | $instance, |
61 | array $row |
62 | ): void { |
63 | $instance->setName( $this->deserializeString( $row, self::COLUMN_NAME ) ); |
64 | $instance->setParent( $this->deserializeUuid( $row, self::COLUMN_PARENT ) ); |
65 | } |
66 | |
67 | /** |
68 | * @param ManuscriptDomain $instance |
69 | * @return array |
70 | */ |
71 | protected function serializeFields( |
72 | $instance |
73 | ): array { |
74 | $array = []; |
75 | $array[ self::COLUMN_NAME ] = $instance->getName(); |
76 | $array[ self::COLUMN_PARENT ] = $instance->getParent(); |
77 | return $array; |
78 | } |
79 | |
80 | /** |
81 | * @param string $parent |
82 | * @return ManuscriptDomain[]|null |
83 | */ |
84 | public function listByParent( |
85 | string $parent |
86 | ): ?array { |
87 | // @phan-suppress-next-line PhanTypeMismatchReturn |
88 | return $this->listByConditions( [ |
89 | self::COLUMN_PARENT => $parent |
90 | ] ); |
91 | } |
92 | } |