Skip to content

Conversation

sshilko
Copy link
Contributor

@sshilko sshilko commented Jan 16, 2019

Prevent boilerplace code for constructing comples (A AND (B OR C)) queries and enforce parenthesis by

  • wrapping multiple matches into another match (enforces "( many matches )") via matchAndMatch()
  • helper for field IN selector to build match code for "@field A | B | C", to get rid of boilerplace everytime (cant do orMatch, must first ->match)

Feel free to rename the functions, i find them usefull in my project to prevent boilerplace

 $matches = [];
 $matches[] = $sphql->matchFieldIN('field_a', [1,2,3]);
 $matches[] = $sphql->matchFieldIN('field_b', [4,5,6]);
 $sphql->resetMatch()->match($sphql->matchAndMatch($matches));
//generates ("(@field_a 1 | 2 | 3) (@field_b 4 | 5 | 6)") without boilerplate

// (A1 AND (B2 OR C3)) still needs boilerplace like this
                    $mymatch  = (new Match($sphql))->match($mymatch1)
                                                   ->orMatch()
                                                   ->match((new Match($sphql))->match($mymatch2)->orMatch($mymatch3));

Prevent boilerplace code for constructing comples (A AND (B OR C)) queries and enforce parenthesis by 

- wrapping multiple matches into another match (enforces "( many matches )") via matchAndMatch()
- helper for field IN selector to build match code for "@field A | B | C", to get rid of boilerplace everytime (cant do orMatch, must first ->match)

Feel free to rename the functions, i find them usefull in my project to prevent boilerplace

```
 $matches = [];
 $matches[] = $sphql->matchFieldIN('field_a', [1,2,3]);
 $matches[] = $sphql->matchFieldIN('field_b', [4,5,6]);
 $sphql->resetMatch()->match($sphql->matchAndMatch($matches));
//generates ("(@field_a 1 | 2 | 3) (@field_b 4 | 5 | 6)") without boilerplate

// (A1 AND (B2 OR C3)) still needs boilerplace like this
                    $mymatch  = (new Match($sphql))->match($mymatch1)
                                                   ->orMatch()
                                                   ->match((new Match($sphql))->match($mymatch2)->orMatch($mymatch3));

```
@scrutinizer-notifier
Copy link

The inspection completed: 5 new issues, 2 updated code elements

Copy link
Contributor

@oohnoitz oohnoitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sshilko this looks fine, but we might want some unit tests written to make sure that the compiled query is correct and also some documentation added to README.md. Can you make those changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants