Skip to content

Commit 5de7d9a

Browse files
committed
Prepare pull request to asseco-voice/laravel-json-query-builder
1 parent cce71d8 commit 5de7d9a

File tree

12 files changed

+86
-82
lines changed

12 files changed

+86
-82
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
[*.json]
3+
tab_width = 4

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Asseco SEE
3+
Copyright (c) 2020 Asseco SEE
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
{
2-
"name": "nealarec/laravel-json-query-builder",
3-
"description": "Laravel JSON query builder",
4-
"keywords": [
5-
"php",
6-
"laravel"
7-
],
8-
"scripts": {
9-
"test": "vendor/bin/phpunit"
10-
},
11-
"license": "MIT",
12-
"require": {
13-
"php": "^8.1",
14-
"illuminate/support": "^8.0|^9.0|^10.0|^11.0"
15-
},
16-
"require-dev": {
17-
"phpunit/phpunit": "^10.0",
18-
"mockery/mockery": "^1.4.4",
19-
"fakerphp/faker": "^1.9.1",
20-
"orchestra/testbench": "^8.5"
21-
},
22-
"autoload": {
23-
"psr-4": {
24-
"Asseco\\JsonQueryBuilder\\": "src/"
2+
"name": "asseco-voice/laravel-json-query-builder",
3+
"description": "Laravel JSON query builder",
4+
"keywords": [
5+
"php",
6+
"laravel"
7+
],
8+
"scripts": {
9+
"test": "vendor/bin/phpunit"
10+
},
11+
"license": "MIT",
12+
"require": {
13+
"php": "^8.1",
14+
"illuminate/support": "^8.0|^9.0|^10.0|^11.0"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^10.0",
18+
"mockery/mockery": "^1.4.4",
19+
"fakerphp/faker": "^1.9.1",
20+
"orchestra/testbench": "^8.5"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Asseco\\JsonQueryBuilder\\": "src/"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Asseco\\JsonQueryBuilder\\Tests\\": "tests/"
30+
}
31+
},
32+
"extra": {
33+
"laravel": {
34+
"providers": [
35+
"Asseco\\JsonQueryBuilder\\JsonQueryServiceProvider"
36+
]
37+
}
2538
}
26-
},
27-
"autoload-dev": {
28-
"psr-4": {
29-
"Asseco\\JsonQueryBuilder\\Tests\\": "tests/"
30-
}
31-
},
32-
"extra": {
33-
"laravel": {
34-
"providers": [
35-
"Asseco\\JsonQueryBuilder\\JsonQueryServiceProvider"
36-
]
37-
}
38-
}
3939
}

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/JsonQueryServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare (strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace Asseco\JsonQueryBuilder;
66

src/RequestParameters/ReturnsParameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare (strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace Asseco\JsonQueryBuilder\RequestParameters;
66

src/SQLProviders/SQLFunctions.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
class SQLFunctions
88
{
99
public const DB_FUNCTIONS = [
10-
"avg",
11-
"count",
12-
"max",
13-
"min",
14-
"sum",
15-
"distinct",
16-
17-
"year",
18-
"month",
19-
"day",
10+
'avg',
11+
'count',
12+
'max',
13+
'min',
14+
'sum',
15+
'distinct',
16+
17+
'year',
18+
'month',
19+
'day',
2020
];
2121

2222
final public static function validateArgument(string $argument): void
2323
{
24-
$split = explode(":", $argument);
24+
$split = explode(':', $argument);
2525
$column = array_pop($split);
2626

2727
if (!preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*|\*$/", $column) || in_array($column, self::DB_FUNCTIONS)) {
@@ -32,7 +32,7 @@ final public static function validateArgument(string $argument): void
3232

3333
if ($invalidFns = array_diff($split, self::DB_FUNCTIONS)) {
3434
throw new JsonQueryBuilderException(
35-
"Invalid function: " . join(",", $invalidFns) . "."
35+
'Invalid function: ' . join(',', $invalidFns) . '.'
3636
);
3737
}
3838
}

src/Traits/DatabaseFunctions.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait DatabaseFunctions
1212
public Builder $builder;
1313

1414
protected array $providers = [
15-
"pgsql" => PgSQLFunctions::class,
15+
'pgsql' => PgSQLFunctions::class,
1616
];
1717

1818
protected function areArgumentsValid(): void
@@ -25,28 +25,29 @@ protected function areArgumentsValid(): void
2525

2626
private function applyAggregation(array $params): string
2727
{
28-
$column = array_pop($params);
29-
$provider = $this->builder->getModel()->connection ?? config("database.default");
28+
$column = array_pop($params);
29+
$provider = $this->builder->getModel()->connection ?? config('database.default');
3030
$functions = $this->providers[$provider] ?? SQLFunctions::class;
3131

3232
return array_reduce(array_reverse($params), function ($query, $param) use (
3333
$column,
3434
$functions
3535
) {
36-
$stat = $query ?? ("*" !== $column ? "\"$column\"" : $column);
36+
$stat = $query ?? ('*' !== $column ? "\"$column\"" : $column);
37+
3738
return $functions::$param($stat);
3839
});
3940
}
4041

4142
protected function prepareArguments(): void
4243
{
4344
$this->arguments = array_map(function ($argument) {
44-
if (strpos($argument, ":") === false) {
45+
if (strpos($argument, ':') === false) {
4546
return $argument;
4647
}
47-
$split = explode(":", $argument);
48+
$split = explode(':', $argument);
4849
$apply = $this->applyAggregation($split);
49-
$alias = join("_", array_filter($split, fn($s) => "*" !== $s));
50+
$alias = join('_', array_filter($split, fn ($s) => '*' !== $s));
5051

5152
return DB::raw("{$apply} as {$alias}");
5253
}, $this->arguments);

tests/Unit/RequestParameters/ReturnsParameterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare (strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace Asseco\JsonQueryBuilder\Tests\Unit\RequestParameters;
66

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

3-
declare (strict_types = 1);
3+
declare(strict_types=1);
4+
45
namespace Asseco\JsonQueryBuilder\Tests\Unit\SQLProviders;
56

67
use Asseco\JsonQueryBuilder\SQLProviders\PgSQLFunctions;
78
use Asseco\JsonQueryBuilder\SQLProviders\SQLFunctions;
8-
use \Asseco\JsonQueryBuilder\Tests\TestCase;
9+
use Asseco\JsonQueryBuilder\Tests\TestCase;
910

1011
class PgSQLFunctionsTest extends TestCase
1112
{
12-
1313
public SQLFunctions $functions;
1414

1515
public function setUp(): void
@@ -22,18 +22,18 @@ public function setUp(): void
2222
public function test_it_should_return_the_year_function()
2323
{
2424
$query = $this->functions::year('column');
25-
$this->assertEquals("EXTRACT(YEAR FROM column)", $query);
25+
$this->assertEquals('EXTRACT(YEAR FROM column)', $query);
2626
}
2727

2828
public function test_it_should_return_the_month_function()
2929
{
3030
$query = $this->functions::month('column');
31-
$this->assertEquals("EXTRACT(MONTH FROM column)", $query);
31+
$this->assertEquals('EXTRACT(MONTH FROM column)', $query);
3232
}
3333

3434
public function test_it_should_return_the_day_function()
3535
{
3636
$query = $this->functions::day('column');
37-
$this->assertEquals("EXTRACT(DAY FROM column)", $query);
37+
$this->assertEquals('EXTRACT(DAY FROM column)', $query);
3838
}
3939
}

0 commit comments

Comments
 (0)