Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
| PersistentJsonDeserializer | |
0.00% |
0 / 36 |
|
0.00% |
0 / 12 |
210 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| visitLanguage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitManuscript | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitManuscriptDomain | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitManuscriptPrompt | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitRecording | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitRecordingAnnotations | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitRecordingReview | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitSkippedManuscriptPrompt | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| visitUser | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitUserDialect | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| visitUserLanguageProficiencyLevel | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\WikispeechSpeechDataCollector\Domain; |
| 4 | |
| 5 | /** |
| 6 | * @file |
| 7 | * @ingroup Extensions |
| 8 | * @license GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | use FormatJson; |
| 12 | use MWException; |
| 13 | |
| 14 | /** |
| 15 | * Loads a persistent instance from a JSON string representation. |
| 16 | * |
| 17 | * @since 0.1.0 |
| 18 | */ |
| 19 | class PersistentJsonDeserializer implements PersistentVisitor { |
| 20 | |
| 21 | /** @var array|null JSON string representation decoded to an associative array */ |
| 22 | private $array; |
| 23 | |
| 24 | /** |
| 25 | * @param string|null $json JSON string representation |
| 26 | * @throws MWException If unable to parse JSON string. |
| 27 | * @since 0.1.0 |
| 28 | */ |
| 29 | public function __construct( ?string $json ) { |
| 30 | if ( $json !== null ) { |
| 31 | $status = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
| 32 | if ( !$status->isOK() ) { |
| 33 | throw new MWException( "Failed to parse JSON string: $status" ); |
| 34 | } |
| 35 | $this->array = $status->getValue(); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param Language $language |
| 41 | * @return Language|null Same instance, or null if serialized value is null. |
| 42 | * @since 0.1.0 |
| 43 | */ |
| 44 | public function visitLanguage( |
| 45 | Language $language |
| 46 | ) { |
| 47 | return $language->accept( |
| 48 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param Manuscript $manuscript |
| 54 | * @return Manuscript|null Same instance, or null if serialized value is null. |
| 55 | * @since 0.1.0 |
| 56 | */ |
| 57 | public function visitManuscript( |
| 58 | Manuscript $manuscript |
| 59 | ) { |
| 60 | return $manuscript->accept( |
| 61 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @param ManuscriptDomain $manuscriptDomain |
| 67 | * @return ManuscriptDomain|null Same instance, or null if serialized value is null. |
| 68 | * @since 0.1.0 |
| 69 | */ |
| 70 | public function visitManuscriptDomain( |
| 71 | ManuscriptDomain $manuscriptDomain |
| 72 | ) { |
| 73 | return $manuscriptDomain->accept( |
| 74 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @param ManuscriptPrompt $manuscriptPrompt |
| 80 | * @return ManuscriptPrompt|null Same instance, or null if serialized value is null. |
| 81 | * @since 0.1.0 |
| 82 | */ |
| 83 | public function visitManuscriptPrompt( |
| 84 | ManuscriptPrompt $manuscriptPrompt |
| 85 | ) { |
| 86 | return $manuscriptPrompt->accept( |
| 87 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @param Recording $recording |
| 93 | * @return Recording|null Same instance, or null if serialized value is null. |
| 94 | * @since 0.1.0 |
| 95 | */ |
| 96 | public function visitRecording( |
| 97 | Recording $recording |
| 98 | ) { |
| 99 | return $recording->accept( |
| 100 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @param RecordingAnnotations $recordingAnnotations |
| 106 | * @return RecordingAnnotations|null Same instance, or null if serialized value is null. |
| 107 | * @since 0.1.0 |
| 108 | */ |
| 109 | public function visitRecordingAnnotations( |
| 110 | RecordingAnnotations $recordingAnnotations |
| 111 | ) { |
| 112 | return $recordingAnnotations->accept( |
| 113 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @param RecordingReview $recordingReview |
| 119 | * @return RecordingReview|null Same instance, or null if serialized value is null. |
| 120 | * @since 0.1.0 |
| 121 | */ |
| 122 | public function visitRecordingReview( |
| 123 | RecordingReview $recordingReview |
| 124 | ) { |
| 125 | return $recordingReview->accept( |
| 126 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 127 | ); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @param SkippedManuscriptPrompt $skippedManuscriptPrompt |
| 132 | * @return SkippedManuscriptPrompt|null Same instance, or null if serialized value is null. |
| 133 | * @since 0.1.0 |
| 134 | */ |
| 135 | public function visitSkippedManuscriptPrompt( |
| 136 | SkippedManuscriptPrompt $skippedManuscriptPrompt |
| 137 | ) { |
| 138 | return $skippedManuscriptPrompt->accept( |
| 139 | new PersistentMWAssociateArrayDeserializer( $this->array ) ); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @param User $user |
| 144 | * @return User|null Same instance, or null if serialized value is null. |
| 145 | * @since 0.1.0 |
| 146 | */ |
| 147 | public function visitUser( |
| 148 | User $user |
| 149 | ) { |
| 150 | return $user->accept( |
| 151 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 152 | ); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @param UserDialect $userDialect |
| 157 | * @return UserDialect|null Same instance, or null if serialized value is null. |
| 158 | * @since 0.1.0 |
| 159 | */ |
| 160 | public function visitUserDialect( |
| 161 | UserDialect $userDialect |
| 162 | ) { |
| 163 | return $userDialect->accept( |
| 164 | new PersistentMWAssociateArrayDeserializer( $this->array ) |
| 165 | ); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @param UserLanguageProficiencyLevel $languageProficiencyLevel |
| 170 | * @return UserLanguageProficiencyLevel|null Same instance, or null if serialized value is null. |
| 171 | * @since 0.1.0 |
| 172 | */ |
| 173 | public function visitUserLanguageProficiencyLevel( |
| 174 | UserLanguageProficiencyLevel $languageProficiencyLevel |
| 175 | ) { |
| 176 | return $languageProficiencyLevel->accept( |
| 177 | new PersistentMWAssociateArrayDeserializer( $this->array ) ); |
| 178 | } |
| 179 | |
| 180 | } |