Skip to content

Commit

Permalink
code sniffer clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
LaravelFreelancerNL committed Aug 11, 2020
1 parent d997139 commit 8fe3eb0
Show file tree
Hide file tree
Showing 28 changed files with 78 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/Clauses/CollectClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Clauses/EdgeCollectionsClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
4 changes: 2 additions & 2 deletions src/Clauses/FilterClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '')
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Clauses/ForClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down
2 changes: 1 addition & 1 deletion src/Clauses/GraphClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function __construct($graphName)

public function compile()
{
return 'GRAPH '.$this->graphName;
return 'GRAPH ' . $this->graphName;
}
}
4 changes: 2 additions & 2 deletions src/Clauses/GroupClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Clauses/KeepClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function __construct($keepVariable)

public function compile()
{
return 'KEEP '.$this->keepVariable;
return 'KEEP ' . $this->keepVariable;
}
}
4 changes: 2 additions & 2 deletions src/Clauses/LimitClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Clauses/OptionsClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function __construct($options)

public function compile()
{
return 'OPTIONS '.$this->options;
return 'OPTIONS ' . $this->options;
}
}
2 changes: 1 addition & 1 deletion src/Clauses/PruneClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public function compile()
{
$compiledPredicates = $this->compilePredicates($this->predicates);

return 'PRUNE '.rtrim($compiledPredicates);
return 'PRUNE ' . rtrim($compiledPredicates);
}
}
2 changes: 1 addition & 1 deletion src/Clauses/ReturnClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function compile()
$output .= ' DISTINCT';
}

return $output.' '.$this->expression;
return $output . ' ' . $this->expression;
}
}
2 changes: 1 addition & 1 deletion src/Clauses/SearchClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public function compile()
{
$compiledPredicates = $this->compilePredicates($this->predicates);

return 'SEARCH '.rtrim($compiledPredicates);
return 'SEARCH ' . rtrim($compiledPredicates);
}
}
2 changes: 1 addition & 1 deletion src/Clauses/SortClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function compile()
return implode(' ', $expression);
}, $this->by));

return 'SORT '.$sortBy;
return 'SORT ' . $sortBy;
}
}
4 changes: 2 additions & 2 deletions src/Clauses/TraverseClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Clauses/WithCountClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function __construct($countVariableName)

public function compile()
{
return 'WITH COUNT INTO '.$this->countVariableName;
return 'WITH COUNT INTO ' . $this->countVariableName;
}
}
2 changes: 1 addition & 1 deletion src/Expressions/ConditionalExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
6 changes: 3 additions & 3 deletions src/Expressions/FunctionExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ')';
}
}
2 changes: 1 addition & 1 deletion src/Expressions/ListExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public function __construct(array $expression)

public function compile()
{
return '['.implode(',', $this->expression).']';
return '[' . implode(',', $this->expression) . ']';
}
}
4 changes: 2 additions & 2 deletions src/Expressions/ObjectExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public function compile()
if ($output != '') {
$output .= ',';
}
$output .= '"'.$key.'":'.$value;
$output .= '"' . $key . '":' . $value;
}

return '{'.$output.'}';
return '{' . $output . '}';
}
}
2 changes: 1 addition & 1 deletion src/Expressions/PredicateExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public function __construct(
*/
public function compile()
{
return $this->leftOperand.' '.$this->comparisonOperator.' '.$this->rightOperand;
return $this->leftOperand . ' ' . $this->comparisonOperator . ' ' . $this->rightOperand;
}
}
2 changes: 1 addition & 1 deletion src/Expressions/TernaryExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getDateFormat()

public function wrap($value): string
{
return '`'.addcslashes($value, '`').'`';
return '`' . addcslashes($value, '`') . '`';
}

public function mapArgumentTypeToExpressionType($argumentType): string
Expand All @@ -155,7 +155,7 @@ public function formatBind(string $bindVariableName, bool $collection = null)
$prefix = '@@';
}

return $prefix.$bindVariableName;
return $prefix . $bindVariableName;
}

public function getAllowedExpressionTypes()
Expand Down
6 changes: 3 additions & 3 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/NormalizesExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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)
. '.');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/ValidatesExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/QueryClausesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -51,22 +51,22 @@ 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()
{
$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()
Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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')
Expand All @@ -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);
}
}
Loading

0 comments on commit 8fe3eb0

Please sign in to comment.