Code Duplication    Length = 17-22 lines in 5 locations

src/Query/Parser.php 1 location

@@ 16-37 (lines=22) @@
13
        return Token::getNameFor($tokenType);
14
    }
15
16
    private function parseObject()
17
    {
18
        $location = $this->expect(Token::T_BRACE_LEFT)->location;
19
        $fields = array();
20
21
        while (true) {
22
            if ($this->scanner->eof()) {
23
                throw $this->getParseError('Unclosed brace of object value');
24
            }
25
26
            if ($this->accept(Token::T_BRACE_RIGHT)) {
27
                break;
28
            }
29
30
            $nameToken = $this->expect(Token::T_NAME);
31
            $this->expect(Token::T_COLON);
32
            $fields[] = new ValueObjectField($nameToken->value, $this->parseValue(), $nameToken->location);
33
            $this->accept(Token::T_COMMA);
34
        }
35
36
        return new ValueObject($fields, $location);
37
    }
38
39
    private function parseList()
40
    {

src/Schema/Parser.php 4 locations

@@ 72-88 (lines=17) @@
69
        throw $this->getParseError($message . " but instead found \"{$token->getName()}\" with value \"{$token->value}\"");
70
    }
71
72
    private function parseObject()
73
    {
74
        $location = $this->expect(Token::T_BRACE_LEFT)->location;
75
        $fields = array();
76
        while ($this->scanner->eof() === false) {
77
            if ($this->accept(Token::T_BRACE_RIGHT)) {
78
                return new ValueObject($fields, $location);
79
            }
80
81
            $nameToken = $this->expect(Token::T_NAME);
82
            $this->expect(Token::T_COLON);
83
            $fields[] = new ValueObjectField($nameToken->value, $this->parseValue(), $nameToken->location);
84
            $this->accept(Token::T_COMMA);
85
        }
86
87
        throw $this->getParseError('Unclosed brace of object value');
88
    }
89
90
    private function parseList()
91
    {
@@ 241-261 (lines=21) @@
238
        throw $this->getParseError('Expected an object field but instead reached end');
239
    }
240
241
    private function parseInputObjectDeclaration()
242
    {
243
        $location = $this->expect(Token::T_NAME)->location;
244
        $name = $this->expect(Token::T_NAME)->value;
245
        $this->expect(Token::T_BRACE_LEFT);
246
        $fields = array();
247
        while ($this->scanner->eof() === false) {
248
            if ($this->accept(Token::T_BRACE_RIGHT)) {
249
                return new DeclarationInputObject(
250
                    $name,
251
                    $fields,
252
                    $location
253
                );
254
            }
255
256
            $fields[] = $this->parseField(true);
257
            $this->accept(Token::T_COMMA);
258
        }
259
260
        throw $this->getParseError('Expected an input object field but instead reached end');
261
    }
262
263
    private function parseEnumDeclaration()
264
    {
@@ 263-283 (lines=21) @@
260
        throw $this->getParseError('Expected an input object field but instead reached end');
261
    }
262
263
    private function parseEnumDeclaration()
264
    {
265
        $location = $this->expect(Token::T_NAME)->location;
266
        $name = $this->expect(Token::T_NAME)->value;
267
        $this->expect(Token::T_BRACE_LEFT);
268
        $values = array();
269
        while ($this->scanner->eof() === false) {
270
            if ($this->accept(Token::T_BRACE_RIGHT)) {
271
                return new DeclarationEnum(
272
                    $name,
273
                    $values,
274
                    $location
275
                );
276
            }
277
278
            $values[] = $this->expect(Token::T_NAME)->value;
279
            $this->accept(Token::T_COMMA);
280
        }
281
282
        throw $this->getParseError('Expected an enumeration value but instead reached end');
283
    }
284
285
    private function parseInterfaceDeclaration()
286
    {
@@ 285-305 (lines=21) @@
282
        throw $this->getParseError('Expected an enumeration value but instead reached end');
283
    }
284
285
    private function parseInterfaceDeclaration()
286
    {
287
        $location = $this->expect(Token::T_NAME)->location;
288
        $name = $this->expect(Token::T_NAME)->value;
289
        $this->expect(Token::T_BRACE_LEFT);
290
        $fields = array();
291
        while ($this->scanner->eof() === false) {
292
            if ($this->accept(Token::T_BRACE_RIGHT)) {
293
                return new DeclarationInterface(
294
                    $name,
295
                    $fields,
296
                    $location
297
                );
298
            }
299
300
            $fields[] = $this->parseField(false);
301
            $this->accept(Token::T_COMMA);
302
        }
303
304
        throw $this->getParseError('Expected an interface field but instead reached end');
305
    }
306
307
    private function parseUnionDeclaration()
308
    {