From 1758065e30e7198abeaf939a2c476bb0a039d5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8nsson?= Date: Tue, 27 Aug 2024 15:42:51 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Allow=20string=20as=20produc?= =?UTF-8?q?t=20for=20ProductLine::new?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DTOs/Invoice/ProductLine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DTOs/Invoice/ProductLine.php b/src/DTOs/Invoice/ProductLine.php index 44649f6..df32c86 100644 --- a/src/DTOs/Invoice/ProductLine.php +++ b/src/DTOs/Invoice/ProductLine.php @@ -37,7 +37,7 @@ class ProductLine extends Resource public ?float $unitNetPrice; public static function new( - Product|int $product, + Product|int|string $product, float $quantity, float $unitNetPrice, ?string $description = null, From 01efa966bfad78a23cebeb80990b2cd38b6b2f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8nsson?= Date: Tue, 27 Aug 2024 15:43:06 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20Add=20test=20for=20setting=20pr?= =?UTF-8?q?oduct=20from=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Unit/ProductLineTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/Unit/ProductLineTest.php diff --git a/tests/Unit/ProductLineTest.php b/tests/Unit/ProductLineTest.php new file mode 100644 index 0000000..e7ae3fc --- /dev/null +++ b/tests/Unit/ProductLineTest.php @@ -0,0 +1,20 @@ +product) + ->toBeInstanceOf(Product::class) + ->productNumber->toBe('test'); +}); From 068a2f62fb091616d9dcf1d98f6f84a589c3f1e6 Mon Sep 17 00:00:00 2001 From: SimonJnsson Date: Tue, 27 Aug 2024 13:43:30 +0000 Subject: [PATCH 3/3] Fix styling --- src/Abstracts/Endpoint.php | 4 +--- src/Abstracts/Resource.php | 2 +- src/Attributes/Resources/Create.php | 4 +--- src/Attributes/Resources/Delete.php | 4 +--- src/Attributes/Resources/GetCollection.php | 4 +--- src/Attributes/Resources/GetSingle.php | 4 +--- .../Properties/ApiFormatting/ResourceToPrimaryKey.php | 4 +--- src/Attributes/Resources/Properties/Filterable.php | 4 +--- src/Attributes/Resources/Properties/PrimaryKey.php | 4 +--- src/Attributes/Resources/Properties/Required.php | 4 +--- src/Attributes/Resources/Properties/ResourceType.php | 4 +--- src/Attributes/Resources/Properties/Sortable.php | 4 +--- src/Attributes/Resources/Update.php | 4 +--- src/Classes/EconomicCollectionIterator.php | 4 +--- src/Classes/EconomicQueryBuilder.php | 4 +--- src/Classes/EconomicQueryFilterBuilder.php | 4 +--- src/Classes/EconomicRelatedResource.php | 4 +--- src/Resources/AccountingYear/Voucher.php | 4 +--- src/Resources/Customer/Total.php | 4 +--- src/Resources/Department.php | 4 +--- src/Traits/Resources/HasLines.php | 2 +- tests/Unit/ProductLineTest.php | 4 ---- 22 files changed, 21 insertions(+), 63 deletions(-) diff --git a/src/Abstracts/Endpoint.php b/src/Abstracts/Endpoint.php index acf9b1b..41f9ca0 100644 --- a/src/Abstracts/Endpoint.php +++ b/src/Abstracts/Endpoint.php @@ -4,9 +4,7 @@ abstract class Endpoint { - public function __construct(protected string $endpoint, protected ?array $references = null) - { - } + public function __construct(protected string $endpoint, protected ?array $references = null) {} public function getEndpoint(...$references): string { diff --git a/src/Abstracts/Resource.php b/src/Abstracts/Resource.php index 83be121..0622381 100644 --- a/src/Abstracts/Resource.php +++ b/src/Abstracts/Resource.php @@ -75,7 +75,7 @@ protected static function resolvePropertyValue(string $property, mixed $value): if (! empty($attribute[0]) && ! empty($value) && is_array($value)) { $resourceType = $attribute[0]->newInstance(); - $collection = new Collection(); + $collection = new Collection; foreach ($value as $item) { $collection->add(new ($resourceType->getTypeClass())($item)); diff --git a/src/Attributes/Resources/Create.php b/src/Attributes/Resources/Create.php index 37012dd..e215a06 100644 --- a/src/Attributes/Resources/Create.php +++ b/src/Attributes/Resources/Create.php @@ -7,7 +7,5 @@ #[Attribute(Attribute::TARGET_CLASS)] class Create extends Endpoint { - public function __construct(protected string $endpoint) - { - } + public function __construct(protected string $endpoint) {} } diff --git a/src/Attributes/Resources/Delete.php b/src/Attributes/Resources/Delete.php index 4cc30d2..52846fa 100644 --- a/src/Attributes/Resources/Delete.php +++ b/src/Attributes/Resources/Delete.php @@ -5,6 +5,4 @@ use Attribute; use Morningtrain\Economic\Abstracts\Endpoint; -#[Attribute(Attribute::TARGET_CLASS)] class Delete extends Endpoint -{ -} +#[Attribute(Attribute::TARGET_CLASS)] class Delete extends Endpoint {} diff --git a/src/Attributes/Resources/GetCollection.php b/src/Attributes/Resources/GetCollection.php index eaa51e8..e52f25b 100644 --- a/src/Attributes/Resources/GetCollection.php +++ b/src/Attributes/Resources/GetCollection.php @@ -7,7 +7,5 @@ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] class GetCollection extends Endpoint { - public function __construct(protected string $endpoint) - { - } + public function __construct(protected string $endpoint) {} } diff --git a/src/Attributes/Resources/GetSingle.php b/src/Attributes/Resources/GetSingle.php index ae4e03b..612b9c0 100644 --- a/src/Attributes/Resources/GetSingle.php +++ b/src/Attributes/Resources/GetSingle.php @@ -7,7 +7,5 @@ #[Attribute(Attribute::TARGET_CLASS)] class GetSingle extends Endpoint { - public function __construct(protected string $endpoint) - { - } + public function __construct(protected string $endpoint) {} } diff --git a/src/Attributes/Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php b/src/Attributes/Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php index 21beda0..6fd8f9c 100644 --- a/src/Attributes/Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php +++ b/src/Attributes/Resources/Properties/ApiFormatting/ResourceToPrimaryKey.php @@ -8,9 +8,7 @@ #[Attribute(Attribute::TARGET_PROPERTY)] class ResourceToPrimaryKey implements ApiFormatter { - public function __construct() - { - } + public function __construct() {} public function format($value): mixed { diff --git a/src/Attributes/Resources/Properties/Filterable.php b/src/Attributes/Resources/Properties/Filterable.php index a8a86c0..b558970 100644 --- a/src/Attributes/Resources/Properties/Filterable.php +++ b/src/Attributes/Resources/Properties/Filterable.php @@ -4,6 +4,4 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] class Filterable -{ -} +#[Attribute(Attribute::TARGET_PROPERTY)] class Filterable {} diff --git a/src/Attributes/Resources/Properties/PrimaryKey.php b/src/Attributes/Resources/Properties/PrimaryKey.php index 41ad8c2..a25e8b0 100644 --- a/src/Attributes/Resources/Properties/PrimaryKey.php +++ b/src/Attributes/Resources/Properties/PrimaryKey.php @@ -4,6 +4,4 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] class PrimaryKey -{ -} +#[Attribute(Attribute::TARGET_PROPERTY)] class PrimaryKey {} diff --git a/src/Attributes/Resources/Properties/Required.php b/src/Attributes/Resources/Properties/Required.php index b8dee4e..4f713b5 100644 --- a/src/Attributes/Resources/Properties/Required.php +++ b/src/Attributes/Resources/Properties/Required.php @@ -4,6 +4,4 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] class Required -{ -} +#[Attribute(Attribute::TARGET_PROPERTY)] class Required {} diff --git a/src/Attributes/Resources/Properties/ResourceType.php b/src/Attributes/Resources/Properties/ResourceType.php index 8409567..a267241 100644 --- a/src/Attributes/Resources/Properties/ResourceType.php +++ b/src/Attributes/Resources/Properties/ResourceType.php @@ -7,9 +7,7 @@ #[Attribute(Attribute::TARGET_PROPERTY)] class ResourceType { - public function __construct(public string $typeClass) - { - } + public function __construct(public string $typeClass) {} public function getTypeClass(): string { diff --git a/src/Attributes/Resources/Properties/Sortable.php b/src/Attributes/Resources/Properties/Sortable.php index ba80a5b..7976607 100644 --- a/src/Attributes/Resources/Properties/Sortable.php +++ b/src/Attributes/Resources/Properties/Sortable.php @@ -4,6 +4,4 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] class Sortable -{ -} +#[Attribute(Attribute::TARGET_PROPERTY)] class Sortable {} diff --git a/src/Attributes/Resources/Update.php b/src/Attributes/Resources/Update.php index 0a1716a..8dc6107 100644 --- a/src/Attributes/Resources/Update.php +++ b/src/Attributes/Resources/Update.php @@ -5,6 +5,4 @@ use Attribute; use Morningtrain\Economic\Abstracts\Endpoint; -#[Attribute(Attribute::TARGET_CLASS)] class Update extends Endpoint -{ -} +#[Attribute(Attribute::TARGET_CLASS)] class Update extends Endpoint {} diff --git a/src/Classes/EconomicCollectionIterator.php b/src/Classes/EconomicCollectionIterator.php index 6c958df..6049073 100644 --- a/src/Classes/EconomicCollectionIterator.php +++ b/src/Classes/EconomicCollectionIterator.php @@ -18,9 +18,7 @@ class EconomicCollectionIterator implements ArrayAccess, Countable, SeekableIter protected int $currentPosition = 0; - public function __construct(protected string $self, protected string $resourceClass) - { - } + public function __construct(protected string $self, protected string $resourceClass) {} protected function getItem(int $position): ?Resource { diff --git a/src/Classes/EconomicQueryBuilder.php b/src/Classes/EconomicQueryBuilder.php index 3edf64c..c6052a3 100644 --- a/src/Classes/EconomicQueryBuilder.php +++ b/src/Classes/EconomicQueryBuilder.php @@ -18,9 +18,7 @@ class EconomicQueryBuilder protected string|Endpoint $endpoint; - public function __construct(protected string $resourceClass) - { - } + public function __construct(protected string $resourceClass) {} public function setEndpoint(string|Endpoint $endpoint): static { diff --git a/src/Classes/EconomicQueryFilterBuilder.php b/src/Classes/EconomicQueryFilterBuilder.php index 2f3f5a1..4f1eeed 100644 --- a/src/Classes/EconomicQueryFilterBuilder.php +++ b/src/Classes/EconomicQueryFilterBuilder.php @@ -42,9 +42,7 @@ class EconomicQueryFilterBuilder protected array $filters = []; - public function __construct(protected string $relation) - { - } + public function __construct(protected string $relation) {} protected function convertOperator(string $operator): string { diff --git a/src/Classes/EconomicRelatedResource.php b/src/Classes/EconomicRelatedResource.php index 43f227e..1a4c755 100644 --- a/src/Classes/EconomicRelatedResource.php +++ b/src/Classes/EconomicRelatedResource.php @@ -12,9 +12,7 @@ */ class EconomicRelatedResource { - public function __construct(protected Endpoint $endpointCollection, protected Endpoint $endpointSingle, protected string $resourceClass, protected array $references) - { - } + public function __construct(protected Endpoint $endpointCollection, protected Endpoint $endpointSingle, protected string $resourceClass, protected array $references) {} /** * @return R|null diff --git a/src/Resources/AccountingYear/Voucher.php b/src/Resources/AccountingYear/Voucher.php index 3a2acba..b0c9a39 100644 --- a/src/Resources/AccountingYear/Voucher.php +++ b/src/Resources/AccountingYear/Voucher.php @@ -4,6 +4,4 @@ use Morningtrain\Economic\Abstracts\Resource; -class Voucher extends Resource -{ -} +class Voucher extends Resource {} diff --git a/src/Resources/Customer/Total.php b/src/Resources/Customer/Total.php index cede639..2534042 100644 --- a/src/Resources/Customer/Total.php +++ b/src/Resources/Customer/Total.php @@ -4,6 +4,4 @@ use Morningtrain\Economic\Abstracts\Resource; -class Total extends Resource -{ -} +class Total extends Resource {} diff --git a/src/Resources/Department.php b/src/Resources/Department.php index 9a22ef5..981ee04 100644 --- a/src/Resources/Department.php +++ b/src/Resources/Department.php @@ -6,6 +6,4 @@ use Morningtrain\Economic\Attributes\Resources\GetCollection; #[GetCollection()] -class Department extends Resource -{ -} +class Department extends Resource {} diff --git a/src/Traits/Resources/HasLines.php b/src/Traits/Resources/HasLines.php index 34e480e..3bd5d38 100644 --- a/src/Traits/Resources/HasLines.php +++ b/src/Traits/Resources/HasLines.php @@ -17,7 +17,7 @@ trait HasLines public function addLine(ProductLine $line): static { if (is_null($this->lines)) { - $this->lines = new Collection(); + $this->lines = new Collection; } $this->lines->add($line); diff --git a/tests/Unit/ProductLineTest.php b/tests/Unit/ProductLineTest.php index e7ae3fc..4764d58 100644 --- a/tests/Unit/ProductLineTest.php +++ b/tests/Unit/ProductLineTest.php @@ -1,11 +1,7 @@