Code Duplication    Length = 21-22 lines in 2 locations

src/Parser.php 2 locations

@@ 124-145 (lines=22) @@
121
    /**
122
     * @return Ast\Term|Ast\Disjunction
123
     */
124
    private function disjunction()
125
    {
126
        /** @var Ast\Term[] $terms */
127
        $terms = [];
128
        $terms[] = $this->conjunction();
129
130
        if ($this->lexer->isNextToken(Tokens::T_SP)) {
131
            $nextToken = $this->lexer->glimpse();
132
            if ($nextToken && $nextToken->is(Tokens::T_OR)) {
133
                $this->match(Tokens::T_SP);
134
                $this->match(Tokens::T_OR);
135
                $this->match(Tokens::T_SP);
136
                $terms[] = $this->conjunction();
137
            }
138
        }
139
140
        if (count($terms) == 1) {
141
            return $terms[0];
142
        }
143
144
        return new Ast\Disjunction($terms);
145
    }
146
147
    /**
148
     * @return Ast\Conjunction|Ast\Factor
@@ 150-170 (lines=21) @@
147
    /**
148
     * @return Ast\Conjunction|Ast\Factor
149
     */
150
    private function conjunction()
151
    {
152
        $factors = [];
153
        $factors[] = $this->factor();
154
155
        if ($this->lexer->isNextToken(Tokens::T_SP)) {
156
            $nextToken = $this->lexer->glimpse();
157
            if ($nextToken && $nextToken->is(Tokens::T_AND)) {
158
                $this->match(Tokens::T_SP);
159
                $this->match(Tokens::T_AND);
160
                $this->match(Tokens::T_SP);
161
                $factors[] = $this->factor();
162
            }
163
        }
164
165
        if (count($factors) == 1) {
166
            return $factors[0];
167
        }
168
169
        return new Ast\Conjunction($factors);
170
    }
171
172
    /**
173
     * @return Ast\Filter