Skip to content

Commit

Permalink
Merge pull request #2 from SiavashBamshadnia/analysis-6VQ3b9
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
SiavashBamshadnia authored Jan 30, 2024
2 parents 007ae6b + 668bb5b commit c97cc39
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 110 deletions.
150 changes: 75 additions & 75 deletions src/QE.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
* @method static Numeric\Tan tan($parameter) Returns the tangent of a number.
* @method static String\Concat concat(...$parameters) Adds two or more expressions together.
* @method static String\ConcatWS concatWS($separator, ...$parameters) Adds two or more expressions together with a separator.
* @method static String\contains contains($haystack, $needle) Determines if a given string contains a given substring.
* @method static String\EndsWith endsWith($haystack, $needle) Determines if a given string ends with a given substring.
* @method static String\contains contains($haystack, $needle) Determines if a given string contains a given substring.
* @method static String\EndsWith endsWith($haystack, $needle) Determines if a given string ends with a given substring.
* @method static String\Left left($string, $numberOfChars) Extracts a number of characters from a string (starting from left).
* @method static String\Length length($parameter) Returns the length of a string.
* @method static String\Lower lower($parameter) Converts a string to lower-case
Expand All @@ -84,102 +84,102 @@
* @method static String\Right right($string, $numberOfChars) Extracts a number of characters from a string (starting from right).
* @method static String\Rtrim rtrim($parameter) Removes trailing spaces from a string.
* @method static String\Space space($parameter) Returns a string consisting of a specified number of spaces.
* @method static String\StartsWith startsWith($haystack, $needle) Determines if a given string starts with a given substring.
* @method static String\StartsWith startsWith($haystack, $needle) Determines if a given string starts with a given substring.
* @method static String\Substr substr($string, $start, $length = null) Extracts a substring from a string starting at a specified position with optional length.
* @method static String\Trim trim($parameter) Removes leading and trailing spaces from a string.
* @method static String\Upper upper($parameter) Converts a string to upper-case.
*/
class QE
{
const DATABASE_FUNCTIONS = [
'c' => 'sbamtr\LaravelQueryEnrich\Column',
'c' => 'sbamtr\LaravelQueryEnrich\Column',
'raw' => 'sbamtr\LaravelQueryEnrich\Raw',

'case' => 'sbamtr\LaravelQueryEnrich\Advanced\CaseExpression\CaseWhenChain',
'if' => 'sbamtr\LaravelQueryEnrich\Advanced\_If',
'case' => 'sbamtr\LaravelQueryEnrich\Advanced\CaseExpression\CaseWhenChain',
'if' => 'sbamtr\LaravelQueryEnrich\Advanced\_If',
'coalesce' => 'sbamtr\LaravelQueryEnrich\Advanced\Coalesce',
'isNull' => 'sbamtr\LaravelQueryEnrich\Advanced\IsNull',
'exists' => 'sbamtr\LaravelQueryEnrich\Advanced\Exists',
'isNull' => 'sbamtr\LaravelQueryEnrich\Advanced\IsNull',
'exists' => 'sbamtr\LaravelQueryEnrich\Advanced\Exists',

'and' => 'sbamtr\LaravelQueryEnrich\Operator\_And',
'or' => 'sbamtr\LaravelQueryEnrich\Operator\_Or',
'or' => 'sbamtr\LaravelQueryEnrich\Operator\_Or',
'not' => 'sbamtr\LaravelQueryEnrich\Operator\Not',

'condition' => 'sbamtr\LaravelQueryEnrich\Condition\Condition',

'addDate' => 'sbamtr\LaravelQueryEnrich\Date\AddDate',
'addDate' => 'sbamtr\LaravelQueryEnrich\Date\AddDate',
'currentDate' => 'sbamtr\LaravelQueryEnrich\Date\CurrentDate',
'currentTime' => 'sbamtr\LaravelQueryEnrich\Date\CurrentTime',
'date' => 'sbamtr\LaravelQueryEnrich\Date\Date',
'dateDiff' => 'sbamtr\LaravelQueryEnrich\Date\DateDiff',
'dayOfWeek' => 'sbamtr\LaravelQueryEnrich\Date\DayOfWeek',
'hour' => 'sbamtr\LaravelQueryEnrich\Date\Hour',
'minute' => 'sbamtr\LaravelQueryEnrich\Date\Minute',
'month' => 'sbamtr\LaravelQueryEnrich\Date\Month',
'monthName' => 'sbamtr\LaravelQueryEnrich\Date\MonthName',
'now' => 'sbamtr\LaravelQueryEnrich\Date\Now',
'second' => 'sbamtr\LaravelQueryEnrich\Date\Second',
'subDate' => 'sbamtr\LaravelQueryEnrich\Date\SubDate',
'time' => 'sbamtr\LaravelQueryEnrich\Date\Time',
'year' => 'sbamtr\LaravelQueryEnrich\Date\Year',
'date' => 'sbamtr\LaravelQueryEnrich\Date\Date',
'dateDiff' => 'sbamtr\LaravelQueryEnrich\Date\DateDiff',
'dayOfWeek' => 'sbamtr\LaravelQueryEnrich\Date\DayOfWeek',
'hour' => 'sbamtr\LaravelQueryEnrich\Date\Hour',
'minute' => 'sbamtr\LaravelQueryEnrich\Date\Minute',
'month' => 'sbamtr\LaravelQueryEnrich\Date\Month',
'monthName' => 'sbamtr\LaravelQueryEnrich\Date\MonthName',
'now' => 'sbamtr\LaravelQueryEnrich\Date\Now',
'second' => 'sbamtr\LaravelQueryEnrich\Date\Second',
'subDate' => 'sbamtr\LaravelQueryEnrich\Date\SubDate',
'time' => 'sbamtr\LaravelQueryEnrich\Date\Time',
'year' => 'sbamtr\LaravelQueryEnrich\Date\Year',

'abs' => 'sbamtr\LaravelQueryEnrich\Numeric\Abs',
'acos' => 'sbamtr\LaravelQueryEnrich\Numeric\Acos',
'add' => 'sbamtr\LaravelQueryEnrich\Numeric\Add',
'asin' => 'sbamtr\LaravelQueryEnrich\Numeric\Asin',
'atan' => 'sbamtr\LaravelQueryEnrich\Numeric\Atan',
'atan2' => 'sbamtr\LaravelQueryEnrich\Numeric\Atan2',
'avg' => 'sbamtr\LaravelQueryEnrich\Numeric\Avg',
'ceil' => 'sbamtr\LaravelQueryEnrich\Numeric\Ceil',
'cos' => 'sbamtr\LaravelQueryEnrich\Numeric\Cos',
'cot' => 'sbamtr\LaravelQueryEnrich\Numeric\Cot',
'count' => 'sbamtr\LaravelQueryEnrich\Numeric\Count',
'abs' => 'sbamtr\LaravelQueryEnrich\Numeric\Abs',
'acos' => 'sbamtr\LaravelQueryEnrich\Numeric\Acos',
'add' => 'sbamtr\LaravelQueryEnrich\Numeric\Add',
'asin' => 'sbamtr\LaravelQueryEnrich\Numeric\Asin',
'atan' => 'sbamtr\LaravelQueryEnrich\Numeric\Atan',
'atan2' => 'sbamtr\LaravelQueryEnrich\Numeric\Atan2',
'avg' => 'sbamtr\LaravelQueryEnrich\Numeric\Avg',
'ceil' => 'sbamtr\LaravelQueryEnrich\Numeric\Ceil',
'cos' => 'sbamtr\LaravelQueryEnrich\Numeric\Cos',
'cot' => 'sbamtr\LaravelQueryEnrich\Numeric\Cot',
'count' => 'sbamtr\LaravelQueryEnrich\Numeric\Count',
'radianToDegrees' => 'sbamtr\LaravelQueryEnrich\Numeric\RadianToDegrees',
'divide' => 'sbamtr\LaravelQueryEnrich\Numeric\Divide',
'exp' => 'sbamtr\LaravelQueryEnrich\Numeric\Exp',
'floor' => 'sbamtr\LaravelQueryEnrich\Numeric\Floor',
'greatest' => 'sbamtr\LaravelQueryEnrich\Numeric\Greatest',
'least' => 'sbamtr\LaravelQueryEnrich\Numeric\Least',
'ln' => 'sbamtr\LaravelQueryEnrich\Numeric\Ln',
'log' => 'sbamtr\LaravelQueryEnrich\Numeric\Log',
'max' => 'sbamtr\LaravelQueryEnrich\Numeric\Max',
'min' => 'sbamtr\LaravelQueryEnrich\Numeric\Min',
'mod' => 'sbamtr\LaravelQueryEnrich\Numeric\Mod',
'multiply' => 'sbamtr\LaravelQueryEnrich\Numeric\Multiply',
'pi' => 'sbamtr\LaravelQueryEnrich\Numeric\PI',
'pow' => 'sbamtr\LaravelQueryEnrich\Numeric\Pow',
'divide' => 'sbamtr\LaravelQueryEnrich\Numeric\Divide',
'exp' => 'sbamtr\LaravelQueryEnrich\Numeric\Exp',
'floor' => 'sbamtr\LaravelQueryEnrich\Numeric\Floor',
'greatest' => 'sbamtr\LaravelQueryEnrich\Numeric\Greatest',
'least' => 'sbamtr\LaravelQueryEnrich\Numeric\Least',
'ln' => 'sbamtr\LaravelQueryEnrich\Numeric\Ln',
'log' => 'sbamtr\LaravelQueryEnrich\Numeric\Log',
'max' => 'sbamtr\LaravelQueryEnrich\Numeric\Max',
'min' => 'sbamtr\LaravelQueryEnrich\Numeric\Min',
'mod' => 'sbamtr\LaravelQueryEnrich\Numeric\Mod',
'multiply' => 'sbamtr\LaravelQueryEnrich\Numeric\Multiply',
'pi' => 'sbamtr\LaravelQueryEnrich\Numeric\PI',
'pow' => 'sbamtr\LaravelQueryEnrich\Numeric\Pow',
'degreesToRadian' => 'sbamtr\LaravelQueryEnrich\Numeric\DegreesToRadian',
'rand' => 'sbamtr\LaravelQueryEnrich\Numeric\Rand',
'round' => 'sbamtr\LaravelQueryEnrich\Numeric\Round',
'sign' => 'sbamtr\LaravelQueryEnrich\Numeric\Sign',
'sin' => 'sbamtr\LaravelQueryEnrich\Numeric\Sin',
'sqrt' => 'sbamtr\LaravelQueryEnrich\Numeric\Sqrt',
'subtract' => 'sbamtr\LaravelQueryEnrich\Numeric\Subtract',
'sum' => 'sbamtr\LaravelQueryEnrich\Numeric\Sum',
'tan' => 'sbamtr\LaravelQueryEnrich\Numeric\Tan',
'rand' => 'sbamtr\LaravelQueryEnrich\Numeric\Rand',
'round' => 'sbamtr\LaravelQueryEnrich\Numeric\Round',
'sign' => 'sbamtr\LaravelQueryEnrich\Numeric\Sign',
'sin' => 'sbamtr\LaravelQueryEnrich\Numeric\Sin',
'sqrt' => 'sbamtr\LaravelQueryEnrich\Numeric\Sqrt',
'subtract' => 'sbamtr\LaravelQueryEnrich\Numeric\Subtract',
'sum' => 'sbamtr\LaravelQueryEnrich\Numeric\Sum',
'tan' => 'sbamtr\LaravelQueryEnrich\Numeric\Tan',

'concat' => 'sbamtr\LaravelQueryEnrich\String\Concat',
'concatWS' => 'sbamtr\LaravelQueryEnrich\String\ConcatWS',
'contains' => 'sbamtr\LaravelQueryEnrich\String\Contains',
'endsWith' => 'sbamtr\LaravelQueryEnrich\String\EndsWith',
'left' => 'sbamtr\LaravelQueryEnrich\String\Left',
'length' => 'sbamtr\LaravelQueryEnrich\String\Length',
'lower' => 'sbamtr\LaravelQueryEnrich\String\Lower',
'ltrim' => 'sbamtr\LaravelQueryEnrich\String\Ltrim',
'md5' => 'sbamtr\LaravelQueryEnrich\String\MD5',
'padLeft' => 'sbamtr\LaravelQueryEnrich\String\PadLeft',
'padRight' => 'sbamtr\LaravelQueryEnrich\String\PadRight',
'position' => 'sbamtr\LaravelQueryEnrich\String\Position',
'repeat' => 'sbamtr\LaravelQueryEnrich\String\Repeat',
'replace' => 'sbamtr\LaravelQueryEnrich\String\Replace',
'reverse' => 'sbamtr\LaravelQueryEnrich\String\Reverse',
'right' => 'sbamtr\LaravelQueryEnrich\String\Right',
'rtrim' => 'sbamtr\LaravelQueryEnrich\String\Rtrim',
'space' => 'sbamtr\LaravelQueryEnrich\String\Space',
'concat' => 'sbamtr\LaravelQueryEnrich\String\Concat',
'concatWS' => 'sbamtr\LaravelQueryEnrich\String\ConcatWS',
'contains' => 'sbamtr\LaravelQueryEnrich\String\Contains',
'endsWith' => 'sbamtr\LaravelQueryEnrich\String\EndsWith',
'left' => 'sbamtr\LaravelQueryEnrich\String\Left',
'length' => 'sbamtr\LaravelQueryEnrich\String\Length',
'lower' => 'sbamtr\LaravelQueryEnrich\String\Lower',
'ltrim' => 'sbamtr\LaravelQueryEnrich\String\Ltrim',
'md5' => 'sbamtr\LaravelQueryEnrich\String\MD5',
'padLeft' => 'sbamtr\LaravelQueryEnrich\String\PadLeft',
'padRight' => 'sbamtr\LaravelQueryEnrich\String\PadRight',
'position' => 'sbamtr\LaravelQueryEnrich\String\Position',
'repeat' => 'sbamtr\LaravelQueryEnrich\String\Repeat',
'replace' => 'sbamtr\LaravelQueryEnrich\String\Replace',
'reverse' => 'sbamtr\LaravelQueryEnrich\String\Reverse',
'right' => 'sbamtr\LaravelQueryEnrich\String\Right',
'rtrim' => 'sbamtr\LaravelQueryEnrich\String\Rtrim',
'space' => 'sbamtr\LaravelQueryEnrich\String\Space',
'startsWith' => 'sbamtr\LaravelQueryEnrich\String\StartsWith',
'substr' => 'sbamtr\LaravelQueryEnrich\String\Substr',
'trim' => 'sbamtr\LaravelQueryEnrich\String\Trim',
'upper' => 'sbamtr\LaravelQueryEnrich\String\Upper',
'substr' => 'sbamtr\LaravelQueryEnrich\String\Substr',
'trim' => 'sbamtr\LaravelQueryEnrich\String\Trim',
'upper' => 'sbamtr\LaravelQueryEnrich\String\Upper',
];

public static function __callStatic(string $name, array $arguments)
Expand Down
3 changes: 2 additions & 1 deletion src/String/Contains.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function getQuery(): string
{
$haystack = $this->escape($this->haystack);
$needle = QE::concat(QE::raw(DB::escape('%')), $this->needle, QE::raw(DB::escape('%')));

return "$haystack like $needle";
}
}
}
3 changes: 2 additions & 1 deletion src/String/EndsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function getQuery(): string
{
$haystack = $this->escape($this->haystack);
$needle = QE::concat(QE::raw(DB::escape('%')), $this->needle);

return "$haystack like $needle";
}
}
}
2 changes: 1 addition & 1 deletion src/String/MD5.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public function configureForSqlite(): void
{
DB::connection()->getPdo()->sqliteCreateFunction('md5', 'md5', 1);
}
}
}
3 changes: 2 additions & 1 deletion src/String/StartsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function getQuery(): string
{
$haystack = $this->escape($this->haystack);
$needle = QE::concat($this->needle, QE::raw(DB::escape('%')));

return "$haystack like $needle";
}
}
}
28 changes: 16 additions & 12 deletions workbench/BaseTest/BaseProjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use sbamtr\LaravelQueryEnrich\QE;
use Workbench\App\Models\Author;
use Workbench\App\Models\Book;

use function sbamtr\LaravelQueryEnrich\c;

abstract class BaseProjectionTest extends BaseTest
Expand Down Expand Up @@ -1498,7 +1499,7 @@ public function testMd5()
{
$string = $this->faker->name;

$queryResult = DB::selectOne('select ' . QE::md5($string)->as('result'));
$queryResult = DB::selectOne('select '.QE::md5($string)->as('result'));

$expected = md5($string);

Expand All @@ -1509,9 +1510,10 @@ public function testStartsWith()
{
$string = 'Laravel Query Enrich';

$queryResult = DB::selectOne('select ' .
QE::startsWith($string, 'Laravel')->as('result_1') . ',' .
QE::startsWith($string, 'Laravel Query')->as('result_2') . ',' .
$queryResult = DB::selectOne(
'select '.
QE::startsWith($string, 'Laravel')->as('result_1').','.
QE::startsWith($string, 'Laravel Query')->as('result_2').','.
QE::startsWith($string, 'Query')->as('result_3')
);

Expand All @@ -1524,9 +1526,10 @@ public function testEndsWith()
{
$string = 'Laravel Query Enrich';

$queryResult = DB::selectOne('select ' .
QE::endsWith($string, 'Enrich')->as('result_1') . ',' .
QE::endsWith($string, 'Query Enrich')->as('result_2') . ',' .
$queryResult = DB::selectOne(
'select '.
QE::endsWith($string, 'Enrich')->as('result_1').','.
QE::endsWith($string, 'Query Enrich')->as('result_2').','.
QE::endsWith($string, 'Query')->as('result_3')
);

Expand All @@ -1539,11 +1542,12 @@ public function testContains()
{
$string = 'Laravel Query Enrich';

$queryResult = DB::selectOne('select ' .
QE::contains($string, 'Laravel Query Enrich')->as('result_1') . ',' .
QE::contains($string, 'Query Enrich')->as('result_2') . ',' .
QE::contains($string, 'Laravel Query')->as('result_3') . ',' .
QE::contains($string, 'Query')->as('result_4') . ',' .
$queryResult = DB::selectOne(
'select '.
QE::contains($string, 'Laravel Query Enrich')->as('result_1').','.
QE::contains($string, 'Query Enrich')->as('result_2').','.
QE::contains($string, 'Laravel Query')->as('result_3').','.
QE::contains($string, 'Query')->as('result_4').','.
QE::contains($string, 'Lumen')->as('result_5')
);

Expand Down
38 changes: 19 additions & 19 deletions workbench/BaseTest/BaseWhereClauseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use sbamtr\LaravelQueryEnrich\QE;
use Workbench\App\Models\Author;
use Workbench\App\Models\Book;

use function sbamtr\LaravelQueryEnrich\c;

abstract class BaseWhereClauseTest extends BaseTest
Expand Down Expand Up @@ -261,18 +262,18 @@ public function testStartsWith()
Author::insert([
[
'first_name' => 'Walter',
'last_name' => 'White',
'email' => '[email protected]',
'last_name' => 'White',
'email' => '[email protected]',
],
[
'first_name' => 'Walt',
'last_name' => 'White',
'email' => '[email protected]',
'last_name' => 'White',
'email' => '[email protected]',
],
[
'first_name' => 'Skyler',
'last_name' => 'White',
'email' => '[email protected]',
'last_name' => 'White',
'email' => '[email protected]',
],
]);

Expand All @@ -285,24 +286,23 @@ public function testStartsWith()
self::assertEquals('Walt', $queryResult[1]->first_name);
}


public function testEndsWith()
{
Author::insert([
[
'first_name' => 'Sandor',
'last_name' => 'Clegane',
'email' => '[email protected]',
'last_name' => 'Clegane',
'email' => '[email protected]',
],
[
'first_name' => 'Gregor',
'last_name' => 'Clegane',
'email' => '[email protected]',
'last_name' => 'Clegane',
'email' => '[email protected]',
],
[
'first_name' => 'Gared',
'last_name' => 'Clegane',
'email' => '[email protected]',
'last_name' => 'Clegane',
'email' => '[email protected]',
],
]);

Expand All @@ -320,18 +320,18 @@ public function testContains()
Author::insert([
[
'first_name' => 'Sandor',
'last_name' => 'Clegane',
'email' => '[email protected]',
'last_name' => 'Clegane',
'email' => '[email protected]',
],
[
'first_name' => 'Gregor',
'last_name' => 'Clegane',
'email' => '[email protected]',
'last_name' => 'Clegane',
'email' => '[email protected]',
],
[
'first_name' => 'Gared',
'last_name' => 'Clegane',
'email' => '[email protected]',
'last_name' => 'Clegane',
'email' => '[email protected]',
],
]);

Expand Down

0 comments on commit c97cc39

Please sign in to comment.