From 7e52c10d6bda2ff20a59d5b4aa9d97e234746724 Mon Sep 17 00:00:00 2001 From: Zoilo Mora Date: Thu, 24 Sep 2020 08:45:22 +0200 Subject: [PATCH] Repository normalization --- .gitignore | 26 +- Dockerfile | 13 + LICENSE | 21 + Makefile | 24 + README.md | 21 + composer.json | 9 +- composer.lock | 707 +++++++++++++++++----- docker-compose.yml | 8 + phpcs.xml.dist | 15 + src/ArrayCriteriaVisitor.php | 60 +- tests/ArrayBuilderCriteriaVisitorTest.php | 24 +- tests/Mocks/Article.php | 21 +- tests/Mocks/ArticleObjectMother.php | 9 +- tests/Mocks/MemoryArticleRepository.php | 4 +- 14 files changed, 751 insertions(+), 211 deletions(-) create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100644 phpcs.xml.dist diff --git a/.gitignore b/.gitignore index 3508b15..82d96b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,24 @@ +# phpstorm project files +.idea + +# netbeans project files +nbproject/* + +# zend studio for eclipse project files +.buildpath +.project +.settings + +# windows thumbnail cache +Thumbs.db + +# Mac DS_Store Files +.DS_Store + +# Composer /vendor/ -/.idea/ -/vendor/ -.phpunit.result.cache \ No newline at end of file + +###> phpunit/phpunit ### +/phpunit.xml +.phpunit.result.cache +###< phpunit/phpunit ### diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7820763 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM php:7.4-cli-alpine3.11 + +RUN apk add --no-cache \ + libzip-dev \ + openssl-dev && \ + docker-php-ext-install -j$(nproc) \ + zip + +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer + +ENV PATH /var/app/bin:/var/app/vendor/bin:$PATH + +WORKDIR /var/app diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0629f02 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 PcComponentes + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fc363c8 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +UID=$(shell id -u) +GID=$(shell id -g) +DOCKER_PHP_SERVICE=php + +start: erase cache-folders build composer-install bash + +erase: + docker-compose down -v + +build: + docker-compose build && \ + docker-compose pull + +cache-folders: + mkdir -p ~/.composer && chown ${UID}:${GID} ~/.composer + +composer-install: + docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} composer install + +bash: + docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} sh + +logs: + docker-compose logs -f ${DOCKER_PHP_SERVICE} diff --git a/README.md b/README.md new file mode 100644 index 0000000..0e4ff76 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Criteria Array Adapter + +This an implementation of [pccomponentes/criteria](https://github.com/PcComponentes/criteria) with [Array](https://www.php.net/manual/es/language.types.array.php). +For example in memory repositories where an array contains the entities. + +## Installation + +1) Install via [composer](https://getcomposer.org/) + + ```shell script + composer require pccomponentes/criteria-array-adapter + ``` + +## Usage + +In the [pccomponentes/criteria](https://github.com/PcComponentes/criteria) repository you will get the necessary information to use **Criteria**. + +## License +Licensed under the [MIT license](http://opensource.org/licenses/MIT) + +Read [LICENSE](LICENSE) for more information diff --git a/composer.json b/composer.json index 5a10817..4878636 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { "name": "pccomponentes/criteria-array-adapter", - "description": "Adapter for array for implement filter/criteria pattern", + "description": "Implementation of pccomponentes/criteria for Array", "type": "library", "license": "MIT", "require": { "php": "^7.4", - "pccomponentes/criteria": "^0.1.1" + "pccomponentes/criteria": "^0.1.3" }, "autoload": { "psr-4": { @@ -14,11 +14,12 @@ }, "autoload-dev": { "psr-4": { - "PcComponentes\\CriteriaDBALAdapter\\Tests\\": "tests/" + "PcComponentes\\CriteriaArrayAdapter\\Tests\\": "tests/" } }, "require-dev": { "phpunit/phpunit": "^9.2", - "fzaninotto/faker": "^1.9" + "fzaninotto/faker": "^1.9", + "pccomponentes/coding-standard": "^1.2" } } diff --git a/composer.lock b/composer.lock index fd018c2..d58703d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6201716b17652e7304fe9360987c6879", + "content-hash": "0a79203c494b38769886a1665d29f765", "packages": [ { "name": "paragonie/random_compat", @@ -53,16 +53,16 @@ }, { "name": "pccomponentes/criteria", - "version": "v0.1.1", + "version": "v0.1.3", "source": { "type": "git", "url": "https://github.com/PcComponentes/criteria.git", - "reference": "4cf175f2355b0d68bd55d3076c823ee5dc5dbb03" + "reference": "ababf7ba48b10d37cae5d26797835cac911cc008" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PcComponentes/criteria/zipball/4cf175f2355b0d68bd55d3076c823ee5dc5dbb03", - "reference": "4cf175f2355b0d68bd55d3076c823ee5dc5dbb03", + "url": "https://api.github.com/repos/PcComponentes/criteria/zipball/ababf7ba48b10d37cae5d26797835cac911cc008", + "reference": "ababf7ba48b10d37cae5d26797835cac911cc008", "shasum": "" }, "require": { @@ -86,20 +86,20 @@ } ], "description": "Helper classes for implement filter/criteria pattern", - "time": "2020-06-22T13:19:39+00:00" + "time": "2020-09-21T13:40:33+00:00" }, { "name": "pccomponentes/ddd", - "version": "v2.0.2", + "version": "v2.0.3", "source": { "type": "git", "url": "https://github.com/PcComponentes/ddd.git", - "reference": "70f15d106348a012c277d43d181dcefdccf80edd" + "reference": "639457da975f155327e1a047256329a5b7c74093" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PcComponentes/ddd/zipball/70f15d106348a012c277d43d181dcefdccf80edd", - "reference": "70f15d106348a012c277d43d181dcefdccf80edd", + "url": "https://api.github.com/repos/PcComponentes/ddd/zipball/639457da975f155327e1a047256329a5b7c74093", + "reference": "639457da975f155327e1a047256329a5b7c74093", "shasum": "" }, "require": { @@ -137,7 +137,7 @@ } ], "description": "Mini Framework to create projects with hexagonal architecture and domain driven design", - "time": "2020-05-14T12:54:19+00:00" + "time": "2020-08-27T06:43:30+00:00" }, { "name": "ramsey/uuid", @@ -228,7 +228,7 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.18.0", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -304,6 +304,72 @@ } ], "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.0", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "e8d808670b8f882188368faaf1144448c169c0b7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e8d808670b8f882188368faaf1144448c169c0b7", + "reference": "e8d808670b8f882188368faaf1144448c169c0b7", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2 || ^3 || 4.0.x-dev" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "time": "2020-06-25T14:57:39+00:00" + }, { "name": "doctrine/instantiator", "version": "1.3.1", @@ -478,30 +544,125 @@ ], "time": "2020-06-29T13:22:24+00:00" }, + { + "name": "nikic/php-parser", + "version": "v4.10.1", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "1b479e7592812411c20c34d9ed33db3957bde66e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1b479e7592812411c20c34d9ed33db3957bde66e", + "reference": "1b479e7592812411c20c34d9ed33db3957bde66e", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2020-09-23T18:23:49+00:00" + }, + { + "name": "pccomponentes/coding-standard", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/PcComponentes/coding-standard.git", + "reference": "d8a704b3d6faad3b2a5b4ad247b236baef57b548" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PcComponentes/coding-standard/zipball/d8a704b3d6faad3b2a5b4ad247b236baef57b548", + "reference": "d8a704b3d6faad3b2a5b4ad247b236baef57b548", + "shasum": "" + }, + "require": { + "php": "^7.4", + "slevomat/coding-standard": "^6.4", + "squizlabs/php_codesniffer": "^3.5" + }, + "require-dev": { + "phpunit/phpunit": "^8.0", + "symfony/var-dumper": "^5.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "PcComponentesCodingStandard\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Zoilo Mora", + "email": "zoilo.mora@pccomponentes.com" + } + ], + "description": "PcComponentes Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "time": "2020-09-06T12:56:36+00:00" + }, { "name": "phar-io/manifest", - "version": "1.0.3", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", - "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", + "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", "shasum": "" }, "require": { "ext-dom": "*", "ext-phar": "*", - "phar-io/version": "^2.0", - "php": "^5.6 || ^7.0" + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -531,24 +692,24 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2018-07-08T19:23:20+00:00" + "time": "2020-06-27T14:33:11+00:00" }, { "name": "phar-io/version", - "version": "2.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", - "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "url": "https://api.github.com/repos/phar-io/version/zipball/c6bb6825def89e0a32220f88337f8ceaf1975fa0", + "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.2 || ^8.0" }, "type": "library", "autoload": { @@ -578,7 +739,7 @@ } ], "description": "Library for handling version information and constraints", - "time": "2018-07-08T19:19:57+00:00" + "time": "2020-06-27T14:39:04+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -631,16 +792,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.2.0", + "version": "5.2.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "3170448f5769fe19f456173d833734e0ff1b84df" + "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/3170448f5769fe19f456173d833734e0ff1b84df", - "reference": "3170448f5769fe19f456173d833734e0ff1b84df", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/069a785b2141f5bcf49f3e353548dc1cce6df556", + "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556", "shasum": "" }, "require": { @@ -679,20 +840,20 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2020-07-20T20:05:34+00:00" + "time": "2020-09-03T19:13:55+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "e878a14a65245fbe78f8080eba03b47c3b705651" + "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e878a14a65245fbe78f8080eba03b47c3b705651", - "reference": "e878a14a65245fbe78f8080eba03b47c3b705651", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", + "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", "shasum": "" }, "require": { @@ -724,7 +885,7 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2020-06-27T10:12:23+00:00" + "time": "2020-09-17T18:55:26+00:00" }, { "name": "phpspec/prophecy", @@ -789,34 +950,86 @@ ], "time": "2020-07-08T12:44:21+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "0.4.9", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "98a088b17966bdf6ee25c8a4b634df313d8aa531" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/98a088b17966bdf6ee25c8a4b634df313d8aa531", + "reference": "98a088b17966bdf6ee25c8a4b634df313d8aa531", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "consistence/coding-standard": "^3.5", + "ergebnis/composer-normalize": "^2.0.2", + "jakub-onderka/php-parallel-lint": "^0.9.2", + "phing/phing": "^2.16.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12.26", + "phpstan/phpstan-strict-rules": "^0.12", + "phpunit/phpunit": "^6.3", + "slevomat/coding-standard": "^4.7.2", + "symfony/process": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.4-dev" + } + }, + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "time": "2020-08-03T20:32:43+00:00" + }, { "name": "phpunit/php-code-coverage", - "version": "8.0.2", + "version": "9.1.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ca6647ffddd2add025ab3f21644a441d7c146cdc" + "reference": "c9394cb9d07ecfa9351b96f2e296bad473195f4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ca6647ffddd2add025ab3f21644a441d7c146cdc", - "reference": "ca6647ffddd2add025ab3f21644a441d7c146cdc", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c9394cb9d07ecfa9351b96f2e296bad473195f4d", + "reference": "c9394cb9d07ecfa9351b96f2e296bad473195f4d", "shasum": "" }, "require": { "ext-dom": "*", + "ext-libxml": "*", "ext-xmlwriter": "*", - "php": "^7.3", - "phpunit/php-file-iterator": "^3.0", - "phpunit/php-text-template": "^2.0", - "phpunit/php-token-stream": "^4.0", - "sebastian/code-unit-reverse-lookup": "^2.0", - "sebastian/environment": "^5.0", - "sebastian/version": "^3.0", - "theseer/tokenizer": "^1.1.3" + "nikic/php-parser": "^4.8", + "php": ">=7.3", + "phpunit/php-file-iterator": "^3.0.3", + "phpunit/php-text-template": "^2.0.2", + "sebastian/code-unit-reverse-lookup": "^2.0.2", + "sebastian/complexity": "^2.0", + "sebastian/environment": "^5.1.2", + "sebastian/lines-of-code": "^1.0", + "sebastian/version": "^3.0.1", + "theseer/tokenizer": "^1.2.0" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "suggest": { "ext-pcov": "*", @@ -825,7 +1038,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.0-dev" + "dev-master": "9.1-dev" } }, "autoload": { @@ -857,7 +1070,7 @@ "type": "github" } ], - "time": "2020-05-23T08:02:54+00:00" + "time": "2020-09-19T05:29:17+00:00" }, { "name": "phpunit/php-file-iterator", @@ -917,16 +1130,16 @@ }, { "name": "phpunit/php-invoker", - "version": "3.0.2", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-invoker.git", - "reference": "f6eedfed1085dd1f4c599629459a0277d25f9a66" + "reference": "7a85b66acc48cacffdf87dadd3694e7123674298" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f6eedfed1085dd1f4c599629459a0277d25f9a66", - "reference": "f6eedfed1085dd1f4c599629459a0277d25f9a66", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/7a85b66acc48cacffdf87dadd3694e7123674298", + "reference": "7a85b66acc48cacffdf87dadd3694e7123674298", "shasum": "" }, "require": { @@ -942,7 +1155,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -972,7 +1185,7 @@ "type": "github" } ], - "time": "2020-06-26T11:53:53+00:00" + "time": "2020-08-06T07:04:15+00:00" }, { "name": "phpunit/php-text-template", @@ -1084,73 +1297,18 @@ ], "time": "2020-06-26T11:58:13+00:00" }, - { - "name": "phpunit/php-token-stream", - "version": "4.0.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "5672711b6b07b14d5ab694e700c62eeb82fcf374" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/5672711b6b07b14d5ab694e700c62eeb82fcf374", - "reference": "5672711b6b07b14d5ab694e700c62eeb82fcf374", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": "^7.3 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2020-06-27T06:36:25+00:00" - }, { "name": "phpunit/phpunit", - "version": "9.2.6", + "version": "9.3.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1c6a9e4312e209e659f1fce3ce88dd197c2448f6" + "reference": "919333f2d046a89f9238f15d09f17a8f0baa5cc2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c6a9e4312e209e659f1fce3ce88dd197c2448f6", - "reference": "1c6a9e4312e209e659f1fce3ce88dd197c2448f6", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/919333f2d046a89f9238f15d09f17a8f0baa5cc2", + "reference": "919333f2d046a89f9238f15d09f17a8f0baa5cc2", "shasum": "" }, "require": { @@ -1161,30 +1319,31 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.9.5", - "phar-io/manifest": "^1.0.3", - "phar-io/version": "^2.0.1", - "php": "^7.3", - "phpspec/prophecy": "^1.10.3", - "phpunit/php-code-coverage": "^8.0.2", - "phpunit/php-file-iterator": "^3.0.3", - "phpunit/php-invoker": "^3.0.2", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.1", + "phar-io/version": "^3.0.2", + "php": ">=7.3", + "phpspec/prophecy": "^1.11.1", + "phpunit/php-code-coverage": "^9.1.5", + "phpunit/php-file-iterator": "^3.0.4", + "phpunit/php-invoker": "^3.1", "phpunit/php-text-template": "^2.0.2", "phpunit/php-timer": "^5.0.1", + "sebastian/cli-parser": "^1.0", "sebastian/code-unit": "^1.0.5", "sebastian/comparator": "^4.0.3", - "sebastian/diff": "^4.0.1", + "sebastian/diff": "^4.0.2", "sebastian/environment": "^5.1.2", "sebastian/exporter": "^4.0.2", - "sebastian/global-state": "^4.0", + "sebastian/global-state": "^5.0", "sebastian/object-enumerator": "^4.0.2", "sebastian/resource-operations": "^3.0.2", - "sebastian/type": "^2.1.1", + "sebastian/type": "^2.2.1", "sebastian/version": "^3.0.1" }, "require-dev": { "ext-pdo": "*", - "phpspec/prophecy-phpunit": "^2.0" + "phpspec/prophecy-phpunit": "^2.0.1" }, "suggest": { "ext-soap": "*", @@ -1196,7 +1355,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.2-dev" + "dev-master": "9.3-dev" } }, "autoload": { @@ -1235,7 +1394,59 @@ "type": "github" } ], - "time": "2020-07-13T17:55:55+00:00" + "time": "2020-09-12T09:34:39+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "2a4a38c56e62f7295bedb8b1b7439ad523d4ea82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2a4a38c56e62f7295bedb8b1b7439ad523d4ea82", + "reference": "2a4a38c56e62f7295bedb8b1b7439ad523d4ea82", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-08-12T10:49:21+00:00" }, { "name": "sebastian/code-unit", @@ -1410,6 +1621,59 @@ ], "time": "2020-06-26T12:05:46+00:00" }, + { + "name": "sebastian/complexity", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "33fcd6a26656c6546f70871244ecba4b4dced097" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/33fcd6a26656c6546f70871244ecba4b4dced097", + "reference": "33fcd6a26656c6546f70871244ecba4b4dced097", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.7", + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-07-25T14:01:34+00:00" + }, { "name": "sebastian/diff", "version": "4.0.2", @@ -1606,26 +1870,26 @@ }, { "name": "sebastian/global-state", - "version": "4.0.0", + "version": "5.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bdb1e7c79e592b8c82cb1699be3c8743119b8a72" + "reference": "22ae663c951bdc39da96603edc3239ed3a299097" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bdb1e7c79e592b8c82cb1699be3c8743119b8a72", - "reference": "bdb1e7c79e592b8c82cb1699be3c8743119b8a72", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/22ae663c951bdc39da96603edc3239ed3a299097", + "reference": "22ae663c951bdc39da96603edc3239ed3a299097", "shasum": "" }, "require": { - "php": "^7.3", + "php": "^7.3 || ^8.0", "sebastian/object-reflector": "^2.0", "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-dom": "*", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "suggest": { "ext-uopz": "*" @@ -1633,7 +1897,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -1656,7 +1920,66 @@ "keywords": [ "global state" ], - "time": "2020-02-07T06:11:37+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-08-07T04:09:03+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "e02bf626f404b5daec382a7b8a6a4456e49017e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e02bf626f404b5daec382a7b8a6a4456e49017e5", + "reference": "e02bf626f404b5daec382a7b8a6a4456e49017e5", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.6", + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-07-22T18:33:42+00:00" }, { "name": "sebastian/object-enumerator", @@ -1973,6 +2296,114 @@ ], "time": "2020-06-26T12:18:43+00:00" }, + { + "name": "slevomat/coding-standard", + "version": "6.4.0", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "bf3a16a630d8245c350b459832a71afa55c02fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/bf3a16a630d8245c350b459832a71afa55c02fd3", + "reference": "bf3a16a630d8245c350b459832a71afa55c02fd3", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", + "php": "^7.1 || ^8.0", + "phpstan/phpdoc-parser": "0.4.5 - 0.4.9", + "squizlabs/php_codesniffer": "^3.5.6" + }, + "require-dev": { + "phing/phing": "2.16.3", + "php-parallel-lint/php-parallel-lint": "1.2.0", + "phpstan/phpstan": "0.12.40", + "phpstan/phpstan-deprecation-rules": "0.12.5", + "phpstan/phpstan-phpunit": "0.12.16", + "phpstan/phpstan-strict-rules": "0.12.5", + "phpunit/phpunit": "7.5.20|8.5.5|9.3.8" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "6.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2020-08-31T07:02:52+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.5.6", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "e97627871a7eab2f70e59166072a6b767d5834e0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/e97627871a7eab2f70e59166072a6b767d5834e0", + "reference": "e97627871a7eab2f70e59166072a6b767d5834e0", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2020-08-10T04:50:15+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.0", diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5c44e40 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.7' + +services: + php: + build: . + volumes: + - .:/var/app + - ~/.composer:/.composer diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..11bb923 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,15 @@ + + + src + tests + + + + + tests/* + + + + src/ArrayCriteriaVisitor.php + + diff --git a/src/ArrayCriteriaVisitor.php b/src/ArrayCriteriaVisitor.php index 795c03e..d13180c 100644 --- a/src/ArrayCriteriaVisitor.php +++ b/src/ArrayCriteriaVisitor.php @@ -42,7 +42,35 @@ public function visitOr(OrFilter $filter) public function visitFilter(Filter $filter) { - return \array_filter($this->dataSet, $this->filter($filter)); + return \array_filter( + $this->dataSet, + static function ($item) use ($filter) { + if (\method_exists($item, $filter->field()->value())) { + $field = $filter->field()->value(); + $itemValue = \method_exists($item->$field(), 'value') + ? $item->$field()->value() + : $item->$field(); + + if (FilterOperator::EQUAL === $filter->operator()->value()) { + return $itemValue == self::cast($itemValue, $filter->value()->value()); + } + + if (FilterOperator::GT === $filter->operator()->value()) { + return $itemValue > self::cast($itemValue, $filter->value()->value()); + } + + if (FilterOperator::LT === $filter->operator()->value()) { + return $itemValue < self::cast($itemValue, $filter->value()->value()); + } + + if (FilterOperator::CONTAINS === $filter->operator()->value()) { + return false !== \strpos($itemValue, $filter->value()->value()); + } + } + + return false; + }, + ); } private static function cast($type, $value) @@ -57,36 +85,6 @@ private static function cast($type, $value) return $castedValue; } - private function filter(Filter $filter): callable - { - return static function ($item) use ($filter) { - if (\method_exists($item, $filter->field()->value())) { - $field = $filter->field()->value(); - $itemValue = \method_exists($item->$field(), 'value') - ? $item->$field()->value() - : $item->$field(); - - if (FilterOperator::EQUAL === $filter->operator()->value()) { - return $itemValue == self::cast($itemValue, $filter->value()->value()); - } - - if (FilterOperator::GT === $filter->operator()->value()) { - return $itemValue > self::cast($itemValue, $filter->value()->value()); - } - - if (FilterOperator::LT === $filter->operator()->value()) { - return $itemValue < self::cast($itemValue, $filter->value()->value()); - } - - if (FilterOperator::CONTAINS === $filter->operator()->value()) { - return false !== strpos( $itemValue, $filter->value()->value()); - } - } - - return false; - }; - } - private function intersect(array $firstArray, array $secondArray): array { $result = []; diff --git a/tests/ArrayBuilderCriteriaVisitorTest.php b/tests/ArrayBuilderCriteriaVisitorTest.php index 8fb501c..8e9404f 100644 --- a/tests/ArrayBuilderCriteriaVisitorTest.php +++ b/tests/ArrayBuilderCriteriaVisitorTest.php @@ -1,10 +1,10 @@ repository = new MemoryArticleRepository(); + parent::setUp(); } @@ -64,7 +64,7 @@ public function test_multiple_filters() new Filter( FilterField::from('stock'), FilterOperator::from(FilterOperator::EQUAL), - FilterValue::from($article->stock()), + FilterValue::from((string) $article->stock()), ), ), null, @@ -92,7 +92,7 @@ public function test_or_filter() new Filter( FilterField::from('stock'), FilterOperator::from(FilterOperator::EQUAL), - FilterValue::from($article->stock()), + FilterValue::from((string) $article->stock()), ), ), ), @@ -121,7 +121,7 @@ public function test_and_filter() new Filter( FilterField::from('stock'), FilterOperator::from(FilterOperator::EQUAL), - FilterValue::from($article->stock()), + FilterValue::from((string) $article->stock()), ), ), ), @@ -166,7 +166,7 @@ public function test_greater_than_operator() new Filter( FilterField::from('stock'), FilterOperator::from(FilterOperator::GT), - FilterValue::from($article->stock() - 1), + FilterValue::from((string) ($article->stock() - 1)), ), ), null, @@ -188,7 +188,7 @@ public function test_less_than_operator() new Filter( FilterField::from('stock'), FilterOperator::from(FilterOperator::LT), - FilterValue::from($article->stock() + 1), + FilterValue::from((string) ($article->stock() + 1)), ), ), null, @@ -263,7 +263,7 @@ public function test_filter_with_no_result() ); $result = $this->repository->filter($criteria); - $this->assertEmpty( $result); + $this->assertEmpty($result); } public function test_non_existing_filter_should_return_no_result() @@ -285,6 +285,6 @@ public function test_non_existing_filter_should_return_no_result() ); $result = $this->repository->filter($criteria); - $this->assertEmpty( $result); + $this->assertEmpty($result); } } diff --git a/tests/Mocks/Article.php b/tests/Mocks/Article.php index 163214c..b85ccdb 100644 --- a/tests/Mocks/Article.php +++ b/tests/Mocks/Article.php @@ -1,29 +1,19 @@ id = $id; $this->name = $name; $this->stock = $stock; @@ -40,7 +30,7 @@ public function name(): string return $this->name; } - public function stock(): int + public function stock(): float { return $this->stock; } @@ -49,5 +39,4 @@ public function date(): \DateTimeImmutable { return $this->date; } - } diff --git a/tests/Mocks/ArticleObjectMother.php b/tests/Mocks/ArticleObjectMother.php index 353eb9a..4424c7d 100644 --- a/tests/Mocks/ArticleObjectMother.php +++ b/tests/Mocks/ArticleObjectMother.php @@ -1,11 +1,8 @@ text(100), $faker->numberBetween(0, 1000), \DateTimeImmutable::createFromMutable($faker->dateTimeBetween('-10 year', 'now')), - (object) ['amount' => $faker->numberBetween(0,1000), 'currency' => $faker->currencyCode], ); } } diff --git a/tests/Mocks/MemoryArticleRepository.php b/tests/Mocks/MemoryArticleRepository.php index 41b2546..1bbabd4 100644 --- a/tests/Mocks/MemoryArticleRepository.php +++ b/tests/Mocks/MemoryArticleRepository.php @@ -1,6 +1,7 @@ users); + return $filter($criteria); } }