Conditions | 1 |
Paths | 1 |
Total Lines | 80 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
96 | public function testSentenceToneAnaysis() |
||
97 | { |
||
98 | $rawResponse = '{ |
||
99 | "document_tone": { |
||
100 | "tones": [ |
||
101 | { |
||
102 | "score": 0.6165, |
||
103 | "tone_id": "sadness", |
||
104 | "tone_name": "Sadness" |
||
105 | }, |
||
106 | { |
||
107 | "score": 0.829888, |
||
108 | "tone_id": "analytical", |
||
109 | "tone_name": "Analytical" |
||
110 | } |
||
111 | ] |
||
112 | }, |
||
113 | "sentences_tone": [ |
||
114 | { |
||
115 | "sentence_id": 0, |
||
116 | "text": "Team, I know that times are tough!", |
||
117 | "tones": [ |
||
118 | { |
||
119 | "score": 0.801827, |
||
120 | "tone_id": "analytical", |
||
121 | "tone_name": "Analytical" |
||
122 | } |
||
123 | ] |
||
124 | }, |
||
125 | { |
||
126 | "sentence_id": 1, |
||
127 | "text": "Product sales have been disappointing for the past three quarters.", |
||
128 | "tones": [ |
||
129 | { |
||
130 | "score": 0.771241, |
||
131 | "tone_id": "sadness", |
||
132 | "tone_name": "Sadness" |
||
133 | }, |
||
134 | { |
||
135 | "score": 0.687768, |
||
136 | "tone_id": "analytical", |
||
137 | "tone_name": "Analytical" |
||
138 | } |
||
139 | ] |
||
140 | }, |
||
141 | { |
||
142 | "sentence_id": 2, |
||
143 | "text": "We have a competitive product, but we need to do a better job of selling it!", |
||
144 | "tones": [ |
||
145 | { |
||
146 | "score": 0.506763, |
||
147 | "tone_id": "analytical", |
||
148 | "tone_name": "Analytical" |
||
149 | } |
||
150 | ] |
||
151 | } |
||
152 | ] |
||
153 | }'; |
||
154 | |||
155 | $this->httpClient->shouldReceive('sendRequest')->once()->andReturnUsing(function () use ($rawResponse) { |
||
156 | return new Response(200, ['Content-Type' => 'application/json'], $rawResponse); |
||
157 | }); |
||
158 | |||
159 | $tone = new Tone($this->httpClient, $this->hydrator, $this->requestBuilder); |
||
160 | |||
161 | $response = $tone->analyze('text', ['content_language' => 'en', 'accept_language' => 'en']); |
||
162 | |||
163 | $sentences = $response->getSentenceAnalysis()->getSentences(); |
||
164 | |||
165 | $this->assertNotEmpty($sentences); |
||
166 | |||
167 | $firstSentence = $sentences[0]; |
||
168 | |||
169 | $this->assertEquals(0, $firstSentence->getId()); |
||
170 | $this->assertEquals('Team, I know that times are tough!', $firstSentence->getText()); |
||
171 | |||
172 | $tones = $firstSentence->getTones(); |
||
173 | |||
174 | $this->assertNotEmpty($tones); |
||
175 | } |
||
176 | |||
211 |