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