diff --git a/.gitignore b/.gitignore
index b5a07c55..5ced1162 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
/docs/coverage/
+/docs/infection/
/site/
vendor/
/.php-cs-fixer.cache
@@ -10,3 +11,4 @@ phpunit.xml
composer.phar
packages.json
results.sarif
+infection.log
diff --git a/Makefile b/Makefile
index 57dc7e12..84a42c12 100644
--- a/Makefile
+++ b/Makefile
@@ -55,6 +55,9 @@ test-clock: phpunit
test-cqrs: PHPUNIT_TESTSUITE=cqrs
test-cqrs: phpunit
+test-http-factory: PHPUNIT_TESTSUITE=http-factory
+test-http-factory: phpunit
+
test-link: PHPUNIT_TESTSUITE=link
test-link: phpunit
@@ -165,6 +168,13 @@ php-cs-fixer-upgrade:
testdox: ## Run tests and output testdox
XDEBUG_MODE=off $(PHP) -dxdebug.mode=off $(PHPUNIT) --testdox
+infection:
+ XDEBUG_MODE=develop \
+ $(PHP) \
+ -dxdebug.mode=develop \
+ -dapc.enable_cli=1 \
+ tools/infection/vendor/bin/infection --debug -vvv --show-mutations
+
tools-install: psalm-install php-cs-fixer-install phpunit-install
tools-upgrade: psalm-upgrade php-cs-fixer-upgrade phpunit-upgrade
diff --git a/bard.json b/bard.json
index b4815600..8837d7fa 100644
--- a/bard.json
+++ b/bard.json
@@ -81,6 +81,18 @@
"path": "src/SonsOfPHP/Component/Pager",
"repository": "git@github.com:SonsOfPHP/pager.git"
},
+ {
+ "path": "src/SonsOfPHP/Bridge/Doctrine/Collections/Pager",
+ "repository": "git@github.com:SonsOfPHP/pager-doctrine-collections.git"
+ },
+ {
+ "path": "src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager",
+ "repository": "git@github.com:SonsOfPHP/pager-doctrine-dbal.git"
+ },
+ {
+ "path": "src/SonsOfPHP/Bridge/Doctrine/ORM/Pager",
+ "repository": "git@github.com:SonsOfPHP/pager-doctrine-orm.git"
+ },
{
"path": "src/SonsOfPHP/Component/Version",
"repository": "git@github.com:SonsOfPHP/version.git"
diff --git a/composer.json b/composer.json
index ac53097c..d42f8f7f 100644
--- a/composer.json
+++ b/composer.json
@@ -72,7 +72,9 @@
"psr/log": "^1.0 || ^2.0 || ^3.0",
"psr/link": "^1.0 || ^2.0",
"twig/twig": "^3.0",
- "ext-intl": "*"
+ "ext-intl": "*",
+ "doctrine/collections": "^2",
+ "doctrine/orm": "^2"
},
"replace": {
"sonsofphp/bard": "self.version",
@@ -105,7 +107,10 @@
"sonsofphp/pager-contract": "self.version",
"sonsofphp/pager": "self.version",
"sonsofphp/link": "self.version",
- "sonsofphp/money-twig": "self.version"
+ "sonsofphp/money-twig": "self.version",
+ "sonsofphp/pager-doctrine-collections": "self.version",
+ "sonsofphp/pager-doctrine-dbal": "self.version",
+ "sonsofphp/pager-doctrine-orm": "self.version"
},
"autoload": {
"psr-4": {
@@ -129,6 +134,9 @@
"SonsOfPHP\\Component\\Logger\\": "src/SonsOfPHP/Component/Logger",
"SonsOfPHP\\Component\\Money\\": "src/SonsOfPHP/Component/Money",
"SonsOfPHP\\Component\\Pager\\": "src/SonsOfPHP/Component/Pager",
+ "SonsOfPHP\\Bridge\\Doctrine\\Collections\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/Collections/Pager",
+ "SonsOfPHP\\Bridge\\Doctrine\\DBAL\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager",
+ "SonsOfPHP\\Bridge\\Doctrine\\ORM\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/ORM/Pager",
"SonsOfPHP\\Component\\Version\\": "src/SonsOfPHP/Component/Version",
"SonsOfPHP\\Contract\\Common\\": "src/SonsOfPHP/Contract/Common",
"SonsOfPHP\\Contract\\Cqrs\\": "src/SonsOfPHP/Contract/Cqrs",
@@ -161,6 +169,9 @@
"src/SonsOfPHP/Component/Logger/Tests",
"src/SonsOfPHP/Component/Money/Tests",
"src/SonsOfPHP/Component/Pager/Tests",
+ "src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/Tests",
+ "src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/Tests",
+ "src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/Tests",
"src/SonsOfPHP/Component/Version/Tests"
]
},
diff --git a/docs/components/cqrs/index.md b/docs/components/cqrs/index.md
index 80a93123..0ef0ca40 100644
--- a/docs/components/cqrs/index.md
+++ b/docs/components/cqrs/index.md
@@ -48,11 +48,11 @@ $queryBus->addHandler(GetUser::class, $handler);
$query = (new GetUser())->with('id', 123);
$user = $queryBus->handle($query);
+```
!!! success "Symfony CQRS Bridge"
Once the CQRS Symfony Bridge is installed, you can use the Query Bus that
comes with that to gain addition features and functionality.
-```
## Messages
diff --git a/docs/components/pager/index.md b/docs/components/pager/index.md
index ab57ea4d..c23393aa 100644
--- a/docs/components/pager/index.md
+++ b/docs/components/pager/index.md
@@ -45,6 +45,25 @@ $pager = new Pager(new ArrayAdapter($results), [
// You can also set current page and max per page
$pager->setCurrentPage(1);
$pager->setMaxPerPage(10);
+
+
+$totalPages = $pager->getTotalPages();
+$totalResults = $pager->getTotalResults();
+$currentPage = $pager->getCurrentPage();
+
+if ($pager->haveToPaginate()) {
+ // ...
+}
+
+if ($pager->hasPreviousPage()) {
+ $prevPage = $pager->getPreviousPage();
+ // ...
+}
+
+if ($pager->hasNextPage()) {
+ $nextPage = $pager->getNextPage();
+ // ...
+}
```
## Adapters
@@ -77,3 +96,22 @@ $adapter = new CallableAdapter(
},
);
```
+
+### ArrayCollectionAdapter
+
+
+!!! warning
+ ```shell
+ composer require sonsofphp/pager-doctrine-collections
+ ```
+
+```php
+
+ src/SonsOfPHP/Bridge/*/*/Pager/Tests
src/SonsOfPHP/Component/Pager/Tests
@@ -86,7 +87,7 @@
-
+
@@ -96,6 +97,8 @@
src/SonsOfPHP/Bard/vendor
+ src/SonsOfPHP/Bridge/*/*/*/Tests
+ src/SonsOfPHP/Bridge/*/*/*/vendor
src/SonsOfPHP/Bridge/*/*/Tests
src/SonsOfPHP/Bridge/*/*/vendor
src/SonsOfPHP/Bundle/*/Tests
diff --git a/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/.gitattributes b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/.gitattributes
new file mode 100644
index 00000000..84c7add0
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/.gitattributes
@@ -0,0 +1,4 @@
+/Tests export-ignore
+/phpunit.xml.dist export-ignore
+/.gitattributes export-ignore
+/.gitignore export-ignore
diff --git a/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/.gitignore b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/.gitignore
new file mode 100644
index 00000000..5414c2c6
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/.gitignore
@@ -0,0 +1,3 @@
+composer.lock
+phpunit.xml
+vendor/
diff --git a/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/ArrayCollectionAdapter.php b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/ArrayCollectionAdapter.php
new file mode 100644
index 00000000..327b7028
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/ArrayCollectionAdapter.php
@@ -0,0 +1,34 @@
+
+ */
+class ArrayCollectionAdapter implements AdapterInterface
+{
+ public function __construct(
+ private ArrayCollection $collection,
+ ) {}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function count(): int
+ {
+ return count($this->collection);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getSlice(int $offset, ?int $length): iterable
+ {
+ return $this->collection->slice($offset, $length);
+ }
+}
diff --git a/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/LICENSE b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/LICENSE
new file mode 100644
index 00000000..39238382
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/LICENSE
@@ -0,0 +1,19 @@
+Copyright 2022 to Present Joshua Estes
+
+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/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/README.md b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/README.md
new file mode 100644
index 00000000..4b3b2a60
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/README.md
@@ -0,0 +1,17 @@
+Sons of PHP - Pager (doctrine/collections)
+==========================================
+
+## Learn More
+
+* [Documentation][docs]
+* [Contributing][contributing]
+* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the
+ [Mother Repository][mother-repo]
+* Get Help & Support using [Discussions][discussions]
+
+[discussions]: https://github.com/orgs/SonsOfPHP/discussions
+[mother-repo]: https://github.com/SonsOfPHP/sonsofphp
+[contributing]: https://docs.sonsofphp.com/contributing/
+[docs]: https://docs.sonsofphp.com/components/pager/
+[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3APager
+[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3APager
diff --git a/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/composer.json b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/composer.json
new file mode 100644
index 00000000..9ff71f0f
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/Collections/Pager/composer.json
@@ -0,0 +1,52 @@
+{
+ "name": "sonsofphp/pager-doctrine-collections",
+ "type": "library",
+ "description": "",
+ "keywords": [
+ "pager"
+ ],
+ "homepage": "https://github.com/SonsOfPHP/pager-doctrine-collections",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Joshua Estes",
+ "email": "joshua@sonsofphp.com"
+ }
+ ],
+ "support": {
+ "issues": "https://github.com/SonsOfPHP/sonsofphp/issues",
+ "forum": "https://github.com/orgs/SonsOfPHP/discussions",
+ "docs": "https://docs.sonsofphp.com"
+ },
+ "autoload": {
+ "psr-4": {
+ "SonsOfPHP\\Bridge\\Doctrine\\Collections\\Pager\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true,
+ "require": {
+ "php": ">=8.1",
+ "doctrine/collections": "^2",
+ "sonsofphp/pager": "^0.3.x-dev"
+ },
+ "extra": {
+ "sort-packages": true,
+ "branch-alias": {
+ "dev-main": "0.3.x-dev"
+ }
+ },
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/JoshuaEstes"
+ },
+ {
+ "type": "tidelift",
+ "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/.gitattributes b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/.gitattributes
new file mode 100644
index 00000000..84c7add0
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/.gitattributes
@@ -0,0 +1,4 @@
+/Tests export-ignore
+/phpunit.xml.dist export-ignore
+/.gitattributes export-ignore
+/.gitignore export-ignore
diff --git a/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/.gitignore b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/.gitignore
new file mode 100644
index 00000000..5414c2c6
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/.gitignore
@@ -0,0 +1,3 @@
+composer.lock
+phpunit.xml
+vendor/
diff --git a/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/LICENSE b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/LICENSE
new file mode 100644
index 00000000..39238382
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/LICENSE
@@ -0,0 +1,19 @@
+Copyright 2022 to Present Joshua Estes
+
+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/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/QueryBuilderAdapter.php b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/QueryBuilderAdapter.php
new file mode 100644
index 00000000..66ecfd23
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/QueryBuilderAdapter.php
@@ -0,0 +1,34 @@
+
+ */
+class QueryBuilderAdapter implements AdapterInterface
+{
+ public function __construct(
+ private QueryBuilder $builder,
+ ) {}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function count(): int
+ {
+ throw new \Exception('@todo');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getSlice(int $offset, ?int $length): iterable
+ {
+ throw new \Exception('@todo');
+ }
+}
diff --git a/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/README.md b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/README.md
new file mode 100644
index 00000000..1e8c9a14
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/README.md
@@ -0,0 +1,17 @@
+Sons of PHP - Pager (doctrine/dbal)
+===================================
+
+## Learn More
+
+* [Documentation][docs]
+* [Contributing][contributing]
+* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the
+ [Mother Repository][mother-repo]
+* Get Help & Support using [Discussions][discussions]
+
+[discussions]: https://github.com/orgs/SonsOfPHP/discussions
+[mother-repo]: https://github.com/SonsOfPHP/sonsofphp
+[contributing]: https://docs.sonsofphp.com/contributing/
+[docs]: https://docs.sonsofphp.com/components/pager/
+[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3APager
+[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3APager
diff --git a/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/composer.json b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/composer.json
new file mode 100644
index 00000000..4da91f2e
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager/composer.json
@@ -0,0 +1,52 @@
+{
+ "name": "sonsofphp/pager-doctrine-dbal",
+ "type": "library",
+ "description": "",
+ "keywords": [
+ "pager"
+ ],
+ "homepage": "https://github.com/SonsOfPHP/pager-doctrine-dbal",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Joshua Estes",
+ "email": "joshua@sonsofphp.com"
+ }
+ ],
+ "support": {
+ "issues": "https://github.com/SonsOfPHP/sonsofphp/issues",
+ "forum": "https://github.com/orgs/SonsOfPHP/discussions",
+ "docs": "https://docs.sonsofphp.com"
+ },
+ "autoload": {
+ "psr-4": {
+ "SonsOfPHP\\Bridge\\Doctrine\\DBAL\\Pager\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true,
+ "require": {
+ "php": ">=8.1",
+ "doctrine/dbal": "^3",
+ "sonsofphp/pager": "^0.3.x-dev"
+ },
+ "extra": {
+ "sort-packages": true,
+ "branch-alias": {
+ "dev-main": "0.3.x-dev"
+ }
+ },
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/JoshuaEstes"
+ },
+ {
+ "type": "tidelift",
+ "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/.gitattributes b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/.gitattributes
new file mode 100644
index 00000000..84c7add0
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/.gitattributes
@@ -0,0 +1,4 @@
+/Tests export-ignore
+/phpunit.xml.dist export-ignore
+/.gitattributes export-ignore
+/.gitignore export-ignore
diff --git a/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/.gitignore b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/.gitignore
new file mode 100644
index 00000000..5414c2c6
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/.gitignore
@@ -0,0 +1,3 @@
+composer.lock
+phpunit.xml
+vendor/
diff --git a/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/LICENSE b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/LICENSE
new file mode 100644
index 00000000..39238382
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/LICENSE
@@ -0,0 +1,19 @@
+Copyright 2022 to Present Joshua Estes
+
+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/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/README.md b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/README.md
new file mode 100644
index 00000000..871e0150
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/README.md
@@ -0,0 +1,17 @@
+Sons of PHP - Pager (doctrine/orm)
+==========================================
+
+## Learn More
+
+* [Documentation][docs]
+* [Contributing][contributing]
+* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the
+ [Mother Repository][mother-repo]
+* Get Help & Support using [Discussions][discussions]
+
+[discussions]: https://github.com/orgs/SonsOfPHP/discussions
+[mother-repo]: https://github.com/SonsOfPHP/sonsofphp
+[contributing]: https://docs.sonsofphp.com/contributing/
+[docs]: https://docs.sonsofphp.com/components/pager/
+[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3APager
+[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3APager
diff --git a/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/composer.json b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/composer.json
new file mode 100644
index 00000000..7b1197a9
--- /dev/null
+++ b/src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/composer.json
@@ -0,0 +1,52 @@
+{
+ "name": "sonsofphp/pager-doctrine-orm",
+ "type": "library",
+ "description": "",
+ "keywords": [
+ "pager"
+ ],
+ "homepage": "https://github.com/SonsOfPHP/pager-doctrine-orm",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Joshua Estes",
+ "email": "joshua@sonsofphp.com"
+ }
+ ],
+ "support": {
+ "issues": "https://github.com/SonsOfPHP/sonsofphp/issues",
+ "forum": "https://github.com/orgs/SonsOfPHP/discussions",
+ "docs": "https://docs.sonsofphp.com"
+ },
+ "autoload": {
+ "psr-4": {
+ "SonsOfPHP\\Bridge\\Doctrine\\ORM\\Pager\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true,
+ "require": {
+ "php": ">=8.1",
+ "doctrine/orm": "^2",
+ "sonsofphp/pager": "^0.3.x-dev"
+ },
+ "extra": {
+ "sort-packages": true,
+ "branch-alias": {
+ "dev-main": "0.3.x-dev"
+ }
+ },
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/JoshuaEstes"
+ },
+ {
+ "type": "tidelift",
+ "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/MessageNormalizerTest.php b/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/MessageNormalizerTest.php
index 0b0f11a3..5954cf6d 100644
--- a/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/MessageNormalizerTest.php
+++ b/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/MessageNormalizerTest.php
@@ -10,8 +10,6 @@
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
-class Msg extends AbstractMessage {}
-
/**
* @coversDefaultClass \SonsOfPHP\Bridge\Symfony\EventSourcing\Message\MessageNormalizer
*
@@ -40,7 +38,7 @@ public function testItWillNormalizeMessage(): void
{
$normalizer = new MessageNormalizer();
- $message = Msg::new();
+ $message = new class () extends AbstractMessage {};
$this->assertTrue($normalizer->supportsNormalization($message));
@@ -49,30 +47,4 @@ public function testItWillNormalizeMessage(): void
$this->assertArrayHasKey('payload', $output);
$this->assertArrayHasKey('metadata', $output);
}
-
- /**
- * @covers ::denormalize
- * @covers ::supportsDenormalization
- */
- public function testItWillDenormalizeMessage(): void
- {
- $normalizer = new MessageNormalizer();
-
- $data = [
- 'payload' => [
- 'unit' => 'test',
- ],
- 'metadata' => [
- 'test' => 'unit',
- ],
- ];
- $type = Msg::class;
-
- $this->assertTrue($normalizer->supportsDenormalization($data, $type));
-
- $output = $normalizer->denormalize($data, $type);
-
- $this->assertSame('test', $output->getPayload()['unit']);
- $this->assertSame('unit', $output->getMetadata()['test']);
- }
}
diff --git a/src/SonsOfPHP/Component/Cache/Tests/CacheItemTest.php b/src/SonsOfPHP/Component/Cache/Tests/CacheItemTest.php
index 7f719e67..cd8dc9c0 100644
--- a/src/SonsOfPHP/Component/Cache/Tests/CacheItemTest.php
+++ b/src/SonsOfPHP/Component/Cache/Tests/CacheItemTest.php
@@ -151,10 +151,10 @@ public function testValidateKeyWithInvalidValues(string $key): void
public static function invalidKeysProvider(): iterable
{
- yield [''];
+ yield 'empty' => [''];
- yield ['not allowed'];
+ yield 'space' => ['not allowed'];
- yield ['contains@reserved}characters'];
+ yield 'reserved' => ['contains@reserved}characters'];
}
}
diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessageHandler.php b/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessageHandler.php
index 28c73466..7fa52e86 100644
--- a/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessageHandler.php
+++ b/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessageHandler.php
@@ -4,6 +4,8 @@
namespace SonsOfPHP\Component\Cqrs;
+use SonsOfPHP\Contract\Cqrs\CommandMessageHandlerInterface;
+
/**
* @author Joshua Estes
*/
diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractMessage.php b/src/SonsOfPHP/Component/Cqrs/AbstractMessage.php
index 06de1337..ed3ad4fe 100644
--- a/src/SonsOfPHP/Component/Cqrs/AbstractMessage.php
+++ b/src/SonsOfPHP/Component/Cqrs/AbstractMessage.php
@@ -13,6 +13,9 @@ abstract class AbstractMessage implements MessageInterface, \JsonSerializable, \
{
private array $payload = [];
+ /**
+ * {@inheritdoc}
+ */
public function with(string|array $key, mixed $value = null): static
{
if (is_object($value) && !$value instanceof \Stringable) {
@@ -54,6 +57,9 @@ public function with(string|array $key, mixed $value = null): static
return $that;
}
+ /**
+ * {@inheritdoc}
+ */
public function get(?string $key = null): mixed
{
if (null === $key) {
diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessageHandler.php b/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessageHandler.php
index e4b76bf6..6b7d99de 100644
--- a/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessageHandler.php
+++ b/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessageHandler.php
@@ -4,6 +4,8 @@
namespace SonsOfPHP\Component\Cqrs;
+use SonsOfPHP\Contract\Cqrs\QueryMessageHandlerInterface;
+
/**
* @author Joshua Estes
*/
diff --git a/src/SonsOfPHP/Component/EventSourcing/Tests/Aggregate/Repository/AggregateRepositoryTest.php b/src/SonsOfPHP/Component/EventSourcing/Tests/Aggregate/Repository/AggregateRepositoryTest.php
index 328da0c6..55c63e7f 100644
--- a/src/SonsOfPHP/Component/EventSourcing/Tests/Aggregate/Repository/AggregateRepositoryTest.php
+++ b/src/SonsOfPHP/Component/EventSourcing/Tests/Aggregate/Repository/AggregateRepositoryTest.php
@@ -14,8 +14,6 @@
use SonsOfPHP\Component\EventSourcing\Message\Repository\MessageRepositoryInterface;
use SonsOfPHP\Component\EventSourcing\Tests\FakeAggregate;
-class Msg extends AbstractMessage {}
-
/**
* @coversDefaultClass \SonsOfPHP\Component\EventSourcing\Aggregate\Repository\AggregateRepository
*
@@ -70,7 +68,7 @@ public function testPersistWillUseEventDispatcher(): void
$aggregate = new FakeAggregate('unique-id');
- $message = Msg::new();
+ $message = new class () extends AbstractMessage {};
$aggregate->raiseThisEvent($message);
$repository->persist($aggregate);
@@ -90,7 +88,7 @@ public function testPersistAndFind(): void
$aggregate = new FakeAggregate('unique-id');
- $message = Msg::new();
+ $message = new class () extends AbstractMessage {};
$aggregate->raiseThisEvent($message);
$repository->persist($aggregate);
@@ -113,7 +111,7 @@ public function testPersistAndFindWithoutUsingAggregateId(): void
$aggregate = new FakeAggregate('unique-id');
- $message = Msg::new();
+ $message = new class () extends AbstractMessage {};
$aggregate->raiseThisEvent($message);
$repository->persist($aggregate);
diff --git a/src/SonsOfPHP/Component/EventSourcing/Tests/Message/AbstractMessageTest.php b/src/SonsOfPHP/Component/EventSourcing/Tests/Message/AbstractMessageTest.php
index 06d12356..6a5309b7 100644
--- a/src/SonsOfPHP/Component/EventSourcing/Tests/Message/AbstractMessageTest.php
+++ b/src/SonsOfPHP/Component/EventSourcing/Tests/Message/AbstractMessageTest.php
@@ -12,8 +12,6 @@
use SonsOfPHP\Component\EventSourcing\Message\MessageInterface;
use SonsOfPHP\Component\EventSourcing\Metadata;
-class Msg extends AbstractMessage {}
-
/**
* @coversDefaultClass \SonsOfPHP\Component\EventSourcing\Message\AbstractMessage
*
@@ -31,7 +29,7 @@ final class AbstractMessageTest extends TestCase
*/
public function testItHasTheRightInterface(): void
{
- $message = Msg::new();
+ $message = $this->createMock(AbstractMessage::class);
$this->assertInstanceOf(MessageInterface::class, $message);
}
@@ -41,7 +39,7 @@ public function testItHasTheRightInterface(): void
*/
public function testGetMetadataHasEmptyArraryAsDefaultValue(): void
{
- $message = Msg::new();
+ $message = $this->createMock(AbstractMessage::class)::new();
$this->assertCount(6, $message->getMetadata());
}
@@ -51,7 +49,7 @@ public function testGetMetadataHasEmptyArraryAsDefaultValue(): void
*/
public function testWithMetadataReturnsNewStatic(): void
{
- $message = Msg::new();
+ $message = $this->createMock(AbstractMessage::class)::new();
$return = $message->withMetadata([
Metadata::EVENT_TYPE => 'test',
@@ -64,7 +62,8 @@ public function testWithMetadataReturnsNewStatic(): void
*/
public function testWithMetadataWorksCorrectly(): void
{
- $message = Msg::new()->withMetadata([
+ $message = $this->createMock(AbstractMessage::class);
+ $message = $message::new()->withMetadata([
Metadata::EVENT_TYPE => 'test',
]);
@@ -81,7 +80,7 @@ public function testWithMetadataWorksCorrectly(): void
*/
public function testGettersWithEmptyMetadata(): void
{
- $message = Msg::new();
+ $message = $this->createMock(AbstractMessage::class)::new();
$this->expectException(EventSourcingException::class);
$this->assertSame('', $message->getEventId());
@@ -103,7 +102,8 @@ public function testGettersWithEmptyMetadata(): void
*/
public function testGettersWithMetadata(): void
{
- $message = Msg::new()->withMetadata([
+ $message = $this->createMock(AbstractMessage::class);
+ $message = $message::new()->withMetadata([
Metadata::EVENT_ID => 'event-id',
Metadata::EVENT_TYPE => 'event.type',
Metadata::TIMESTAMP => '2022-04-20',
@@ -126,7 +126,8 @@ public function testGettersWithMetadata(): void
*/
public function testGetAggregateIdReturnsCorrectInterface(): void
{
- $message = Msg::new()->withMetadata([
+ $message = $this->createMock(AbstractMessage::class);
+ $message = $message::new()->withMetadata([
Metadata::AGGREGATE_ID => 'aggregate-id',
]);
@@ -139,7 +140,8 @@ public function testGetAggregateIdReturnsCorrectInterface(): void
*/
public function testGetAggregateVersionReturnsCorrectInterface(): void
{
- $message = Msg::new()->withMetadata([
+ $message = $this->createMock(AbstractMessage::class);
+ $message = $message::new()->withMetadata([
Metadata::AGGREGATE_VERSION => 123,
]);
@@ -151,7 +153,7 @@ public function testGetAggregateVersionReturnsCorrectInterface(): void
*/
public function testGetPayloadHasEmptyArraryAsDefaultValue(): void
{
- $message = Msg::new();
+ $message = $this->createMock(AbstractMessage::class)::new();
$this->assertCount(0, $message->getPayload());
}
@@ -161,7 +163,7 @@ public function testGetPayloadHasEmptyArraryAsDefaultValue(): void
*/
public function testWithPayloadReturnsNewStatic(): void
{
- $message = Msg::new();
+ $message = $this->createMock(AbstractMessage::class)::new();
$return = $message->withPayload([
'key' => 'val',
@@ -174,7 +176,8 @@ public function testWithPayloadReturnsNewStatic(): void
*/
public function testWithPayloadWorksCorrectly(): void
{
- $message = Msg::new()->withPayload([
+ $message = $this->createMock(AbstractMessage::class);
+ $message = $message::new()->withPayload([
'key' => 'val',
]);
diff --git a/src/SonsOfPHP/Component/EventSourcing/Tests/Message/Enricher/MessageEnricherTest.php b/src/SonsOfPHP/Component/EventSourcing/Tests/Message/Enricher/MessageEnricherTest.php
index 8f87ef2d..a0c5d434 100644
--- a/src/SonsOfPHP/Component/EventSourcing/Tests/Message/Enricher/MessageEnricherTest.php
+++ b/src/SonsOfPHP/Component/EventSourcing/Tests/Message/Enricher/MessageEnricherTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\EventSourcing\Tests\Message;
+namespace SonsOfPHP\Component\EventSourcing\Tests\Message\Enricher;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\EventSourcing\Message\Enricher\Handler\NullMessageEnricherHandler;
diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ChainAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ChainAdapterTest.php
index 75b8c36c..426550e8 100644
--- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ChainAdapterTest.php
+++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ChainAdapterTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\Filesystem\Tests;
+namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/InMemoryAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/InMemoryAdapterTest.php
index ef9fa5b9..135fa225 100644
--- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/InMemoryAdapterTest.php
+++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/InMemoryAdapterTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\Filesystem\Tests;
+namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/NativeAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/NativeAdapterTest.php
index 833833d1..2474974a 100644
--- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/NativeAdapterTest.php
+++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/NativeAdapterTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\Filesystem\Tests;
+namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/NullAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/NullAdapterTest.php
index 654d747a..f95a1084 100644
--- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/NullAdapterTest.php
+++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/NullAdapterTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\Filesystem\Tests;
+namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ReadOnlyAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ReadOnlyAdapterTest.php
index 939058de..32f9597b 100644
--- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ReadOnlyAdapterTest.php
+++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ReadOnlyAdapterTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\Filesystem\Tests;
+namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;
use PHPUnit\Framework\MockObject;
use PHPUnit\Framework\TestCase;
diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/WormAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/WormAdapterTest.php
index dbaae807..66569e7e 100644
--- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/WormAdapterTest.php
+++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/WormAdapterTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\Filesystem\Tests;
+namespace SonsOfPHP\Component\Filesystem\Tests\Adapter;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface;
diff --git a/src/SonsOfPHP/Component/HttpFactory/HttpFactory.php b/src/SonsOfPHP/Component/HttpFactory/HttpFactory.php
index e8ad321a..1a63bd7a 100644
--- a/src/SonsOfPHP/Component/HttpFactory/HttpFactory.php
+++ b/src/SonsOfPHP/Component/HttpFactory/HttpFactory.php
@@ -15,7 +15,7 @@ final class HttpFactory implements RequestFactoryInterface
{
use RequestFactoryTrait;
use ResponseFactoryTrait;
- use ServerResponseFactoryTrait;
+ use ServerRequestFactoryTrait;
use StreamFactoryTrait;
use UploadedFileFactoryTrait;
use UriFactoryTrait;
diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php
index 13bb0373..b94da85b 100644
--- a/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php
+++ b/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php
@@ -11,6 +11,7 @@
/**
* @coversDefaultClass \SonsOfPHP\Component\HttpFactory\ResponseFactory
+ * @uses \SonsOfPHP\Component\HttpMessage\Response
*/
final class ResponseFactoryTest extends TestCase
{
@@ -23,13 +24,21 @@ public function testItImplementsCorrectInterface(): void
}
/**
+ * @dataProvider validCreateResponseProvider
+ *
* @covers ::createResponse
- * @uses \SonsOfPHP\Component\HttpMessage\Response
*/
- public function testCreateResponseWorksAsExpected(): void
+ public function testCreateResponseWorksAsExpected(int $code, string $reasonPhrase): void
{
$factory = new ResponseFactory();
- $this->assertInstanceOf(ResponseInterface::class, $factory->createResponse());
+ $this->assertInstanceOf(ResponseInterface::class, $factory->createResponse($code, $reasonPhrase));
+ }
+
+ public static function validCreateResponseProvider(): iterable
+ {
+ yield [200, 'OK'];
+ yield [201, 'Not Content'];
+ yield [404, 'Not Found'];
}
}
diff --git a/src/SonsOfPHP/Component/Money/Amount.php b/src/SonsOfPHP/Component/Money/Amount.php
index 5fe7cecd..d986f484 100644
--- a/src/SonsOfPHP/Component/Money/Amount.php
+++ b/src/SonsOfPHP/Component/Money/Amount.php
@@ -17,8 +17,8 @@
use SonsOfPHP\Component\Money\Query\Amount\IsPositiveAmountQuery;
use SonsOfPHP\Component\Money\Query\Amount\IsZeroAmountQuery;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
@@ -60,32 +60,32 @@ public function getAmount(): string
return $this->amount;
}
- public function with(AmountOperatorInterface $operator): AmountInterface
+ public function with(AmountOperatorInterface $operator): static
{
return $operator->apply($this);
}
- public function query(AmountQueryInterface $query)
+ public function query(AmountQueryInterface $query)/*: mixed*/
{
return $query->queryFrom($this);
}
- public function add(AmountInterface $amount): AmountInterface
+ public function add(AmountInterface $amount): static
{
return $this->with(new AddAmountOperator($amount));
}
- public function subtract(AmountInterface $amount): AmountInterface
+ public function subtract(AmountInterface $amount): static
{
return $this->with(new SubtractAmountOperator($amount));
}
- public function multiply($multiplier): AmountInterface
+ public function multiply($multiplier): static
{
return $this->with(new MultiplyAmountOperator($multiplier));
}
- public function divide($divisor): AmountInterface
+ public function divide($divisor): static
{
return $this->with(new DivideAmountOperator($divisor));
}
diff --git a/src/SonsOfPHP/Component/Money/Currency.php b/src/SonsOfPHP/Component/Money/Currency.php
index 517de761..f1188243 100644
--- a/src/SonsOfPHP/Component/Money/Currency.php
+++ b/src/SonsOfPHP/Component/Money/Currency.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Query\Currency\IsEqualToCurrencyQuery;
use SonsOfPHP\Contract\Money\CurrencyInterface;
-use SonsOfPHP\Contract\Money\Query\Currency\CurrencyQueryInterface;
+use SonsOfPHP\Contract\Money\CurrencyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/CurrencyProvider/AbstractCurrencyProvider.php b/src/SonsOfPHP/Component/Money/CurrencyProvider/AbstractCurrencyProvider.php
index 6a547481..83204bed 100644
--- a/src/SonsOfPHP/Component/Money/CurrencyProvider/AbstractCurrencyProvider.php
+++ b/src/SonsOfPHP/Component/Money/CurrencyProvider/AbstractCurrencyProvider.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Query\CurrencyProvider\HasCurrencyQuery;
use SonsOfPHP\Contract\Money\CurrencyInterface;
use SonsOfPHP\Contract\Money\CurrencyProviderInterface;
-use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface;
+use SonsOfPHP\Contract\Money\CurrencyProviderQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Money.php b/src/SonsOfPHP/Component/Money/Money.php
index b4e57beb..6ac58c35 100644
--- a/src/SonsOfPHP/Component/Money/Money.php
+++ b/src/SonsOfPHP/Component/Money/Money.php
@@ -19,13 +19,13 @@
use SonsOfPHP\Contract\Money\AmountInterface;
use SonsOfPHP\Contract\Money\CurrencyInterface;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
*/
-final class Money implements MoneyInterface
+final class Money implements MoneyInterface, \JsonSerializable
{
private AmountInterface $amount;
private CurrencyInterface $currency;
@@ -151,4 +151,12 @@ public function divide($divisor): MoneyInterface
{
return $this->with(new DivideMoneyOperator($divisor));
}
+
+ public function jsonSerialize(): array
+ {
+ return [
+ 'amount' => $this->getAmount()->toInt(),
+ 'currency' => $this->getCurrency()->getCurrencyCode(),
+ ];
+ }
}
diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/AddAmountOperator.php b/src/SonsOfPHP/Component/Money/Operator/Amount/AddAmountOperator.php
index 2d5cbce2..0c987e5c 100644
--- a/src/SonsOfPHP/Component/Money/Operator/Amount/AddAmountOperator.php
+++ b/src/SonsOfPHP/Component/Money/Operator/Amount/AddAmountOperator.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/DivideAmountOperator.php b/src/SonsOfPHP/Component/Money/Operator/Amount/DivideAmountOperator.php
index 689f59b3..0cc403be 100644
--- a/src/SonsOfPHP/Component/Money/Operator/Amount/DivideAmountOperator.php
+++ b/src/SonsOfPHP/Component/Money/Operator/Amount/DivideAmountOperator.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/MultiplyAmountOperator.php b/src/SonsOfPHP/Component/Money/Operator/Amount/MultiplyAmountOperator.php
index 70120c86..8ac20c58 100644
--- a/src/SonsOfPHP/Component/Money/Operator/Amount/MultiplyAmountOperator.php
+++ b/src/SonsOfPHP/Component/Money/Operator/Amount/MultiplyAmountOperator.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/SubtractAmountOperator.php b/src/SonsOfPHP/Component/Money/Operator/Amount/SubtractAmountOperator.php
index 7881fad3..4fa9dfcf 100644
--- a/src/SonsOfPHP/Component/Money/Operator/Amount/SubtractAmountOperator.php
+++ b/src/SonsOfPHP/Component/Money/Operator/Amount/SubtractAmountOperator.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/AddMoneyOperator.php b/src/SonsOfPHP/Component/Money/Operator/Money/AddMoneyOperator.php
index 9a54ccf1..9becfbcf 100644
--- a/src/SonsOfPHP/Component/Money/Operator/Money/AddMoneyOperator.php
+++ b/src/SonsOfPHP/Component/Money/Operator/Money/AddMoneyOperator.php
@@ -7,7 +7,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/DivideMoneyOperator.php b/src/SonsOfPHP/Component/Money/Operator/Money/DivideMoneyOperator.php
index 224760c3..eb7f98c0 100644
--- a/src/SonsOfPHP/Component/Money/Operator/Money/DivideMoneyOperator.php
+++ b/src/SonsOfPHP/Component/Money/Operator/Money/DivideMoneyOperator.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/MultiplyMoneyOperator.php b/src/SonsOfPHP/Component/Money/Operator/Money/MultiplyMoneyOperator.php
index 2e1d0302..f5f22ebc 100644
--- a/src/SonsOfPHP/Component/Money/Operator/Money/MultiplyMoneyOperator.php
+++ b/src/SonsOfPHP/Component/Money/Operator/Money/MultiplyMoneyOperator.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/SubtractMoneyOperator.php b/src/SonsOfPHP/Component/Money/Operator/Money/SubtractMoneyOperator.php
index 5822b388..d3402bc4 100644
--- a/src/SonsOfPHP/Component/Money/Operator/Money/SubtractMoneyOperator.php
+++ b/src/SonsOfPHP/Component/Money/Operator/Money/SubtractMoneyOperator.php
@@ -7,7 +7,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsEqualToAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsEqualToAmountQuery.php
index f6e86581..c3b32926 100644
--- a/src/SonsOfPHP/Component/Money/Query/Amount/IsEqualToAmountQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsEqualToAmountQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanAmountQuery.php
index 6fba3d12..65d71bd3 100644
--- a/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanAmountQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanAmountQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanOrEqualToAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanOrEqualToAmountQuery.php
index 15204625..7e63aa4c 100644
--- a/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanOrEqualToAmountQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanOrEqualToAmountQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanAmountQuery.php
index dee98c25..86d98f03 100644
--- a/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanAmountQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanAmountQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanOrEqualToAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanOrEqualToAmountQuery.php
index c27ae797..e7bd7fa8 100644
--- a/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanOrEqualToAmountQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanOrEqualToAmountQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsNegativeAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsNegativeAmountQuery.php
index 82fbf59f..aba098fd 100644
--- a/src/SonsOfPHP/Component/Money/Query/Amount/IsNegativeAmountQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsNegativeAmountQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsPositiveAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsPositiveAmountQuery.php
index d5d16881..e707149f 100644
--- a/src/SonsOfPHP/Component/Money/Query/Amount/IsPositiveAmountQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsPositiveAmountQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsZeroAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsZeroAmountQuery.php
index 34baf643..9a855e03 100644
--- a/src/SonsOfPHP/Component/Money/Query/Amount/IsZeroAmountQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsZeroAmountQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Amount;
use SonsOfPHP\Contract\Money\AmountInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Currency/IsEqualToCurrencyQuery.php b/src/SonsOfPHP/Component/Money/Query/Currency/IsEqualToCurrencyQuery.php
index 94746b7a..188982e9 100644
--- a/src/SonsOfPHP/Component/Money/Query/Currency/IsEqualToCurrencyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Currency/IsEqualToCurrencyQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Currency;
use SonsOfPHP\Contract\Money\CurrencyInterface;
-use SonsOfPHP\Contract\Money\Query\Currency\CurrencyQueryInterface;
+use SonsOfPHP\Contract\Money\CurrencyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/GetCurrencyQuery.php b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/GetCurrencyQuery.php
index 88786024..bb6ca981 100644
--- a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/GetCurrencyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/GetCurrencyQuery.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Contract\Money\CurrencyInterface;
use SonsOfPHP\Contract\Money\CurrencyProviderInterface;
-use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface;
+use SonsOfPHP\Contract\Money\CurrencyProviderQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/HasCurrencyQuery.php b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/HasCurrencyQuery.php
index 1e4fbb1a..3f2b9669 100644
--- a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/HasCurrencyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/HasCurrencyQuery.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Contract\Money\CurrencyInterface;
use SonsOfPHP\Contract\Money\CurrencyProviderInterface;
-use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface;
+use SonsOfPHP\Contract\Money\CurrencyProviderQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsEqualToMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsEqualToMoneyQuery.php
index cd8334eb..cdb09659 100644
--- a/src/SonsOfPHP/Component/Money/Query/Money/IsEqualToMoneyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Money/IsEqualToMoneyQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Money;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanMoneyQuery.php
index dd8ac01e..c63bde93 100644
--- a/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanMoneyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanMoneyQuery.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanOrEqualToMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanOrEqualToMoneyQuery.php
index 76ea907d..a474db26 100644
--- a/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanOrEqualToMoneyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanOrEqualToMoneyQuery.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanMoneyQuery.php
index a79fc4ed..2b24df34 100644
--- a/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanMoneyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanMoneyQuery.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanOrEqualToMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanOrEqualToMoneyQuery.php
index 38f88b9b..82880b88 100644
--- a/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanOrEqualToMoneyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanOrEqualToMoneyQuery.php
@@ -6,7 +6,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsNegativeMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsNegativeMoneyQuery.php
index 441e4602..ba29a77f 100644
--- a/src/SonsOfPHP/Component/Money/Query/Money/IsNegativeMoneyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Money/IsNegativeMoneyQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Money;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsPositiveMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsPositiveMoneyQuery.php
index b1597f44..3a1fb918 100644
--- a/src/SonsOfPHP/Component/Money/Query/Money/IsPositiveMoneyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Money/IsPositiveMoneyQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Money;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsZeroMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsZeroMoneyQuery.php
index 9d7f29d6..b43ffba1 100644
--- a/src/SonsOfPHP/Component/Money/Query/Money/IsZeroMoneyQuery.php
+++ b/src/SonsOfPHP/Component/Money/Query/Money/IsZeroMoneyQuery.php
@@ -5,7 +5,7 @@
namespace SonsOfPHP\Component\Money\Query\Money;
use SonsOfPHP\Contract\Money\MoneyInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Component/Money/Tests/AmountTest.php b/src/SonsOfPHP/Component/Money/Tests/AmountTest.php
index 700bf28c..07bb9a43 100644
--- a/src/SonsOfPHP/Component/Money/Tests/AmountTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/AmountTest.php
@@ -27,6 +27,22 @@
*/
final class AmountTest extends TestCase
{
+ public static function validAmountProvider(): iterable
+ {
+ yield [420];
+ yield ['420'];
+ yield [-420];
+ yield ['-420'];
+ }
+
+ public static function invalidAmountProvider(): iterable
+ {
+ yield [4.20];
+ yield ['4.20'];
+ yield [-4.20];
+ yield ['-4.20'];
+ }
+
/**
* @covers ::__construct
*/
diff --git a/src/SonsOfPHP/Component/Money/Tests/CurrencyTest.php b/src/SonsOfPHP/Component/Money/Tests/CurrencyTest.php
index 299e6ccc..764d13a3 100644
--- a/src/SonsOfPHP/Component/Money/Tests/CurrencyTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/CurrencyTest.php
@@ -16,6 +16,16 @@
*/
final class CurrencyTest extends TestCase
{
+ /**
+ * @covers ::__construct
+ */
+ public function testContructWillValidateCurrencyCode(): void
+ {
+ $currency = new Currency('usd');
+
+ $this->assertSame('USD', $currency->getCurrencyCode());
+ }
+
/**
* @covers ::__callStatic
* @covers ::__construct
diff --git a/src/SonsOfPHP/Component/Money/Tests/MoneyTest.php b/src/SonsOfPHP/Component/Money/Tests/MoneyTest.php
index 8f8ab3ad..2ed99691 100644
--- a/src/SonsOfPHP/Component/Money/Tests/MoneyTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/MoneyTest.php
@@ -44,6 +44,14 @@
*/
final class MoneyTest extends TestCase
{
+ public static function validMoneyConstructorArgumentsProvider(): iterable
+ {
+ yield [420, 'usd'];
+ yield [420, new Currency('usd')];
+ yield [-420, 'usd'];
+ yield [-420, new Currency('usd')];
+ }
+
/**
* @covers ::__callStatic
* @covers ::__construct
@@ -363,4 +371,14 @@ public function testDivide(): void
$output = $money1->divide(5);
$this->assertSame('20', (string) $output->getAmount());
}
+
+ /**
+ * @covers ::jsonSerialize
+ */
+ public function testJsonSerialize(): void
+ {
+ $money = Money::USD(420);
+
+ $this->assertSame('{"amount":420,"currency":"USD"}', json_encode($money));
+ }
}
diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/AddAmountOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/AddAmountOperatorTest.php
index b593eeed..a09f3d86 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/AddAmountOperatorTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/AddAmountOperatorTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Operator\Amount\AddAmountOperator;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Amount\AddAmountOperator
diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/DivideAmountOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/DivideAmountOperatorTest.php
index e143641e..fcd6afb2 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/DivideAmountOperatorTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/DivideAmountOperatorTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Operator\Amount\DivideAmountOperator;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Amount\DivideAmountOperator
diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/MultiplyAmountOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/MultiplyAmountOperatorTest.php
index 21844e66..6b8ee735 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/MultiplyAmountOperatorTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/MultiplyAmountOperatorTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Operator\Amount\MultiplyAmountOperator;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Amount\MultiplyAmountOperator
diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/SubtractAmountOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/SubtractAmountOperatorTest.php
index 0f5cc314..80e08c18 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/SubtractAmountOperatorTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/SubtractAmountOperatorTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Operator\Amount\SubtractAmountOperator;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
+use SonsOfPHP\Contract\Money\AmountOperatorInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Amount\SubtractAmountOperator
diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/AddMoneyOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/AddMoneyOperatorTest.php
index e3f29f50..22bf8ade 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/AddMoneyOperatorTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/AddMoneyOperatorTest.php
@@ -9,7 +9,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Operator\Money\AddMoneyOperator;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Money\AddMoneyOperator
diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/DivideMoneyOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/DivideMoneyOperatorTest.php
index 7948d979..66dbf5a7 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/DivideMoneyOperatorTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/DivideMoneyOperatorTest.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Operator\Money\DivideMoneyOperator;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Money\DivideMoneyOperator
diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/MultiplyMoneyOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/MultiplyMoneyOperatorTest.php
index 4ca68b93..0c443f1e 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/MultiplyMoneyOperatorTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/MultiplyMoneyOperatorTest.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Operator\Money\MultiplyMoneyOperator;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Money\MultiplyMoneyOperator
diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/SubtractMoneyOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/SubtractMoneyOperatorTest.php
index 5bbc6b9a..7e161ae3 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/SubtractMoneyOperatorTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/SubtractMoneyOperatorTest.php
@@ -9,7 +9,7 @@
use SonsOfPHP\Component\Money\Exception\MoneyException;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Operator\Money\SubtractMoneyOperator;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
+use SonsOfPHP\Contract\Money\MoneyOperatorInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Money\SubtractMoneyOperator
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsEqualToAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsEqualToAmountQueryTest.php
index 669e8a85..efbe16e8 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsEqualToAmountQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsEqualToAmountQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Query\Amount\IsEqualToAmountQuery;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsEqualToAmountQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanAmountQueryTest.php
index fc17a297..2b9f85a2 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanAmountQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanAmountQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanAmountQuery;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanAmountQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanOrEqualToAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanOrEqualToAmountQueryTest.php
index c975fe43..2157df5a 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanOrEqualToAmountQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanOrEqualToAmountQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanOrEqualToAmountQuery;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanOrEqualToAmountQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanAmountQueryTest.php
index 1318ed67..f17b64f2 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanAmountQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanAmountQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Query\Amount\IsLessThanAmountQuery;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsLessThanAmountQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanOrEqualToAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanOrEqualToAmountQueryTest.php
index 6f422fc4..2fb87f97 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanOrEqualToAmountQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanOrEqualToAmountQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Query\Amount\IsLessThanOrEqualToAmountQuery;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsLessThanOrEqualToAmountQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsNegativeAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsNegativeAmountQueryTest.php
index f5ed3247..3076b82d 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsNegativeAmountQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsNegativeAmountQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Query\Amount\IsNegativeAmountQuery;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsNegativeAmountQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsPositiveAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsPositiveAmountQueryTest.php
index 28944e8e..dd8a6050 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsPositiveAmountQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsPositiveAmountQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Query\Amount\IsPositiveAmountQuery;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsPositiveAmountQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsZeroAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsZeroAmountQueryTest.php
index 87e66965..1f3946c3 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsZeroAmountQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsZeroAmountQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Amount;
use SonsOfPHP\Component\Money\Query\Amount\IsZeroAmountQuery;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
+use SonsOfPHP\Contract\Money\AmountQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsZeroAmountQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Currency/IsEqualToCurrencyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Currency/IsEqualToCurrencyQueryTest.php
index 055424b6..78dff0f6 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Currency/IsEqualToCurrencyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Currency/IsEqualToCurrencyQueryTest.php
@@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\Query\Currency\IsEqualToCurrencyQuery;
-use SonsOfPHP\Contract\Money\Query\Currency\CurrencyQueryInterface;
+use SonsOfPHP\Contract\Money\CurrencyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Currency\IsEqualToCurrencyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/GetCurrencyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/GetCurrencyQueryTest.php
index 31ca2e67..a3fae2cc 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/GetCurrencyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/GetCurrencyQueryTest.php
@@ -2,14 +2,14 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\Money\Tests\Query\Currency;
+namespace SonsOfPHP\Component\Money\Tests\Query\CurrencyProvider;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\CurrencyProvider\XCurrencyProvider;
use SonsOfPHP\Component\Money\Query\CurrencyProvider\GetCurrencyQuery;
+use SonsOfPHP\Contract\Money\CurrencyProviderQueryInterface;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\CurrencyProvider\GetCurrencyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/HasCurrencyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/HasCurrencyQueryTest.php
index 9c2681d2..ce889b40 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/HasCurrencyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/HasCurrencyQueryTest.php
@@ -2,14 +2,14 @@
declare(strict_types=1);
-namespace SonsOfPHP\Component\Money\Tests\Query\Currency;
+namespace SonsOfPHP\Component\Money\Tests\Query\CurrencyProvider;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\CurrencyProvider\XCurrencyProvider;
use SonsOfPHP\Component\Money\Query\CurrencyProvider\HasCurrencyQuery;
+use SonsOfPHP\Contract\Money\CurrencyProviderQueryInterface;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\CurrencyProvider\HasCurrencyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsEqualToMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsEqualToMoneyQueryTest.php
index b1ca02df..27adb027 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsEqualToMoneyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsEqualToMoneyQueryTest.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Query\Money\IsEqualToMoneyQuery;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Money\IsEqualToMoneyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanMoneyQueryTest.php
index 3bccba6c..a13d2aec 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanMoneyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanMoneyQueryTest.php
@@ -9,7 +9,7 @@
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Query\Money\IsGreaterThanMoneyQuery;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Money\IsGreaterThanMoneyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanOrEqualToMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanOrEqualToMoneyQueryTest.php
index 3e1bb096..592f0dff 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanOrEqualToMoneyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanOrEqualToMoneyQueryTest.php
@@ -9,7 +9,7 @@
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Query\Money\IsGreaterThanOrEqualToMoneyQuery;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Money\IsGreaterThanOrEqualToMoneyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanMoneyQueryTest.php
index bcfe6d81..40ea0b1c 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanMoneyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanMoneyQueryTest.php
@@ -9,7 +9,7 @@
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Query\Money\IsLessThanMoneyQuery;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Money\IsLessThanMoneyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanOrEqualToMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanOrEqualToMoneyQueryTest.php
index f341a9ab..10cf66b7 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanOrEqualToMoneyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanOrEqualToMoneyQueryTest.php
@@ -9,7 +9,7 @@
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Query\Money\IsLessThanOrEqualToMoneyQuery;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Money\IsLessThanOrEqualToMoneyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsNegativeMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsNegativeMoneyQueryTest.php
index d2b6fbda..cfd9e990 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsNegativeMoneyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsNegativeMoneyQueryTest.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Query\Money\IsNegativeMoneyQuery;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Money\IsNegativeMoneyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsPositiveMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsPositiveMoneyQueryTest.php
index 8f9ee2e0..335d2a89 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsPositiveMoneyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsPositiveMoneyQueryTest.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Query\Money\IsPositiveMoneyQuery;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Money\IsPositiveMoneyQuery
diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsZeroMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsZeroMoneyQueryTest.php
index cd7f8991..ee85b349 100644
--- a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsZeroMoneyQueryTest.php
+++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsZeroMoneyQueryTest.php
@@ -8,7 +8,7 @@
use SonsOfPHP\Component\Money\Currency;
use SonsOfPHP\Component\Money\Money;
use SonsOfPHP\Component\Money\Query\Money\IsZeroMoneyQuery;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
+use SonsOfPHP\Contract\Money\MoneyQueryInterface;
/**
* @coversDefaultClass \SonsOfPHP\Component\Money\Query\Money\IsZeroMoneyQuery
diff --git a/src/SonsOfPHP/Component/Pager/Pager.php b/src/SonsOfPHP/Component/Pager/Pager.php
index 1c40f569..5612fa16 100644
--- a/src/SonsOfPHP/Component/Pager/Pager.php
+++ b/src/SonsOfPHP/Component/Pager/Pager.php
@@ -35,6 +35,9 @@ public function __construct(
}
}
+ /**
+ * {@inheritdoc}
+ */
public function getCurrentPageResults(): iterable
{
if (null === $this->results) {
@@ -49,6 +52,9 @@ public function getCurrentPageResults(): iterable
return $this->results;
}
+ /**
+ * {@inheritdoc}
+ */
public function getTotalResults(): int
{
if (null === $this->count) {
@@ -58,6 +64,9 @@ public function getTotalResults(): int
return $this->count;
}
+ /**
+ * {@inheritdoc}
+ */
public function getTotalPages(): int
{
if (null === $this->getMaxPerPage() || 0 === $this->getTotalResults()) {
@@ -67,6 +76,9 @@ public function getTotalPages(): int
return (int) ceil($this->getTotalResults() / $this->getMaxPerPage());
}
+ /**
+ * {@inheritdoc}
+ */
public function haveToPaginate(): bool
{
if (null === $this->getMaxPerPage()) {
@@ -76,11 +88,17 @@ public function haveToPaginate(): bool
return $this->getTotalResults() > $this->getMaxPerPage();
}
+ /**
+ * {@inheritdoc}
+ */
public function hasPreviousPage(): bool
{
return $this->getCurrentPage() > 1;
}
+ /**
+ * {@inheritdoc}
+ */
public function getPreviousPage(): ?int
{
if ($this->hasPreviousPage()) {
@@ -90,11 +108,17 @@ public function getPreviousPage(): ?int
return null;
}
+ /**
+ * {@inheritdoc}
+ */
public function hasNextPage(): bool
{
return $this->getCurrentPage() < $this->getTotalPages();
}
+ /**
+ * {@inheritdoc}
+ */
public function getNextPage(): ?int
{
if ($this->hasNextPage()) {
@@ -104,11 +128,17 @@ public function getNextPage(): ?int
return null;
}
+ /**
+ * {@inheritdoc}
+ */
public function getCurrentPage(): int
{
return $this->currentPage;
}
+ /**
+ * {@inheritdoc}
+ */
public function setCurrentPage(int $page): void
{
if (1 > $page) {
@@ -119,11 +149,17 @@ public function setCurrentPage(int $page): void
$this->results = null;
}
+ /**
+ * {@inheritdoc}
+ */
public function getMaxPerPage(): ?int
{
return $this->maxPerPage;
}
+ /**
+ * {@inheritdoc}
+ */
public function setMaxPerPage(?int $maxPerPage): void
{
if (is_int($maxPerPage) && 1 > $maxPerPage) {
diff --git a/src/SonsOfPHP/Contract/Common/ArrayableInterface.php b/src/SonsOfPHP/Contract/Common/ArrayableInterface.php
index 1771476a..823452a3 100644
--- a/src/SonsOfPHP/Contract/Common/ArrayableInterface.php
+++ b/src/SonsOfPHP/Contract/Common/ArrayableInterface.php
@@ -9,7 +9,5 @@
*/
interface ArrayableInterface
{
- /**
- */
public function toArray(): array;
}
diff --git a/src/SonsOfPHP/Contract/Common/TryableInterface.php b/src/SonsOfPHP/Contract/Common/TryableInterface.php
new file mode 100644
index 00000000..e74e2f14
--- /dev/null
+++ b/src/SonsOfPHP/Contract/Common/TryableInterface.php
@@ -0,0 +1,24 @@
+
+ */
+interface TryableInterface
+{
+ /**
+ * Pass in $data and the object is built.
+ *
+ * @throws \InvalidArgumentException
+ * If $data is invalid
+ */
+ public static function from(mixed $data): static;
+
+ /**
+ * Pass in data and if the data is invalid it will return null
+ */
+ public function tryFrom(mixed $data): ?static;
+}
diff --git a/src/SonsOfPHP/Contract/Money/AmountInterface.php b/src/SonsOfPHP/Contract/Money/AmountInterface.php
index f5f7a456..a2e2f5f4 100644
--- a/src/SonsOfPHP/Contract/Money/AmountInterface.php
+++ b/src/SonsOfPHP/Contract/Money/AmountInterface.php
@@ -4,34 +4,28 @@
namespace SonsOfPHP\Contract\Money;
-use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface;
-use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface;
-
/**
* Amount.
*
* The amount is used to represent the Numerical Value of the Money.
*
+ * The amount SHOULD be represented in the smallest form of the currency. So
+ * for USD a value of `420` would represent `$4.20`.
+ *
* @author Joshua Estes
*/
-interface AmountInterface
+interface AmountInterface // extends \Stringable
{
- /**
- * Considering some of these methods.
- */
- // public function getPrecision(): int;
- // public function getScale(): int;
-
/**
* Allows you to run you own operations of the amount.
*/
- public function with(AmountOperatorInterface $operator): self;
+ public function with(AmountOperatorInterface $operator): static;
/**
* Allows you to ask different questions about the amount and get
* different results returned to you.
*/
- public function query(AmountQueryInterface $query);
+ public function query(AmountQueryInterface $query)/*: mixed*/;
/**
* Returns the value for this amount as a string.
@@ -46,7 +40,7 @@ public function toInt(): int;
/**
* Returns the value for this amount as a float.
*/
- public function toFloat(): float;
+ //public function toFloat(): float;
/**
* Returns the value that this is for the object.
@@ -56,7 +50,7 @@ public function getAmount(): string;
/**
* Add amounts together.
*/
- public function add(self $amount): self;
+ public function add(AmountInterface $amount): static;
/**
* Subtract amounts from each other.
@@ -67,27 +61,27 @@ public function add(self $amount): self;
* $amount1->subtract($amount2) == 50
* $amount2->subtract($amount1) == -50
*/
- public function subtract(self $amount): self;
+ public function subtract(AmountInterface $amount): static;
/**
* Multiply amount by a specific amount.
*/
- public function multiply($multiplier): self;
+ public function multiply(/*int */$multiplier): static;
/**
* Divide the amount by a specific amount.
*/
- public function divide($divisor): self;
+ public function divide(/*int */$divisor): static;
- public function isEqualTo(self $amount): bool;
+ public function isEqualTo(AmountInterface $amount): bool;
- public function isGreaterThan(self $amount): bool;
+ public function isGreaterThan(AmountInterface $amount): bool;
- public function isGreaterThanOrEqualTo(self $amount): bool;
+ public function isGreaterThanOrEqualTo(AmountInterface $amount): bool;
- public function isLessThan(self $amount): bool;
+ public function isLessThan(AmountInterface $amount): bool;
- public function isLessThanOrEqualTo(self $amount): bool;
+ public function isLessThanOrEqualTo(AmountInterface $amount): bool;
public function isNegative(): bool;
diff --git a/src/SonsOfPHP/Contract/Money/Operator/Amount/AmountOperatorInterface.php b/src/SonsOfPHP/Contract/Money/AmountOperatorInterface.php
similarity index 76%
rename from src/SonsOfPHP/Contract/Money/Operator/Amount/AmountOperatorInterface.php
rename to src/SonsOfPHP/Contract/Money/AmountOperatorInterface.php
index be298f24..a1617d21 100644
--- a/src/SonsOfPHP/Contract/Money/Operator/Amount/AmountOperatorInterface.php
+++ b/src/SonsOfPHP/Contract/Money/AmountOperatorInterface.php
@@ -2,9 +2,8 @@
declare(strict_types=1);
-namespace SonsOfPHP\Contract\Money\Operator\Amount;
+namespace SonsOfPHP\Contract\Money;
-use SonsOfPHP\Contract\Money\AmountInterface;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
/**
diff --git a/src/SonsOfPHP/Contract/Money/Query/Amount/AmountQueryInterface.php b/src/SonsOfPHP/Contract/Money/AmountQueryInterface.php
similarity index 75%
rename from src/SonsOfPHP/Contract/Money/Query/Amount/AmountQueryInterface.php
rename to src/SonsOfPHP/Contract/Money/AmountQueryInterface.php
index ae4e8272..07a22221 100644
--- a/src/SonsOfPHP/Contract/Money/Query/Amount/AmountQueryInterface.php
+++ b/src/SonsOfPHP/Contract/Money/AmountQueryInterface.php
@@ -2,9 +2,8 @@
declare(strict_types=1);
-namespace SonsOfPHP\Contract\Money\Query\Amount;
+namespace SonsOfPHP\Contract\Money;
-use SonsOfPHP\Contract\Money\AmountInterface;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
/**
diff --git a/src/SonsOfPHP/Contract/Money/CurrencyInterface.php b/src/SonsOfPHP/Contract/Money/CurrencyInterface.php
index ff08b445..ca99d6d4 100644
--- a/src/SonsOfPHP/Contract/Money/CurrencyInterface.php
+++ b/src/SonsOfPHP/Contract/Money/CurrencyInterface.php
@@ -4,8 +4,6 @@
namespace SonsOfPHP\Contract\Money;
-use SonsOfPHP\Contract\Money\Query\Currency\CurrencyQueryInterface;
-
/**
* Currency Interface.
*
diff --git a/src/SonsOfPHP/Contract/Money/CurrencyProviderInterface.php b/src/SonsOfPHP/Contract/Money/CurrencyProviderInterface.php
index d3684399..1da619ba 100644
--- a/src/SonsOfPHP/Contract/Money/CurrencyProviderInterface.php
+++ b/src/SonsOfPHP/Contract/Money/CurrencyProviderInterface.php
@@ -5,7 +5,6 @@
namespace SonsOfPHP\Contract\Money;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface;
/**
* Currency Provider.
diff --git a/src/SonsOfPHP/Contract/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php b/src/SonsOfPHP/Contract/Money/CurrencyProviderQueryInterface.php
similarity index 73%
rename from src/SonsOfPHP/Contract/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php
rename to src/SonsOfPHP/Contract/Money/CurrencyProviderQueryInterface.php
index f13d949b..37925163 100644
--- a/src/SonsOfPHP/Contract/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php
+++ b/src/SonsOfPHP/Contract/Money/CurrencyProviderQueryInterface.php
@@ -2,9 +2,8 @@
declare(strict_types=1);
-namespace SonsOfPHP\Contract\Money\Query\CurrencyProvider;
+namespace SonsOfPHP\Contract\Money;
-use SonsOfPHP\Contract\Money\CurrencyProviderInterface;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
/**
diff --git a/src/SonsOfPHP/Contract/Money/Query/Currency/CurrencyQueryInterface.php b/src/SonsOfPHP/Contract/Money/CurrencyQueryInterface.php
similarity index 75%
rename from src/SonsOfPHP/Contract/Money/Query/Currency/CurrencyQueryInterface.php
rename to src/SonsOfPHP/Contract/Money/CurrencyQueryInterface.php
index bd253722..52dc9395 100644
--- a/src/SonsOfPHP/Contract/Money/Query/Currency/CurrencyQueryInterface.php
+++ b/src/SonsOfPHP/Contract/Money/CurrencyQueryInterface.php
@@ -2,9 +2,8 @@
declare(strict_types=1);
-namespace SonsOfPHP\Contract\Money\Query\Currency;
+namespace SonsOfPHP\Contract\Money;
-use SonsOfPHP\Contract\Money\CurrencyInterface;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
/**
diff --git a/src/SonsOfPHP/Contract/Money/MoneyInterface.php b/src/SonsOfPHP/Contract/Money/MoneyInterface.php
index 70f3ebfb..b8669e4e 100644
--- a/src/SonsOfPHP/Contract/Money/MoneyInterface.php
+++ b/src/SonsOfPHP/Contract/Money/MoneyInterface.php
@@ -4,9 +4,6 @@
namespace SonsOfPHP\Contract\Money;
-use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface;
-use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface;
-
/**
* Money Interface.
*
@@ -14,7 +11,7 @@
*
* @author Joshua Estes
*/
-interface MoneyInterface
+interface MoneyInterface // extends \JsonSerializable
{
public function getAmount(): AmountInterface;
diff --git a/src/SonsOfPHP/Contract/Money/Operator/Money/MoneyOperatorInterface.php b/src/SonsOfPHP/Contract/Money/MoneyOperatorInterface.php
similarity index 76%
rename from src/SonsOfPHP/Contract/Money/Operator/Money/MoneyOperatorInterface.php
rename to src/SonsOfPHP/Contract/Money/MoneyOperatorInterface.php
index df17d9d3..19cea13d 100644
--- a/src/SonsOfPHP/Contract/Money/Operator/Money/MoneyOperatorInterface.php
+++ b/src/SonsOfPHP/Contract/Money/MoneyOperatorInterface.php
@@ -2,10 +2,9 @@
declare(strict_types=1);
-namespace SonsOfPHP\Contract\Money\Operator\Money;
+namespace SonsOfPHP\Contract\Money;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\MoneyInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Contract/Money/Query/Money/MoneyQueryInterface.php b/src/SonsOfPHP/Contract/Money/MoneyQueryInterface.php
similarity index 76%
rename from src/SonsOfPHP/Contract/Money/Query/Money/MoneyQueryInterface.php
rename to src/SonsOfPHP/Contract/Money/MoneyQueryInterface.php
index b7a3cfaf..268e627b 100644
--- a/src/SonsOfPHP/Contract/Money/Query/Money/MoneyQueryInterface.php
+++ b/src/SonsOfPHP/Contract/Money/MoneyQueryInterface.php
@@ -2,10 +2,9 @@
declare(strict_types=1);
-namespace SonsOfPHP\Contract\Money\Query\Money;
+namespace SonsOfPHP\Contract\Money;
use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface;
-use SonsOfPHP\Contract\Money\MoneyInterface;
/**
* @author Joshua Estes
diff --git a/src/SonsOfPHP/Contract/Pager/PagerInterface.php b/src/SonsOfPHP/Contract/Pager/PagerInterface.php
index 3272a565..38e2f8df 100644
--- a/src/SonsOfPHP/Contract/Pager/PagerInterface.php
+++ b/src/SonsOfPHP/Contract/Pager/PagerInterface.php
@@ -20,12 +20,25 @@ interface PagerInterface extends \Countable, \IteratorAggregate, \JsonSerializab
*/
public function getCurrentPageResults(): iterable;
+ /**
+ * Returns the total number of results that the adapter can return
+ */
public function getTotalResults(): int;
+ /**
+ * Returns the total number of pages that exist based on the total results
+ * and the max results per page
+ */
public function getTotalPages(): int;
+ /**
+ * Returns true if there are 2 or more total pages
+ */
public function haveToPaginate(): bool;
+ /**
+ * If there is a previous page available, this will return true
+ */
public function hasPreviousPage(): bool;
/**
@@ -33,6 +46,9 @@ public function hasPreviousPage(): bool;
*/
public function getPreviousPage(): ?int;
+ /**
+ * If there is a next page available, this will return true
+ */
public function hasNextPage(): bool;
/**
diff --git a/tools/infection/composer.json b/tools/infection/composer.json
new file mode 100644
index 00000000..52c4ca17
--- /dev/null
+++ b/tools/infection/composer.json
@@ -0,0 +1,10 @@
+{
+ "require": {
+ "infection/infection": "^0.27.8"
+ },
+ "config": {
+ "allow-plugins": {
+ "infection/extension-installer": true
+ }
+ }
+}