From 8fe3eb03228d327c74c5befe1d4680d567644b0a Mon Sep 17 00:00:00 2001 From: Bas de Groot Date: Tue, 11 Aug 2020 11:11:16 +0200 Subject: [PATCH] code sniffer clean up --- src/Clauses/CollectClause.php | 2 +- src/Clauses/EdgeCollectionsClause.php | 4 +- src/Clauses/FilterClause.php | 4 +- src/Clauses/ForClause.php | 2 +- src/Clauses/GraphClause.php | 2 +- src/Clauses/GroupClause.php | 4 +- src/Clauses/KeepClause.php | 2 +- src/Clauses/LimitClause.php | 4 +- src/Clauses/OptionsClause.php | 2 +- src/Clauses/PruneClause.php | 2 +- src/Clauses/ReturnClause.php | 2 +- src/Clauses/SearchClause.php | 2 +- src/Clauses/SortClause.php | 2 +- src/Clauses/TraverseClause.php | 4 +- src/Clauses/WithCountClause.php | 2 +- src/Expressions/ConditionalExpression.php | 2 +- src/Expressions/FunctionExpression.php | 6 +-- src/Expressions/ListExpression.php | 2 +- src/Expressions/ObjectExpression.php | 4 +- src/Expressions/PredicateExpression.php | 2 +- src/Expressions/TernaryExpression.php | 2 +- src/Grammar.php | 4 +- src/QueryBuilder.php | 6 +-- src/Traits/NormalizesExpressions.php | 8 ++-- src/Traits/ValidatesExpressions.php | 8 ++-- tests/unit/QueryBuilderTest.php | 8 ++-- tests/unit/QueryClausesTest.php | 16 ++++---- tests/unit/StatementClausesTest.php | 48 +++++++++++------------ 28 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/Clauses/CollectClause.php b/src/Clauses/CollectClause.php index dfe3569..f093499 100644 --- a/src/Clauses/CollectClause.php +++ b/src/Clauses/CollectClause.php @@ -19,7 +19,7 @@ public function compile() { $output = 'COLLECT'; if (isset($this->variableName) && isset($this->expression)) { - $output .= ' '.$this->variableName.' = '.$this->expression; + $output .= ' ' . $this->variableName . ' = ' . $this->expression; } return $output; diff --git a/src/Clauses/EdgeCollectionsClause.php b/src/Clauses/EdgeCollectionsClause.php index 760de70..09332c5 100644 --- a/src/Clauses/EdgeCollectionsClause.php +++ b/src/Clauses/EdgeCollectionsClause.php @@ -18,10 +18,10 @@ public function compile() return implode(', ', array_map(function ($expression) { $output = ''; if (isset($expression[1])) { - $output = $expression[1].' '; + $output = $expression[1] . ' '; } - return $output.$expression[0]; + return $output . $expression[0]; }, $this->edgeCollections)); } } diff --git a/src/Clauses/FilterClause.php b/src/Clauses/FilterClause.php index aaef8d0..4b7eb9d 100644 --- a/src/Clauses/FilterClause.php +++ b/src/Clauses/FilterClause.php @@ -26,7 +26,7 @@ public function compile() { $compiledPredicates = $this->compilePredicates($this->predicates); - return 'FILTER '.rtrim($compiledPredicates); + return 'FILTER ' . rtrim($compiledPredicates); } protected function compilePredicates($predicates, $compiledPredicates = '') @@ -35,7 +35,7 @@ protected function compilePredicates($predicates, $compiledPredicates = '') foreach ($predicates as $predicate) { if ($predicate instanceof PredicateExpression) { if ($compiledPredicates != '' && $compiledPredicates !== '(') { - $compiledPredicates .= ' '.$predicate->logicalOperator.' '; + $compiledPredicates .= ' ' . $predicate->logicalOperator . ' '; } $compiledPredicates .= $predicate; } diff --git a/src/Clauses/ForClause.php b/src/Clauses/ForClause.php index a8fdf9d..c771464 100644 --- a/src/Clauses/ForClause.php +++ b/src/Clauses/ForClause.php @@ -31,7 +31,7 @@ public function compile() $inExpression = (string) $this->in; if (is_array($this->in)) { - $inExpression = '['.implode(', ', $this->in).']'; + $inExpression = '[' . implode(', ', $this->in) . ']'; } return "FOR {$variableExpression} IN {$inExpression}"; diff --git a/src/Clauses/GraphClause.php b/src/Clauses/GraphClause.php index 6518341..9185abf 100644 --- a/src/Clauses/GraphClause.php +++ b/src/Clauses/GraphClause.php @@ -13,6 +13,6 @@ public function __construct($graphName) public function compile() { - return 'GRAPH '.$this->graphName; + return 'GRAPH ' . $this->graphName; } } diff --git a/src/Clauses/GroupClause.php b/src/Clauses/GroupClause.php index 798aca6..f6c2c73 100644 --- a/src/Clauses/GroupClause.php +++ b/src/Clauses/GroupClause.php @@ -15,9 +15,9 @@ public function __construct($groupsVariable, $projectionExpression = null) public function compile() { - $output = 'INTO '.$this->groupsVariable; + $output = 'INTO ' . $this->groupsVariable; if (isset($this->projectionExpression)) { - $output .= ' = '.$this->projectionExpression; + $output .= ' = ' . $this->projectionExpression; } return $output; diff --git a/src/Clauses/KeepClause.php b/src/Clauses/KeepClause.php index 95fb42f..cae60e1 100644 --- a/src/Clauses/KeepClause.php +++ b/src/Clauses/KeepClause.php @@ -13,6 +13,6 @@ public function __construct($keepVariable) public function compile() { - return 'KEEP '.$this->keepVariable; + return 'KEEP ' . $this->keepVariable; } } diff --git a/src/Clauses/LimitClause.php b/src/Clauses/LimitClause.php index 3f89784..e14abc4 100644 --- a/src/Clauses/LimitClause.php +++ b/src/Clauses/LimitClause.php @@ -30,9 +30,9 @@ public function compile() { $output = 'LIMIT '; if ($this->offset !== null) { - $output .= $this->offset.', '; + $output .= $this->offset . ', '; } - return $output.$this->count; + return $output . $this->count; } } diff --git a/src/Clauses/OptionsClause.php b/src/Clauses/OptionsClause.php index 119ad65..35cbf7b 100644 --- a/src/Clauses/OptionsClause.php +++ b/src/Clauses/OptionsClause.php @@ -13,6 +13,6 @@ public function __construct($options) public function compile() { - return 'OPTIONS '.$this->options; + return 'OPTIONS ' . $this->options; } } diff --git a/src/Clauses/PruneClause.php b/src/Clauses/PruneClause.php index 3d18fb8..d862633 100644 --- a/src/Clauses/PruneClause.php +++ b/src/Clauses/PruneClause.php @@ -12,6 +12,6 @@ public function compile() { $compiledPredicates = $this->compilePredicates($this->predicates); - return 'PRUNE '.rtrim($compiledPredicates); + return 'PRUNE ' . rtrim($compiledPredicates); } } diff --git a/src/Clauses/ReturnClause.php b/src/Clauses/ReturnClause.php index e91309e..a480eb1 100644 --- a/src/Clauses/ReturnClause.php +++ b/src/Clauses/ReturnClause.php @@ -30,6 +30,6 @@ public function compile() $output .= ' DISTINCT'; } - return $output.' '.$this->expression; + return $output . ' ' . $this->expression; } } diff --git a/src/Clauses/SearchClause.php b/src/Clauses/SearchClause.php index 11da1c6..ca5030e 100644 --- a/src/Clauses/SearchClause.php +++ b/src/Clauses/SearchClause.php @@ -12,6 +12,6 @@ public function compile() { $compiledPredicates = $this->compilePredicates($this->predicates); - return 'SEARCH '.rtrim($compiledPredicates); + return 'SEARCH ' . rtrim($compiledPredicates); } } diff --git a/src/Clauses/SortClause.php b/src/Clauses/SortClause.php index 5670468..87ac064 100644 --- a/src/Clauses/SortClause.php +++ b/src/Clauses/SortClause.php @@ -19,6 +19,6 @@ public function compile() return implode(' ', $expression); }, $this->by)); - return 'SORT '.$sortBy; + return 'SORT ' . $sortBy; } } diff --git a/src/Clauses/TraverseClause.php b/src/Clauses/TraverseClause.php index c8b58fb..45e3512 100644 --- a/src/Clauses/TraverseClause.php +++ b/src/Clauses/TraverseClause.php @@ -39,9 +39,9 @@ public function compile() if (isset($this->toVertex)) { $output .= ($this->kShortestPaths) ? ' K_SHORTEST_PATHS' : ' SHORTEST_PATH'; } - $output .= ' '.$this->startVertex; + $output .= ' ' . $this->startVertex; if (isset($this->toVertex)) { - $output .= ' TO '.$this->toVertex; + $output .= ' TO ' . $this->toVertex; } return $output; diff --git a/src/Clauses/WithCountClause.php b/src/Clauses/WithCountClause.php index 019d42e..8c1c8a8 100644 --- a/src/Clauses/WithCountClause.php +++ b/src/Clauses/WithCountClause.php @@ -13,6 +13,6 @@ public function __construct($countVariableName) public function compile() { - return 'WITH COUNT INTO '.$this->countVariableName; + return 'WITH COUNT INTO ' . $this->countVariableName; } } diff --git a/src/Expressions/ConditionalExpression.php b/src/Expressions/ConditionalExpression.php index c6bb9c6..31ad8ff 100644 --- a/src/Expressions/ConditionalExpression.php +++ b/src/Expressions/ConditionalExpression.php @@ -23,6 +23,6 @@ public function __construct($if, $then, $else = null) public function compile() { - return $this->parameters['if'].' ? '.$this->parameters['then'].' : '.$this->parameters['else']; + return $this->parameters['if'] . ' ? ' . $this->parameters['then'] . ' : ' . $this->parameters['else']; } } diff --git a/src/Expressions/FunctionExpression.php b/src/Expressions/FunctionExpression.php index 944cce0..f9fb424 100644 --- a/src/Expressions/FunctionExpression.php +++ b/src/Expressions/FunctionExpression.php @@ -42,15 +42,15 @@ public function __construct(string $functionName, $parameters = []) public function compile() { - $output = strtoupper($this->functionName).'('; + $output = strtoupper($this->functionName) . '('; $implosion = ''; foreach ($this->parameters as $parameter) { - $implosion .= ', '.(string) $parameter; + $implosion .= ', ' . (string) $parameter; } if ($implosion != '') { $output .= ltrim($implosion, ', '); } - return $output.')'; + return $output . ')'; } } diff --git a/src/Expressions/ListExpression.php b/src/Expressions/ListExpression.php index c0da697..75a772a 100644 --- a/src/Expressions/ListExpression.php +++ b/src/Expressions/ListExpression.php @@ -17,6 +17,6 @@ public function __construct(array $expression) public function compile() { - return '['.implode(',', $this->expression).']'; + return '[' . implode(',', $this->expression) . ']'; } } diff --git a/src/Expressions/ObjectExpression.php b/src/Expressions/ObjectExpression.php index bb072fc..89ae352 100644 --- a/src/Expressions/ObjectExpression.php +++ b/src/Expressions/ObjectExpression.php @@ -14,9 +14,9 @@ public function compile() if ($output != '') { $output .= ','; } - $output .= '"'.$key.'":'.$value; + $output .= '"' . $key . '":' . $value; } - return '{'.$output.'}'; + return '{' . $output . '}'; } } diff --git a/src/Expressions/PredicateExpression.php b/src/Expressions/PredicateExpression.php index 4224f1e..f94f9ff 100644 --- a/src/Expressions/PredicateExpression.php +++ b/src/Expressions/PredicateExpression.php @@ -43,6 +43,6 @@ public function __construct( */ public function compile() { - return $this->leftOperand.' '.$this->comparisonOperator.' '.$this->rightOperand; + return $this->leftOperand . ' ' . $this->comparisonOperator . ' ' . $this->rightOperand; } } diff --git a/src/Expressions/TernaryExpression.php b/src/Expressions/TernaryExpression.php index 0609424..5b916f1 100644 --- a/src/Expressions/TernaryExpression.php +++ b/src/Expressions/TernaryExpression.php @@ -34,6 +34,6 @@ public function __construct($if, $then, $else = null) */ public function compile() { - return $this->if.' ? '.$this->then.' : '.$this->else; + return $this->if . ' ? ' . $this->then . ' : ' . $this->else; } } diff --git a/src/Grammar.php b/src/Grammar.php index 2beb6db..55b7bf7 100644 --- a/src/Grammar.php +++ b/src/Grammar.php @@ -136,7 +136,7 @@ public function getDateFormat() public function wrap($value): string { - return '`'.addcslashes($value, '`').'`'; + return '`' . addcslashes($value, '`') . '`'; } public function mapArgumentTypeToExpressionType($argumentType): string @@ -155,7 +155,7 @@ public function formatBind(string $bindVariableName, bool $collection = null) $prefix = '@@'; } - return $prefix.$bindVariableName; + return $prefix . $bindVariableName; } public function getAllowedExpressionTypes() diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 2e55acd..bb5dcb4 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -203,7 +203,7 @@ public function bind($data, $to = null, $collection = false): BindExpression } if ($to == null) { - $to = $this->queryId.'_'.(count($this->binds) + 1); + $to = $this->queryId . '_' . (count($this->binds) + 1); } $this->binds[$to] = $data; @@ -224,7 +224,7 @@ public function compile(): self foreach ($this->commands as $command) { $result = $command->compile(); - $this->query .= ' '.$result; + $this->query .= ' ' . $result; if ($command instanceof self) { // Extract binds @@ -239,7 +239,7 @@ public function compile(): self $this->query = trim($this->query); if ($this->isSubQuery) { - $this->query = '('.$this->query.')'; + $this->query = '(' . $this->query . ')'; } return $this; diff --git a/src/Traits/NormalizesExpressions.php b/src/Traits/NormalizesExpressions.php index 886d186..c457da8 100644 --- a/src/Traits/NormalizesExpressions.php +++ b/src/Traits/NormalizesExpressions.php @@ -56,7 +56,7 @@ protected function createExpression($argument, $argumentType) return $this->bind($argument); } - $expressionClass = '\LaravelFreelancerNL\FluentAQL\Expressions\\'.$expressionType.'Expression'; + $expressionClass = '\LaravelFreelancerNL\FluentAQL\Expressions\\' . $expressionType . 'Expression'; return new $expressionClass($argument); } @@ -200,7 +200,7 @@ protected function determineArgumentType($argument, $allowedExpressionTypes = nu } foreach ($allowedExpressionTypes as $allowedExpressionType) { - $check = 'is'.$allowedExpressionType; + $check = 'is' . $allowedExpressionType; if ($allowedExpressionType == 'Reference' || $allowedExpressionType == 'RegisteredVariable') { if ($this->grammar->$check($argument, $this->variables)) { return $allowedExpressionType; @@ -218,8 +218,8 @@ protected function determineArgumentType($argument, $allowedExpressionTypes = nu } throw new ExpressionTypeException("This argument, '{$argument}', does not match one of these expression types: " - .implode(', ', $allowedExpressionTypes) - .'.'); + . implode(', ', $allowedExpressionTypes) + . '.'); } /** diff --git a/src/Traits/ValidatesExpressions.php b/src/Traits/ValidatesExpressions.php index f5ebffb..f83aca1 100644 --- a/src/Traits/ValidatesExpressions.php +++ b/src/Traits/ValidatesExpressions.php @@ -191,7 +191,7 @@ public function isRegisteredVariable($value, $registeredVariables = []): bool public function isAttribute($value): bool { $pattern = '/^(@?[\d\w_]+|`@?[\d\w_]+`)(\[\`.+\`\]|\[[\d\w\*]*\])*' - .'(\.(\`.+\`|@?[\d\w]*)(\[\`.+\`\]|\[[\d\w\*]*\])*)*$/'; + . '(\.(\`.+\`|@?[\d\w]*)(\[\`.+\`\]|\[[\d\w\*]*\])*)*$/'; if ( is_string($value) && preg_match($pattern, $value) @@ -212,14 +212,14 @@ public function isReference($value, $registeredVariables = []): bool { $variables = ''; if (!empty($registeredVariables)) { - $variables = implode('|', $registeredVariables).'|'; + $variables = implode('|', $registeredVariables) . '|'; } if ( is_string($value) && preg_match('/^(' - .$variables - .'NEW|OLD)(\[\`.+\`\]|\[[\d\w\*]*\])*(\.(\`.+\`|@?[\d\w]*)(\[\`.+\`\]|\[[\d\w\*]*\])*)*$/', $value) + . $variables + . 'NEW|OLD)(\[\`.+\`\]|\[[\d\w\*]*\])*(\.(\`.+\`|@?[\d\w]*)(\[\`.+\`\]|\[[\d\w\*]*\])*)*$/', $value) ) { return true; } diff --git a/tests/unit/QueryBuilderTest.php b/tests/unit/QueryBuilderTest.php index fe11c21..7ad942c 100644 --- a/tests/unit/QueryBuilderTest.php +++ b/tests/unit/QueryBuilderTest.php @@ -66,11 +66,11 @@ public function testBind() ] }'); self::assertInstanceOf(BindExpression::class, $bind); - self::assertEquals('@'.$qb->getQueryId().'_1', (string) $bind); + self::assertEquals('@' . $qb->getQueryId() . '_1', (string) $bind); - self::arrayHasKey($qb->getQueryId().'_1'); - self::assertIsString($qb->binds[$qb->getQueryId().'_1']); - self::assertEquals(121, strlen($qb->binds[$qb->getQueryId().'_1'])); + self::arrayHasKey($qb->getQueryId() . '_1'); + self::assertIsString($qb->binds[$qb->getQueryId() . '_1']); + self::assertEquals(121, strlen($qb->binds[$qb->getQueryId() . '_1'])); } public function testRegisterCollections() diff --git a/tests/unit/QueryClausesTest.php b/tests/unit/QueryClausesTest.php index 1a085ad..934e93c 100644 --- a/tests/unit/QueryClausesTest.php +++ b/tests/unit/QueryClausesTest.php @@ -32,7 +32,7 @@ public function testCollectClause() $result = (new QueryBuilder()) ->collect('doc', 'expression') ->get(); - self::assertEquals('COLLECT doc = @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('COLLECT doc = @' . $result->getQueryId() . '_1', $result->query); $result = (new QueryBuilder()) ->for('u', 'Users') @@ -51,14 +51,14 @@ public function testGroupClause() $result = (new QueryBuilder()) ->group('groupsVariable', 'projectionExpression') ->get(); - self::assertEquals('INTO groupsVariable = @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('INTO groupsVariable = @' . $result->getQueryId() . '_1', $result->query); $result = (new QueryBuilder()) ->group('groupsVariable', '{ "name" : u.name, "isActive" : u.status == "active" }')->get(); - self::assertEquals('INTO groupsVariable = @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('INTO groupsVariable = @' . $result->getQueryId() . '_1', $result->query); } public function testAggregateClause() @@ -66,7 +66,7 @@ public function testAggregateClause() $result = (new QueryBuilder()) ->aggregate('variableName', 'aggregateExpression') ->get(); - self::assertEquals('AGGREGATE variableName = @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('AGGREGATE variableName = @' . $result->getQueryId() . '_1', $result->query); } public function testKeepClause() @@ -168,7 +168,7 @@ public function testFilterOnNullValueCanUseAllLogicalOperators() ->get(); self::assertEquals( 'FOR doc IN documents FILTER doc.attribute1 != null AND doc.attribute2 != null' - .' AND doc.attribute3 != null RETURN doc', + . ' AND doc.attribute3 != null RETURN doc', $result->query ); } @@ -312,7 +312,7 @@ public function testReturnSyntax() $result = (new QueryBuilder()) ->return('u.name') ->get(); - self::assertEquals('RETURN @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('RETURN @' . $result->getQueryId() . '_1', $result->query); $result = (new QueryBuilder()) ->for('u', 'Users') @@ -323,11 +323,11 @@ public function testReturnSyntax() $result = (new QueryBuilder()) ->return('1 + 1') ->get(); - self::assertEquals('RETURN @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('RETURN @' . $result->getQueryId() . '_1', $result->query); $result = (new QueryBuilder()) ->return('1 + 1', true) ->get(); - self::assertEquals('RETURN DISTINCT @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('RETURN DISTINCT @' . $result->getQueryId() . '_1', $result->query); } } diff --git a/tests/unit/StatementClausesTest.php b/tests/unit/StatementClausesTest.php index da11084..6dc3252 100644 --- a/tests/unit/StatementClausesTest.php +++ b/tests/unit/StatementClausesTest.php @@ -26,7 +26,7 @@ public function testLetStatement() "C" ] }')->get(); - self::assertEquals('LET x = @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('LET x = @' . $result->getQueryId() . '_1', $result->query); $qb = new QueryBuilder(); $object = new \stdClass(); @@ -39,18 +39,18 @@ public function testLetStatement() ->get(); self::assertEquals( 'LET x = {"name":"Catelyn","surname":"Stark","alive":false,"age":40,"traits":[@' - .$result->getQueryId() - .'_1,@' - .$result->getQueryId() - .'_2,@' - .$result->getQueryId() - .'_3]}', + . $result->getQueryId() + . '_1,@' + . $result->getQueryId() + . '_2,@' + . $result->getQueryId() + . '_3]}', $result->query ); $result = (new QueryBuilder())->let('x', 'y') ->get(); - self::assertEquals('LET x = @'.$result->getQueryId().'_1', $result->query); + self::assertEquals('LET x = @' . $result->getQueryId() . '_1', $result->query); } /** @@ -71,7 +71,7 @@ public function insert() "C" ] }', 'Characters')->get(); - self::assertEquals('INSERT @'.$result->getQueryId().'_1 IN Characters', $result->query); + self::assertEquals('INSERT @' . $result->getQueryId() . '_1 IN Characters', $result->query); } /** @@ -88,7 +88,7 @@ public function update() '{ name: CONCAT(u.firstName, " ", u.lastName) }', 'users' )->get(); - self::assertEquals('FOR u IN users UPDATE u WITH @'.$result->getQueryId().'_1 IN users', $result->query); + self::assertEquals('FOR u IN users UPDATE u WITH @' . $result->getQueryId() . '_1 IN users', $result->query); } /** @@ -106,7 +106,7 @@ public function replace() 'users' ) ->get(); - self::assertEquals('FOR u IN users REPLACE u WITH @'.$result->getQueryId().'_1 IN users', $result->query); + self::assertEquals('FOR u IN users REPLACE u WITH @' . $result->getQueryId() . '_1 IN users', $result->query); } /** @@ -131,7 +131,7 @@ public function remove() ->for('i', '1..1000') ->remove('{ _key: CONCAT(\'test\', i) }', 'users') ->get(); - self::assertEquals('FOR i IN 1..1000 REMOVE @'.$result->getQueryId().'_1 IN users', $result->query); + self::assertEquals('FOR i IN 1..1000 REMOVE @' . $result->getQueryId() . '_1 IN users', $result->query); } /** @@ -150,12 +150,12 @@ public function upsert() )->get(); self::assertEquals( 'UPSERT @' - .$result->getQueryId() - .'_1 INSERT @' - .$result->getQueryId() - .'_2 UPDATE @' - .$result->getQueryId() - .'_3 IN users', + . $result->getQueryId() + . '_1 INSERT @' + . $result->getQueryId() + . '_2 UPDATE @' + . $result->getQueryId() + . '_3 IN users', $result->query ); @@ -169,12 +169,12 @@ public function upsert() )->get(); self::assertEquals( 'UPSERT @' - .$result->getQueryId() - .'_1 INSERT @' - .$result->getQueryId() - .'_2 REPLACE @' - .$result->getQueryId() - .'_3 IN users', + . $result->getQueryId() + . '_1 INSERT @' + . $result->getQueryId() + . '_2 REPLACE @' + . $result->getQueryId() + . '_3 IN users', $result->query ); }