From 3699ea09fa001496e62560ba513a5db9fe1df865 Mon Sep 17 00:00:00 2001 From: Moath Alhajri Date: Fri, 9 Sep 2022 18:40:11 +0300 Subject: [PATCH 1/2] Create dependabot.yml --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e9d271d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "composer" + directory: "/" + schedule: + interval: "weekly" From 4da985ea90160c8e1d5bf0f1d46cd4a7b37ccceb Mon Sep 17 00:00:00 2001 From: devmoath Date: Sat, 10 Sep 2022 01:25:13 +0300 Subject: [PATCH 2/2] :sparkles: internal improvements and php 8.2 support --- .github/workflows/codecov.yml | 20 ++--------- .github/workflows/php-cs-fixer.yml | 20 +++-------- .github/workflows/phpstan.yml | 22 +++--------- .github/workflows/tests.yml | 22 +++--------- composer.json | 6 ++-- phpstan.neon | 7 +++- phpunit.xml | 1 + src/Jql.php | 55 ++++++++++++++++++------------ src/helpers.php | 38 --------------------- 9 files changed, 59 insertions(+), 132 deletions(-) delete mode 100644 src/helpers.php diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index d9c2e1c..2b7b06e 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -2,37 +2,23 @@ name: codecov on: push: - paths: - - '**.php' - - '.github/workflows/codecov.yml' - - 'composer.lock' - - 'composer.json' pull_request: - paths: - - '**.php' - - '.github/workflows/codecov.yml' - - 'composer.lock' - - 'composer.json' jobs: codecov: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: 8.1 + extensions: dom, libxml, mbstring + ini-values: error_reporting=E_ALL coverage: xdebug - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: vendor - key: composer-${{ hashFiles('composer.lock') }} - - name: Install dependencies run: composer install --prefer-dist --no-interaction diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml index 733ffa5..d763bed 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/php-cs-fixer.yml @@ -2,37 +2,25 @@ name: php-cs-fixer on: push: - paths: - - '**.php' - - '.github/workflows/php-cs-fixer.yml' - - 'composer.lock' pull_request: - paths: - - '**.php' - - '.github/workflows/php-cs-fixer.yml' - - 'composer.lock' jobs: php-cs-fixer: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup php uses: shivammathur/setup-php@v2 with: php-version: 8.0 + extensions: dom, libxml, mbstring + ini-values: error_reporting=E_ALL coverage: none - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: vendor - key: composer-${{ hashFiles('composer.lock') }} - - name: Install dependencies run: composer install --prefer-dist --no-interaction - name: Run php-cs-fixer - run: vendor/bin/php-cs-fixer fix --dry-run + run: composer php-cs-fixer diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 4dcb394..cf0af8a 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -2,42 +2,30 @@ name: phpstan on: push: - paths: - - '**.php' - - '.github/workflows/phpstan.yml' - - 'composer.lock' pull_request: - paths: - - '**.php' - - '.github/workflows/phpstan.yml' - - 'composer.lock' jobs: phpstan: runs-on: ubuntu-latest strategy: matrix: - php: [ 8.0, 8.1 ] + php: [ 8.0, 8.1, 8.2 ] name: php@${{ matrix.php }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} + extensions: dom, libxml, mbstring + ini-values: error_reporting=E_ALL coverage: none - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: vendor - key: composer-${{ hashFiles('composer.lock') }} - - name: Install dependencies run: composer install --prefer-dist --no-interaction - name: Run phpstan - run: vendor/bin/phpstan --error-format=github + run: composer phpstan:github diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6ace1c3..0bcf7d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,42 +1,30 @@ -name: tests +name: Tests on: push: - paths: - - '**.php' - - '.github/workflows/tests.yml' - - 'composer.lock' pull_request: - paths: - - '**.php' - - '.github/workflows/tests.yml' - - 'composer.lock' jobs: phpunit: runs-on: ubuntu-latest strategy: + fail-fast: true matrix: - php: [ 8.0, 8.1 ] + php: [ 8.0, 8.1, 8.2 ] name: php@${{ matrix.php }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup php uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: dom, libxml, mbstring + ini-values: error_reporting=E_ALL coverage: none - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: vendor - key: composer-${{ hashFiles('composer.lock') }} - - name: Install dependencies run: composer install --prefer-dist --no-interaction diff --git a/composer.json b/composer.json index 248ecca..981dcad 100644 --- a/composer.json +++ b/composer.json @@ -45,10 +45,7 @@ "autoload-dev": { "psr-4": { "JqlBuilder\\Tests\\": "tests" - }, - "files": [ - "src/helpers.php" - ] + } }, "extra": { "laravel": { @@ -67,6 +64,7 @@ "php-cs-fixer": "php-cs-fixer fix --dry-run", "php-cs-fixer:fix": "php-cs-fixer fix", "phpstan": "phpstan analyse", + "phpstan:github": "phpstan analyse --error-format=github", "test": "phpunit" } } diff --git a/phpstan.neon b/phpstan.neon index cbc8b6f..ee0c038 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,12 @@ parameters: - level: 8 + level: max paths: - src ignoreErrors: + - '#Parameter \#2 \$operator of method JqlBuilder\\Jql::invalidBooleanOrOperator\(\) expects string, mixed given.#' + - '#Parameter \#1 \$operator of method JqlBuilder\\Jql::quote\(\) expects string, mixed given.#' + - '#Part \$operator \(mixed\) of encapsed string cannot be cast to string.#' + - '#Parameter \#3 \$subject of function str_replace expects array\|string, mixed given.#' + - '#Parameter \#2 ...\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given.#' diff --git a/phpunit.xml b/phpunit.xml index 795389c..2c3d23c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,6 +6,7 @@ convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" + convertDeprecationsToExceptions="true" processIsolation="false" stopOnFailure="false" verbose="true" diff --git a/src/Jql.php b/src/Jql.php index c241e53..a734ec4 100644 --- a/src/Jql.php +++ b/src/Jql.php @@ -22,18 +22,18 @@ public function where( string $boolean = Keyword::AND ): self { if ($column instanceof Closure) { - return tap($this, function () use ($boolean, $column) { - if (empty($this->query)) { - $queryTemplate = "(%s)"; - } else { - $queryTemplate = "$this->query $boolean (%s)"; - $this->query = ''; - } + if (empty($this->query)) { + $queryTemplate = "(%s)"; + } else { + $queryTemplate = "$this->query $boolean (%s)"; + $this->query = ''; + } + + $column($this); - $column($this); + $this->query = sprintf($queryTemplate, $this->query); - $this->query = sprintf($queryTemplate, $this->query); - }); + return $this; } if (count(func_get_args()) === 2) { @@ -42,7 +42,9 @@ public function where( $this->invalidBooleanOrOperator($boolean, $operator, $value); - return tap($this, fn () => $this->appendQuery("$column $operator {$this->quote($operator, $value)}", $boolean)); + $this->appendQuery("$column $operator {$this->quote($operator, $value)}", $boolean); + + return $this; } public function orWhere(string|Closure $column, mixed $operator = Operator::EQUALS, mixed $value = null): self @@ -51,12 +53,14 @@ public function orWhere(string|Closure $column, mixed $operator = Operator::EQUA [$column, $operator, $value] = [$column, is_array($operator) ? Operator::IN : Operator::EQUALS, $operator]; } - return tap($this, fn () => $this->where($column, $operator, $value, Keyword::OR)); + $this->where($column, $operator, $value, Keyword::OR); + + return $this; } public function when(mixed $value, callable $callback): self { - $value = value($value, $this); + $value = $value instanceof Closure ? $value($this) : $value; if ($value) { return $callback($this, $value) ?: $this; @@ -67,7 +71,7 @@ public function when(mixed $value, callable $callback): self public function whenNot(mixed $value, callable $callback): self { - $value = value($value, $this); + $value = $value instanceof Closure ? $value($this) : $value; if (! $value) { return $callback($this, $value) ?: $this; @@ -78,12 +82,16 @@ public function whenNot(mixed $value, callable $callback): self public function orderBy(string $column, string $direction): self { - return tap($this, fn () => $this->appendQuery(Keyword::ORDER_BY." $column $direction")); + $this->appendQuery(Keyword::ORDER_BY." $column $direction"); + + return $this; } public function rawQuery(string $query): self { - return tap($this, fn () => $this->appendQuery($query)); + $this->appendQuery($query); + + return $this; } public function getQuery(): string @@ -99,13 +107,16 @@ public function __toString(): string private function quote(string $operator, mixed $value): string { if (in_array($operator, [Operator::IN, Operator::NOT_IN, Operator::WAS_IN, Operator::WAS_NOT_IN])) { - $values = array_reduce(array_wrap($value), function ($prev, $current) { - if ($prev === null) { - return '"'.str_replace('"', '\\"', $current).'"'; + $values = array_reduce( + is_array($value) ? $value : [$value], + function ($prev, $current) { + if ($prev === null) { + return '"'.str_replace('"', '\\"', $current).'"'; + } + + return $prev.', "'.str_replace('"', '\\"', $current).'"'; } - - return $prev.', "'.str_replace('"', '\\"', $current).'"'; - }); + ); return "($values)"; } diff --git a/src/helpers.php b/src/helpers.php deleted file mode 100644 index dd664b4..0000000 --- a/src/helpers.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ - function array_wrap(mixed $value): array - { - return is_array($value) ? $value : [$value]; - } -} - -if (! function_exists('value')) { - /** - * @param mixed $value - * @param mixed ...$args - * @return mixed - */ - function value(mixed $value, mixed ...$args): mixed - { - return $value instanceof Closure ? $value(...$args) : $value; - } -}