From 7e705f2fe040b2a97ef6a1942030877ced8e299e Mon Sep 17 00:00:00 2001 From: Leandro Silva Date: Fri, 7 May 2021 08:07:14 -0300 Subject: [PATCH 1/2] Added release automation --- .github/FUNDING.yml | 1 + .github/ISSUE_TEMPLATE/Bug_Report.md | 35 ++++++++++ .github/ISSUE_TEMPLATE/Feature_Request.md | 31 +++++++++ .github/ISSUE_TEMPLATE/Question.md | 19 ++++++ .../Pull_Request_Template.md | 30 +++++++++ .../workflows/release-on-milestone-closed.yml | 67 +++++++++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/Bug_Report.md create mode 100644 .github/ISSUE_TEMPLATE/Feature_Request.md create mode 100644 .github/ISSUE_TEMPLATE/Question.md create mode 100644 .github/PULL_REQUEST_TEMPLATE/Pull_Request_Template.md create mode 100644 .github/workflows/release-on-milestone-closed.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..0b98694 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: Lansoweb diff --git a/.github/ISSUE_TEMPLATE/Bug_Report.md b/.github/ISSUE_TEMPLATE/Bug_Report.md new file mode 100644 index 0000000..1d003a7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Bug_Report.md @@ -0,0 +1,35 @@ +--- +name: Bug Report +about: Create a bug report to help us improve +labels: bug +assignees: +--- + + +## Description + + +## Steps to reproduce + +1. Step one... +2. Step two... +3. Step three... + +## Expected behavior + + +## Screenshots or output + + +## Environment details + +- version of this package: *e.g. 1.0.0, 1.0.1, 1.1.0* +- PHP version: *e.g. 7.3.16, 7.4.4* +- OS: *e.g. Windows 10, Linux (Ubuntu 18.04.1), macOS Catalina (10.15.3)* + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/Feature_Request.md b/.github/ISSUE_TEMPLATE/Feature_Request.md new file mode 100644 index 0000000..fdde4b2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Feature_Request.md @@ -0,0 +1,31 @@ +--- +name: Feature Request +about: Suggest a feature for this project +labels: enhancement +assignees: +--- + + + +## My feature title + + +## Background/problem + + +## Proposal/solution + + +## Alternatives + + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/Question.md b/.github/ISSUE_TEMPLATE/Question.md new file mode 100644 index 0000000..5c76b2a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Question.md @@ -0,0 +1,19 @@ +--- +name: Question +about: Ask a question about how to use this library +labels: question +assignees: +--- + + + +## How do I... ? + + +## Example code + diff --git a/.github/PULL_REQUEST_TEMPLATE/Pull_Request_Template.md b/.github/PULL_REQUEST_TEMPLATE/Pull_Request_Template.md new file mode 100644 index 0000000..df4646c --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/Pull_Request_Template.md @@ -0,0 +1,30 @@ + + +## Description + + +## Motivation and context + + + +## How has this been tested? + + + + +## Types of changes + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to change) + +## PR checklist + + +- [ ] My code follows the code style of this project. +- [ ] My change requires a change to the documentation. +- [ ] I have updated the documentation accordingly. +- [ ] I have read the **CONTRIBUTING** document. +- [ ] I have added tests to cover my changes. +- [ ] All new and existing tests passed. +- [ ] I have run `composer test` locally, and there were no failures or errors. diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml new file mode 100644 index 0000000..169fd65 --- /dev/null +++ b/.github/workflows/release-on-milestone-closed.yml @@ -0,0 +1,67 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +name: "Automatic Releases" + +on: + milestone: + types: + - "closed" + +jobs: + release: + name: "GIT tag, release & create merge-up PR" + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Release" + uses: "laminas/automatic-releases@v1" + with: + command-name: "laminas:automatic-releases:release" + env: + "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} + "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} + "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} + "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + + - name: "Create Merge-Up Pull Request" + uses: "laminas/automatic-releases@v1" + with: + command-name: "laminas:automatic-releases:create-merge-up-pull-request" + env: + "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} + "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} + "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} + "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + + - name: "Create and/or Switch to new Release Branch" + uses: "laminas/automatic-releases@v1" + with: + command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor" + env: + "GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} + "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} + "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} + "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + + - name: "Bump Changelog Version On Originating Release Branch" + uses: "laminas/automatic-releases@v1" + with: + command-name: "laminas:automatic-releases:bump-changelog" + env: + "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} + "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} + "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} + "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + + - name: "Create new milestones" + uses: "laminas/automatic-releases@v1" + with: + command-name: "laminas:automatic-releases:create-milestones" + env: + "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} + "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} + "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} + "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} From d7ec4cf8020c215210e9620083fcbf44882f15cb Mon Sep 17 00:00:00 2001 From: Leandro Silva Date: Tue, 19 Sep 2023 14:24:55 -0300 Subject: [PATCH 2/2] remove php 7.4 and update dependencies --- .github/workflows/coding-standard.yml | 45 +++++++++ .../workflows/release-on-milestone-closed.yml | 6 +- .gitignore | 3 +- composer.json | 23 +++-- phpcs.xml | 7 -- phpcs.xml.dist | 24 +++++ phpstan.neon.dist | 10 ++ src/BuilderInterface.php | 50 +++++----- src/ElasticSearchBuilder.php | 98 +++++++++++-------- src/Exception/MalformedException.php | 1 + ...ZendDbBuilder.php => LaminasDbBuilder.php} | 96 +++++++++--------- ...ilderTest.php => LaminasDbBuilderTest.php} | 10 +- 12 files changed, 228 insertions(+), 145 deletions(-) create mode 100644 .github/workflows/coding-standard.yml delete mode 100644 phpcs.xml create mode 100644 phpcs.xml.dist create mode 100644 phpstan.neon.dist rename src/{ZendDbBuilder.php => LaminasDbBuilder.php} (72%) rename test/{ZendDbBuilderTest.php => LaminasDbBuilderTest.php} (97%) diff --git a/.github/workflows/coding-standard.yml b/.github/workflows/coding-standard.yml new file mode 100644 index 0000000..4d504e2 --- /dev/null +++ b/.github/workflows/coding-standard.yml @@ -0,0 +1,45 @@ +name: "Check Coding Standards" + +on: + pull_request: + push: + branches: + - "master" + +jobs: + coding-standards: + name: "Check Coding Standards" + + runs-on: ${{ matrix.operating-system }} + + strategy: + matrix: + dependencies: + - "highest" + php-version: + - "8.2" + operating-system: + - "ubuntu-latest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v3" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: memory_limit=-1 + tools: composer:v2 + + - uses: "ramsey/composer-install@v1" + with: + dependency-versions: "${{ matrix.dependencies }}" + composer-options: "${{ matrix.composer-options }}" + + - name: "phpcs" + run: "vendor/bin/phpcs" + + - name: "phpstan" + run: "vendor/bin/phpstan analyze" diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml index 169fd65..c7613e4 100644 --- a/.github/workflows/release-on-milestone-closed.yml +++ b/.github/workflows/release-on-milestone-closed.yml @@ -1,5 +1,3 @@ -# https://help.github.com/en/categories/automating-your-workflow-with-github-actions - name: "Automatic Releases" on: @@ -14,14 +12,14 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v3" - name: "Release" uses: "laminas/automatic-releases@v1" with: command-name: "laminas:automatic-releases:release" env: - "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} + "GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} diff --git a/.gitignore b/.gitignore index 69e0fc9..a2fe4a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vendor composer.lock clover.xml -build +/build +/.phpunit.result.cache diff --git a/composer.json b/composer.json index a11ec66..71845dc 100644 --- a/composer.json +++ b/composer.json @@ -11,17 +11,17 @@ } ], "require": { - "php": "^7.1", - "psr/http-message": "^1.0" + "php": "^8.1", + "psr/http-message": "^1.0 || ^2.0" }, "require-dev": { "laminas/laminas-db": "^2.9", - "laminas/laminas-coding-standard": "^1.0", - "squizlabs/php_codesniffer": "^2.7", - "phpstan/phpstan": "^0.9.2", - "phpunit/phpunit": "^7.1", - "laminas/laminas-diactoros": "^1.7", - "php-coveralls/php-coveralls": "^2.0" + "squizlabs/php_codesniffer": "^3.7", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.3", + "laminas/laminas-diactoros": "^3.2", + "php-coveralls/php-coveralls": "^2.6", + "doctrine/coding-standard": "^12.0" }, "autoload": { "psr-4": { @@ -41,9 +41,14 @@ ], "cs-check": "phpcs", "cs-fix": "phpcbf", - "phpstan": "phpstan analyse -l max src", + "phpstan": "phpstan analyse", "test": "phpunit --colors=always", "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", "upload-coverage": "coveralls -v" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 2c12b89..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - src - diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..5c84d78 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,24 @@ + + + + Project coding standards + + + + + + ./src + + + + + + + + + + + + diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..198b9b0 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,10 @@ +parameters: + level: max + tmpDir: ./build/cache/phpstan + checkMissingIterableValueType: false + paths: + - ./src + ignoreErrors: + - '#no type specified#' + - '#mixed#' + - '#on a separate line does not do anything#' diff --git a/src/BuilderInterface.php b/src/BuilderInterface.php index 2f23d39..fcbe377 100644 --- a/src/BuilderInterface.php +++ b/src/BuilderInterface.php @@ -1,4 +1,5 @@ queryName = $queryName; - $this->hintName = $hintName; } - public function fromRequest(ServerRequestInterface $request) : array + public function fromRequest(ServerRequestInterface $request): array { $queryParams = $request->getQueryParams(); - $query = json_decode($queryParams['q'] ?? '{}', true); - $hint = json_decode($queryParams['h'] ?? '{}', true); + $query = json_decode($queryParams['q'] ?? '{}', true); + $hint = json_decode($queryParams['h'] ?? '{}', true); if (! is_array($query) || ! is_array($hint)) { throw new Exception\MalformedException('Invalid query or hint'); @@ -30,7 +35,7 @@ public function fromRequest(ServerRequestInterface $request) : array return $this->fromParams($query, $hint); } - public function fromParams(array $query, array $hint = []) : array + public function fromParams(array $query, array $hint = []): array { foreach ($query as $key => $value) { $this->params = array_merge($this->params, $this->parseQuery($key, $value)); @@ -41,54 +46,59 @@ public function fromParams(array $query, array $hint = []) : array $hintParams = array_merge($hintParams, $this->parseHint($key, $value)); } - $result = [ 'body' => [ 'query' => ['constant_score' => [ 'filter' => [ 'bool' => $this->params ] ] ] ] ]; + $result = ['body' => ['query' => ['constant_score' => ['filter' => ['bool' => $this->params]]]]]; - if (!empty($hintParams)) { + if (! empty($hintParams)) { $result = array_merge($result, $hintParams); } return $result; } - private function parseQuery(string $key, $value, bool $withoutOperator = false) : array + private function parseQuery(string $key, $value, bool $withoutOperator = false): array { if ($key === BuilderInterface::OP_NULL) { - $params = [ 'exists' => [ 'field' => $value ] ]; - return $withoutOperator ? $params : [ 'must_not' => $params ]; + $params = ['exists' => ['field' => $value]]; + + return $withoutOperator ? $params : ['must_not' => $params]; } if ($key === BuilderInterface::OP_NOT_NULL) { - $params = [ 'field' => $value ]; - return $withoutOperator ? $params : [ 'exists' => $params ]; + $params = ['field' => $value]; + + return $withoutOperator ? $params : ['exists' => $params]; } if (! is_array($value)) { - $params = [ 'term' => [ $key => $value ] ]; - return $withoutOperator ? $params : [ 'must' => $params ]; + $params = ['term' => [$key => $value]]; + + return $withoutOperator ? $params : ['must' => $params]; } if ($key === BuilderInterface::OP_OR) { $params = []; foreach ($value as $query) { - $value2 = reset($query); - $key2 = key($query); + $value2 = reset($query); + $key2 = key($query); $params[] = $this->parseQuery($key2, $value2, true); } - return $withoutOperator ? $params : [ 'should' => $params ]; + + return $withoutOperator ? $params : ['should' => $params]; } if ($key === BuilderInterface::OP_AND) { $params = []; foreach ($value as $query) { - $value2 = reset($query); - $key2 = key($query); + $value2 = reset($query); + $key2 = key($query); $params[] = $this->parseQuery($key2, $value2, true); } - return $withoutOperator ? $params : [ 'must' => $params ]; + + return $withoutOperator ? $params : ['must' => $params]; } $opValue = reset($value); - $op = key($value); + $op = key($value); if (in_array($op, BuilderInterface::OP_LOGIC)) { return $this->parseLogic($key, $op, $opValue); @@ -101,65 +111,67 @@ private function parseQuery(string $key, $value, bool $withoutOperator = false) return []; } - private function parseLogic(string $key, $op, $value) : array + private function parseLogic(string $key, $op, $value): array { if ($op === BuilderInterface::OP_NOT) { - return [ 'must_not' => [ 'term' => [ $key => $value ] ] ]; + return ['must_not' => ['term' => [$key => $value]]]; } if ($op === BuilderInterface::OP_IN) { - return [ 'filter' => [ 'terms' => [ $key => $value ] ] ]; + return ['filter' => ['terms' => [$key => $value]]]; } if ($op === BuilderInterface::OP_NOT_IN) { - return [ 'must_not' => [ 'terms' => [ $key => $value ] ] ]; + return ['must_not' => ['terms' => [$key => $value]]]; } // At this point, should only be BuilderInterface::OP_LIKE . No if to keep PHPUnit happy - return [ 'wildcard' => [ $key => str_replace('%', '*', $value) ] ]; + return ['wildcard' => [$key => str_replace('%', '*', $value)]]; } - private function parseConditional(string $key, $op, $value) : array + private function parseConditional(string $key, $op, $value): array { if ($op === BuilderInterface::OP_GREATER) { - return [ 'filter' => [ 'range' => [ $key => [ 'gt' => $value ] ] ] ]; + return ['filter' => ['range' => [$key => ['gt' => $value]]]]; } if ($op === BuilderInterface::OP_GREATER_EQUAL) { - return [ 'filter' => [ 'range' => [ $key => [ 'gte' => $value ] ] ] ]; + return ['filter' => ['range' => [$key => ['gte' => $value]]]]; } if ($op === BuilderInterface::OP_LESS) { - return [ 'filter' => [ 'range' => [ $key => [ 'lt' => $value ] ] ] ]; + return ['filter' => ['range' => [$key => ['lt' => $value]]]]; } if ($op === BuilderInterface::OP_LESS_EQUAL) { - return [ 'filter' => [ 'range' => [ $key => [ 'lte' => $value ] ] ] ]; + return ['filter' => ['range' => [$key => ['lte' => $value]]]]; } // At this point, should only be BuilderInterface::OP_BETWEEN . No if to keep PHPUnit happy - return [ 'filter' => [ 'range' => [ $key => [ 'gt' => $value[0], 'lt' => $value[1] ] ] ] ]; + return ['filter' => ['range' => [$key => ['gt' => $value[0], 'lt' => $value[1]]]]]; } - private function parseHint($key, $value) : array + private function parseHint($key, $value): array { if ($key === BuilderInterface::HINT_SORT) { if (! is_array($value)) { - return [ 'sort' => [ $value ] ]; + return ['sort' => [$value]]; } + $params = []; foreach ($value as $field => $order) { - $order = in_array($order, BuilderInterface::HINT_ORDER_ASC) ? 'asc' : 'desc'; - $params[] = [ $field => [ 'order' => $order ] ]; + $order = in_array($order, BuilderInterface::HINT_ORDER_ASC) ? 'asc' : 'desc'; + $params[] = [$field => ['order' => $order]]; } - return [ 'sort' => $params ]; + + return ['sort' => $params]; } if ($key === BuilderInterface::HINT_LIMIT) { - return [ 'size' => $value ]; + return ['size' => $value]; } // At this point, should only be BuilderInterface::HINT_SKIP . No if to keep PHPUnit happy - return [ 'from' => $value ]; + return ['from' => $value]; } } diff --git a/src/Exception/MalformedException.php b/src/Exception/MalformedException.php index e594d76..d1ccc6f 100644 --- a/src/Exception/MalformedException.php +++ b/src/Exception/MalformedException.php @@ -1,4 +1,5 @@ queryName = $queryName; - $this->hintName = $hintName; $this->select = clone $select; } - /** - * @param ServerRequestInterface $request - * @return Select - */ - public function fromRequest(ServerRequestInterface $request) : Select + public function fromRequest(ServerRequestInterface $request): Select { $queryParams = $request->getQueryParams(); - $query = json_decode($queryParams['q'] ?? '{}', true); - $hint = json_decode($queryParams['h'] ?? '{}', true); + $query = json_decode($queryParams['q'] ?? '{}', true); + $hint = json_decode($queryParams['h'] ?? '{}', true); if (! is_array($query) || ! is_array($hint)) { throw new Exception\MalformedException('Invalid query or hint'); @@ -48,9 +43,8 @@ public function fromRequest(ServerRequestInterface $request) : Select /** * @param array $query * @param array $hint - * @return Select */ - public function fromParams(array $query, array $hint = []) : Select + public function fromParams(array $query, array $hint = []): Select { foreach ($query as $key => $value) { $this->parseQuery($key, $value, $this->select->where); @@ -63,25 +57,23 @@ public function fromParams(array $query, array $hint = []) : Select return $this->select; } - /** - * @param mixed $key - * @param mixed $value - * @param Predicate $where - */ - private function parseQuery($key, $value, Predicate $where) : void + private function parseQuery(mixed $key, mixed $value, Predicate $where): void { if ($key === BuilderInterface::OP_NULL) { $where->addPredicate(new IsNull($value)); + return; } if ($key === BuilderInterface::OP_NOT_NULL) { $where->addPredicate(new IsNotNull($value)); + return; } if (! is_array($value)) { $where->equalTo($key, $value); + return; } @@ -89,10 +81,11 @@ private function parseQuery($key, $value, Predicate $where) : void $nested = $where->nest(); foreach ($value as $query) { $value2 = reset($query); - $key2 = key($query); + $key2 = key($query); $this->parseQuery($key2, $value2, $nested); $nested->or; } + return; } @@ -100,47 +93,49 @@ private function parseQuery($key, $value, Predicate $where) : void $nested = $where->nest(); foreach ($value as $query) { $value2 = reset($query); - $key2 = key($query); + $key2 = key($query); $this->parseQuery($key2, $value2, $nested); $nested->and; } + return; } $opValue = reset($value); - $op = key($value); + $op = key($value); + + assert(is_string($op)); if (in_array($op, BuilderInterface::OP_LOGIC)) { $this->parseLogic($key, $op, $opValue, $where); + return; } if (in_array($op, BuilderInterface::OP_CONDITIONAL)) { $this->parseConditional($key, $op, $opValue, $where); + return; } } - /** - * @param mixed $key - * @param string $op - * @param mixed $value - * @param Predicate $where - */ - private function parseLogic($key, string $op, $value, Predicate $where) : void + private function parseLogic(mixed $key, string $op, mixed $value, Predicate $where): void { if ($op === BuilderInterface::OP_NOT) { $where->notEqualTo($key, $value); + return; } if ($op === BuilderInterface::OP_IN) { $where->in($key, $value); + return; } if ($op === BuilderInterface::OP_NOT_IN) { $where->notIn($key, $value); + return; } @@ -148,31 +143,29 @@ private function parseLogic($key, string $op, $value, Predicate $where) : void $where->like($key, $value); } - /** - * @param mixed $key - * @param string $op - * @param mixed $value - * @param Predicate $where - */ - private function parseConditional($key, string $op, $value, Predicate $where) : void + private function parseConditional(mixed $key, string $op, mixed $value, Predicate $where): void { if ($op === BuilderInterface::OP_GREATER) { $where->greaterThan($key, $value); + return; } if ($op === BuilderInterface::OP_GREATER_EQUAL) { $where->greaterThanOrEqualTo($key, $value); + return; } if ($op === BuilderInterface::OP_LESS) { $where->lessThan($key, $value); + return; } if ($op === BuilderInterface::OP_LESS_EQUAL) { $where->lessThanOrEqualTo($key, $value); + return; } @@ -180,30 +173,29 @@ private function parseConditional($key, string $op, $value, Predicate $where) : $where->between($key, $value[0], $value[1]); } - /** - * @param mixed $key - * @param mixed $value - * @param Select $select - */ - private function parseHint($key, $value, Select $select) : void + private function parseHint(mixed $key, mixed $value, Select $select): void { if ($key === BuilderInterface::HINT_SORT) { if (! is_array($value)) { $select->order($value); + return; } + foreach ($value as $sort => $order) { $order = in_array($order, BuilderInterface::HINT_ORDER_ASC) ? Select::ORDER_ASCENDING : Select::ORDER_DESCENDING; - $value = "$sort $order"; + $value = $sort . ' ' . $order; $select->order($value); } + return; } if ($key === BuilderInterface::HINT_LIMIT) { $select->limit($value); + return; } diff --git a/test/ZendDbBuilderTest.php b/test/LaminasDbBuilderTest.php similarity index 97% rename from test/ZendDbBuilderTest.php rename to test/LaminasDbBuilderTest.php index 09bfd02..2d3d76b 100644 --- a/test/ZendDbBuilderTest.php +++ b/test/LaminasDbBuilderTest.php @@ -4,20 +4,20 @@ namespace Los\UqlTests; use Los\Uql\Exception\MalformedException; -use Los\Uql\ZendDbBuilder; +use Los\Uql\LaminasDbBuilder; use Los\UqlTests\TestAssets\TrustingSql92Platform; use PHPUnit\Framework\TestCase; use Laminas\Db\Sql\Select; use Laminas\Diactoros\ServerRequest; -class ZendDbBuilderTest extends TestCase +class LaminasDbBuilderTest extends TestCase { - /** @var ZendDbBuilder */ + /** @var LaminasDbBuilder */ private $builder; - protected function setUp() + protected function setUp(): void { - $this->builder = new ZendDbBuilder(new Select('test')); + $this->builder = new LaminasDbBuilder(new Select('test')); } public function testFromRequestWithInvalidQuery()