Code Duplication    Length = 10-12 lines in 6 locations

src/Internal/JsonDecodeReader.php 4 locations

@@ 151-160 (lines=10) @@
148
     * @return bool
149
     * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not BOOLEAN
150
     */
151
    public function nextBoolean(): bool
152
    {
153
        if ($this->peek() !== JsonToken::BOOLEAN) {
154
            throw new UnexpectedJsonTokenException(
155
                sprintf('Expected "%s", but found "%s"', JsonToken::BOOLEAN, $this->peek())
156
            );
157
        }
158
159
        return $this->pop();
160
    }
161
162
    /**
163
     * Consumes the value of the next token, asserts it's a double and returns it
@@ 168-177 (lines=10) @@
165
     * @return double
166
     * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NUMBER
167
     */
168
    public function nextDouble(): float
169
    {
170
        if ($this->peek() !== JsonToken::NUMBER) {
171
            throw new UnexpectedJsonTokenException(
172
                sprintf('Expected "%s", but found "%s"', JsonToken::NUMBER, $this->peek())
173
            );
174
        }
175
176
        return (float)$this->pop();
177
    }
178
179
    /**
180
     * Consumes the value of the next token, asserts it's an int and returns it
@@ 185-194 (lines=10) @@
182
     * @return int
183
     * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NUMBER
184
     */
185
    public function nextInteger(): int
186
    {
187
        if ($this->peek() !== JsonToken::NUMBER) {
188
            throw new UnexpectedJsonTokenException(
189
                sprintf('Expected "%s", but found "%s"', JsonToken::NUMBER, $this->peek())
190
            );
191
        }
192
193
        return (int)$this->pop();
194
    }
195
196
    /**
197
     * Consumes the value of the next token, asserts it's a string and returns it
@@ 224-235 (lines=12) @@
221
     * @return null
222
     * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NAME or NULL
223
     */
224
    public function nextNull()
225
    {
226
        if ($this->peek() !== JsonToken::NULL) {
227
            throw new UnexpectedJsonTokenException(
228
                sprintf('Expected "%s", but found "%s"', JsonToken::NULL, $this->peek())
229
            );
230
        }
231
232
        $this->pop();
233
234
        return null;
235
    }
236
237
    /**
238
     * Consumes the next name and returns it

src/Internal/JsonElementReader.php 2 locations

@@ 174-183 (lines=10) @@
171
     * @return double
172
     * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NUMBER
173
     */
174
    public function nextDouble(): float
175
    {
176
        if ($this->peek() !== JsonToken::NUMBER) {
177
            throw new UnexpectedJsonTokenException(
178
                sprintf('Expected "%s", but found "%s"', JsonToken::NUMBER, $this->peek())
179
            );
180
        }
181
182
        return $this->pop()->asFloat();
183
    }
184
185
    /**
186
     * Consumes the value of the next token, asserts it's an int and returns it
@@ 230-241 (lines=12) @@
227
     * @return null
228
     * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NAME or NULL
229
     */
230
    public function nextNull()
231
    {
232
        if ($this->peek() !== JsonToken::NULL) {
233
            throw new UnexpectedJsonTokenException(
234
                sprintf('Expected "%s", but found "%s"', JsonToken::NULL, $this->peek())
235
            );
236
        }
237
238
        $this->pop();
239
240
        return null;
241
    }
242
243
    /**
244
     * Consumes the next name and returns it