From 9556a3f18fd29fea050ed26cc2e6dfc5c0eea404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schadegg=20Br=C3=B8nniche?= Date: Wed, 20 Aug 2025 10:21:39 +0200 Subject: [PATCH 1/8] =?UTF-8?q?=E2=9E=95=20Add=20PSR=20logger=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add PSR logger as a dependency. This allows the application to utilize a standard logging interface, improving interoperability with other logging libraries and frameworks. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7a288f6..12aa6fb 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ ], "require": { "php": "^8.1", - "illuminate/support": "^10.0|^11.0|^12.0" + "illuminate/support": "^10.0|^11.0|^12.0", + "psr/log": "^3.0.2" }, "require-dev": { "laravel/pint": "^1.0", From 4dd9941247c0b67c7ef73548571952bc11423f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schadegg=20Br=C3=B8nniche?= Date: Wed, 20 Aug 2025 10:33:36 +0200 Subject: [PATCH 2/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Fixes=20exception=20me?= =?UTF-8?q?ssage=20in=20ResourceToPrimaryKey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates the exception message to reflect the correct attribute name. The previous message incorrectly referred to 'ResourceToArray' instead of 'ResourceToPrimaryKey', leading to potential confusion when debugging. --- .../Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Attributes/Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php b/src/Attributes/Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php index 6fd8f9c..f74ebc9 100644 --- a/src/Attributes/Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php +++ b/src/Attributes/Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php @@ -13,7 +13,7 @@ public function __construct() {} public function format($value): mixed { if (! is_a($value, Resource::class)) { - throw new \InvalidArgumentException('ResourceToArray can only be used on properties of type Resource'); + throw new \InvalidArgumentException('ResourceToPrimaryKey can only be used on properties of type Resource'); } return $value->getPrimaryKey(); From 870abb62d28d1d95cb6c1be57f1562275e78bca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schadegg=20Br=C3=B8nniche?= Date: Wed, 20 Aug 2025 10:38:14 +0200 Subject: [PATCH 3/8] =?UTF-8?q?=E2=9C=A8=20Add=20float=20precision=20API?= =?UTF-8?q?=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds an attribute to format float values with a specific precision when interacting with the API. This ensures consistent and accurate data representation by rounding float values to the desired precision level. --- .../ApiFormatting/FloatPrecision.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php diff --git a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php new file mode 100644 index 0000000..e255243 --- /dev/null +++ b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php @@ -0,0 +1,23 @@ +precision); + } +} From d9570617a3fc2333ab14d60b031e0c90a1a234f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schadegg=20Br=C3=B8nniche?= Date: Wed, 20 Aug 2025 10:47:56 +0200 Subject: [PATCH 4/8] =?UTF-8?q?=E2=9C=A8=20Add=20float=20precision=20to=20?= =?UTF-8?q?discount=20percentage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensures the discount percentage is formatted with a precision of 2 when sent to the API. --- src/DTOs/Invoice/ProductLine.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DTOs/Invoice/ProductLine.php b/src/DTOs/Invoice/ProductLine.php index df32c86..d142f18 100644 --- a/src/DTOs/Invoice/ProductLine.php +++ b/src/DTOs/Invoice/ProductLine.php @@ -3,6 +3,7 @@ namespace Morningtrain\Economic\DTOs\Invoice; use Morningtrain\Economic\Abstracts\Resource; +use Morningtrain\Economic\Attributes\Resources\Properties\ApiFormatting\FloatPrecision; use Morningtrain\Economic\Attributes\Resources\Properties\ApiFormatting\ResourceToArray; use Morningtrain\Economic\Resources\DepartmentalDistribution; use Morningtrain\Economic\Resources\Product; @@ -16,6 +17,7 @@ class ProductLine extends Resource public ?string $description; + #[FloatPrecision(2)] public ?float $discountPercentage; public ?float $marginInBaseCurrency; From 2621599a459cdfa9832502f7a3ee48d57a17af19 Mon Sep 17 00:00:00 2001 From: mschadegg <11231039+mschadegg@users.noreply.github.com> Date: Wed, 20 Aug 2025 09:11:16 +0000 Subject: [PATCH 5/8] Fix styling --- .../Resources/Properties/ApiFormatting/FloatPrecision.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php index e255243..03f8bf7 100644 --- a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php +++ b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php @@ -9,12 +9,11 @@ { public function __construct( protected int $precision - ) { - } + ) {} public function format($value): float { - if(!is_numeric($value)) { + if (! is_numeric($value)) { return $value; } From 898c8b0cc16cb6485bfb258ae2b43874ba181e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schadegg=20Br=C3=B8nniche?= Date: Wed, 20 Aug 2025 11:14:41 +0200 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=94=80=20Update=20src/Attributes/Reso?= =?UTF-8?q?urces/Properties/ApiFormatting/FloatPrecision.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Resources/Properties/ApiFormatting/FloatPrecision.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php index 03f8bf7..fc47f4e 100644 --- a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php +++ b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php @@ -11,7 +11,7 @@ public function __construct( protected int $precision ) {} - public function format($value): float + public function format($value): mixed { if (! is_numeric($value)) { return $value; From 4facb2940b7e2989cfe38bc8dc132d3520425882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schadegg=20Br=C3=B8nniche?= Date: Wed, 20 Aug 2025 11:16:51 +0200 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=94=80=20Update=20src/Attributes/Reso?= =?UTF-8?q?urces/Properties/ApiFormatting/FloatPrecision.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Resources/Properties/ApiFormatting/FloatPrecision.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php index fc47f4e..efdfcde 100644 --- a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php +++ b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php @@ -6,7 +6,8 @@ use Morningtrain\Economic\Interfaces\ApiFormatter; #[Attribute(Attribute::TARGET_PROPERTY)] class FloatPrecision implements ApiFormatter -{ +#[Attribute(Attribute::TARGET_PROPERTY)] +class FloatPrecision implements ApiFormatter public function __construct( protected int $precision ) {} From 10ef6df6312183591cf9e3abcece7cdb19d359e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schadegg=20Br=C3=B8nniche?= Date: Wed, 20 Aug 2025 11:26:03 +0200 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=90=9B=20Fix=20missing=20curly=20brac?= =?UTF-8?q?e=20introduced=20after=20copilot=20codereview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a missing curly brace to the `FloatPrecision` class. This resolves a syntax error and ensures the class functions as intended. --- .../Resources/Properties/ApiFormatting/FloatPrecision.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php index efdfcde..eb845e8 100644 --- a/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php +++ b/src/Attributes/Resources/Properties/ApiFormatting/FloatPrecision.php @@ -5,9 +5,9 @@ use Attribute; use Morningtrain\Economic\Interfaces\ApiFormatter; -#[Attribute(Attribute::TARGET_PROPERTY)] class FloatPrecision implements ApiFormatter #[Attribute(Attribute::TARGET_PROPERTY)] class FloatPrecision implements ApiFormatter +{ public function __construct( protected int $precision ) {}