Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
64.71% covered (warning)
64.71%
22 / 34
60.00% covered (warning)
60.00%
6 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
LanguageCrud
64.71% covered (warning)
64.71%
22 / 34
60.00% covered (warning)
60.00%
6 / 10
14.40
0.00% covered (danger)
0.00%
0 / 1
 getClassColumnsPrefix
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getColumns
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 instanceFactory
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 deserializeRow
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 serializeFields
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 findLanguageByIso639a1
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 findLanguageByIso639a2b
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 findLanguageByIso639a2t
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 findLanguageByIso639a3
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\WikispeechSpeechDataCollector\Crud\Rdbms;
4
5/**
6 * @file
7 * @ingroup Extensions
8 * @license GPL-2.0-or-later
9 */
10
11use MediaWiki\WikispeechSpeechDataCollector\Domain\Language;
12use MediaWiki\WikispeechSpeechDataCollector\Domain\Persistent;
13
14/**
15 * @since 0.1.0
16 */
17class LanguageCrud extends AbstractUuidRdbmsCrud {
18
19    /** @var string Name of table in database. */
20    public const TABLE = self::TABLES_PREFIX . 'language';
21
22    private const CLASS_COLUMNS_PREFIX = self::COLUMNS_PREFIX . 'l_';
23
24    /**
25     * @return string COLUMNS_PREFIX . 'class prefix' . '_'
26     */
27    protected function getClassColumnsPrefix(): string {
28        return self::CLASS_COLUMNS_PREFIX;
29    }
30
31    private const COLUMN_NATIVE_NAME = self::CLASS_COLUMNS_PREFIX . 'native_name';
32    private const COLUMN_ISO639A1 = self::CLASS_COLUMNS_PREFIX . 'iso639a1';
33    private const COLUMN_ISO639A2B = self::CLASS_COLUMNS_PREFIX . 'iso639a2b';
34    private const COLUMN_ISO639A2T = self::CLASS_COLUMNS_PREFIX . 'iso639a2t';
35    private const COLUMN_ISO639A3 = self::CLASS_COLUMNS_PREFIX . 'iso639a3';
36
37    /**
38     * @return string Name of database table representing this class.
39     */
40    protected function getTable(): string {
41        return self::TABLE;
42    }
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_NATIVE_NAME,
50            self::COLUMN_ISO639A1,
51            self::COLUMN_ISO639A2B,
52            self::COLUMN_ISO639A2T,
53            self::COLUMN_ISO639A3
54        ];
55    }
56
57    public function instanceFactory(): Persistent {
58        return new Language();
59    }
60
61    /**
62     * @param Language $instance Instance
63     * @param array $row
64     */
65    protected function deserializeRow(
66        $instance,
67        array $row
68    ): void {
69        $instance->setNativeName( $this->deserializeString( $row, self::COLUMN_NATIVE_NAME ) );
70        $instance->setIso639a1( $this->deserializeString( $row, self::COLUMN_ISO639A1 ) );
71        $instance->setIso639a2b( $this->deserializeString( $row, self::COLUMN_ISO639A2B ) );
72        $instance->setIso639a2t( $this->deserializeString( $row, self::COLUMN_ISO639A2T ) );
73        $instance->setIso639a3( $this->deserializeString( $row, self::COLUMN_ISO639A3 ) );
74    }
75
76    /**
77     * @param Language $instance
78     * @return array
79     */
80    protected function serializeFields(
81        $instance
82    ): array {
83        $array = [];
84        $array[ self::COLUMN_NATIVE_NAME ] = $instance->getNativeName();
85        $array[ self::COLUMN_ISO639A1 ] = $instance->getIso639a1();
86        $array[ self::COLUMN_ISO639A2B ] = $instance->getIso639a2b();
87        $array[ self::COLUMN_ISO639A2T ] = $instance->getIso639a2t();
88        $array[ self::COLUMN_ISO639A3 ] = $instance->getIso639a3();
89        return $array;
90    }
91
92    /**
93     * @param string $iso639a1
94     * @return Language|null
95     */
96    public function findLanguageByIso639a1(
97        string $iso639a1
98    ): ?Persistent {
99        // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
100        return $this->getByConditions( [
101            self::COLUMN_ISO639A1 => $iso639a1
102        ] );
103    }
104
105    /**
106     * @param string $iso639a2b
107     * @return Language|null
108     */
109    public function findLanguageByIso639a2b(
110        string $iso639a2b
111    ): ?Persistent {
112        // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
113        return $this->getByConditions( [
114            self::COLUMN_ISO639A2B => $iso639a2b
115        ] );
116    }
117
118    /**
119     * @param string $iso639a2t
120     * @return Language|null
121     */
122    public function findLanguageByIso639a2t(
123        string $iso639a2t
124    ): ?Persistent {
125        // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
126        return $this->getByConditions( [
127            self::COLUMN_ISO639A2T => $iso639a2t
128        ] );
129    }
130
131    /**
132     * @param string $iso639a3
133     * @return Language|null
134     */
135    public function findLanguageByIso639a3(
136        string $iso639a3
137    ): ?Persistent {
138        // @phan-suppress-next-line PhanTypeMismatchReturnSuperType
139        return $this->getByConditions( [
140            self::COLUMN_ISO639A3 => $iso639a3
141        ] );
142    }
143}