Skip to content

Commit

Permalink
🔀 Merge pull request #33 from Morning-Train/feature/allow-string-as-p…
Browse files Browse the repository at this point in the history
…roduct

Allow parsing productNumber as string when creating ProductLine with ::new function
  • Loading branch information
mschadegg authored Aug 28, 2024
2 parents 362845f + 068a2f6 commit 4e98d73
Show file tree
Hide file tree
Showing 23 changed files with 38 additions and 60 deletions.
4 changes: 1 addition & 3 deletions src/Abstracts/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Abstracts/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 1 addition & 3 deletions src/Attributes/Resources/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@

#[Attribute(Attribute::TARGET_CLASS)] class Create extends Endpoint
{
public function __construct(protected string $endpoint)
{
}
public function __construct(protected string $endpoint) {}
}
4 changes: 1 addition & 3 deletions src/Attributes/Resources/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
4 changes: 1 addition & 3 deletions src/Attributes/Resources/GetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
4 changes: 1 addition & 3 deletions src/Attributes/Resources/GetSingle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@

#[Attribute(Attribute::TARGET_CLASS)] class GetSingle extends Endpoint
{
public function __construct(protected string $endpoint)
{
}
public function __construct(protected string $endpoint) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

#[Attribute(Attribute::TARGET_PROPERTY)] class ResourceToPrimaryKey implements ApiFormatter
{
public function __construct()
{
}
public function __construct() {}

public function format($value): mixed
{
Expand Down
4 changes: 1 addition & 3 deletions src/Attributes/Resources/Properties/Filterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)] class Filterable
{
}
#[Attribute(Attribute::TARGET_PROPERTY)] class Filterable {}
4 changes: 1 addition & 3 deletions src/Attributes/Resources/Properties/PrimaryKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)] class PrimaryKey
{
}
#[Attribute(Attribute::TARGET_PROPERTY)] class PrimaryKey {}
4 changes: 1 addition & 3 deletions src/Attributes/Resources/Properties/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)] class Required
{
}
#[Attribute(Attribute::TARGET_PROPERTY)] class Required {}
4 changes: 1 addition & 3 deletions src/Attributes/Resources/Properties/ResourceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 1 addition & 3 deletions src/Attributes/Resources/Properties/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)] class Sortable
{
}
#[Attribute(Attribute::TARGET_PROPERTY)] class Sortable {}
4 changes: 1 addition & 3 deletions src/Attributes/Resources/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
4 changes: 1 addition & 3 deletions src/Classes/EconomicCollectionIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 1 addition & 3 deletions src/Classes/EconomicQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 1 addition & 3 deletions src/Classes/EconomicQueryFilterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 1 addition & 3 deletions src/Classes/EconomicRelatedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/DTOs/Invoice/ProductLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions src/Resources/AccountingYear/Voucher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Morningtrain\Economic\Abstracts\Resource;

class Voucher extends Resource
{
}
class Voucher extends Resource {}
4 changes: 1 addition & 3 deletions src/Resources/Customer/Total.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Morningtrain\Economic\Abstracts\Resource;

class Total extends Resource
{
}
class Total extends Resource {}
4 changes: 1 addition & 3 deletions src/Resources/Department.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
use Morningtrain\Economic\Attributes\Resources\GetCollection;

#[GetCollection()]
class Department extends Resource
{
}
class Department extends Resource {}
2 changes: 1 addition & 1 deletion src/Traits/Resources/HasLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/ProductLineTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Morningtrain\Economic\DTOs\Invoice\ProductLine;
use Morningtrain\Economic\Resources\Product;

it('allows setting product from string', function () {
$productLine = ProductLine::new(
product: 'test',
quantity: 1,
unitNetPrice: 100,
);

expect($productLine->product)
->toBeInstanceOf(Product::class)
->productNumber->toBe('test');
});

0 comments on commit 4e98d73

Please sign in to comment.