Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #15

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,17 @@ function implode_non_empty(string $separator, array $parts): ?string

return implode($separator, $filtered) ?: null;
}

/**
* @param non-empty-list<array-key> $lookup
*/
function any_key_exists(array $lookup, array $haystack): bool
{
foreach ($lookup as $item) {
if (array_key_exists($item, $haystack)) {
return true;
}
}

return false;
}
13 changes: 9 additions & 4 deletions src/Command/DummyCommand.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
/** @noinspection PhpPropertyOnlyWrittenInspection */

declare(strict_types=1);

namespace App\Command;

use LogicException;
use App\Service\Zoho\ZohoManager;
use CuyZ\Valinor\Mapper\TreeMapper;
use App\Service\ZohoImprovedManager;
use App\Repository\Company\CompanyRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Attribute\AsCommand;
Expand All @@ -22,7 +24,9 @@
class DummyCommand extends Command
{
public function __construct(
private ZohoManager $zohoSync,
// #[SupportDateFormats('Y-m-d', 'Y-m-d H:i'), AllowSuperfluousKeys]
private TreeMapper $treeMapper,
private ZohoImprovedManager $zohoImprovedManager,
private CompanyRepository $companyRepository,
)
{
Expand All @@ -32,7 +36,8 @@ public function __construct(
protected function execute(InputInterface $input, OutputInterface $output): int
{
$company = $this->companyRepository->findOneBy(['name' => 'Strictify']) ?? throw new LogicException();
$this->zohoSync->downloadAll($company);

$this->zohoImprovedManager->downloadAll($company);

return Command::SUCCESS;
}
Expand Down
25 changes: 19 additions & 6 deletions src/DTO/Zoho/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@

namespace App\DTO\Zoho;

use Override;
use function is_string;

class Item
class Item implements ZohoSingleResultInterface
{
/**
* @param non-empty-string|int $itemId
*/
public function __construct(
private string $itemId,
private string|int $itemId,
private string $name,
private ?string $description,
private ?float $rate,
private ?string $taxId,
private string|int|null $taxId,
)
{
}

public function getItemId(): string
/**
* @return non-empty-string|int
*/
public function getItemId(): string|int
{
return $this->itemId;
}
Expand All @@ -39,9 +46,9 @@ public function getRate(): ?float
}

/**
* @return non-empty-string|null
* @return non-empty-string|int|null
*/
public function getTaxId(): ?string
public function getTaxId(): string|int|null
{
$taxId = $this->taxId;
if (is_string($taxId) && $taxId !== '') {
Expand All @@ -50,4 +57,10 @@ public function getTaxId(): ?string

return null;
}

#[Override]
public function getId(): string
{
return (string)$this->getItemId();
}
}
20 changes: 18 additions & 2 deletions src/DTO/Zoho/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@

namespace App\DTO\Zoho;

class Items
use LogicException;

/**
* @implements ZohoMappingInterface<Item>
*/
class Items implements ZohoMappingInterface
{
/**
* @param list<Item> $items
*/
public function __construct(
public int $code,
public string $message,
public array $items,
public ?Item $item = null,
public array $items = [],
)
{
}

public function getOne(): object
{
return $this->item ?? throw new LogicException();
}

public function getMany(): array
{
return $this->items;
}
}
20 changes: 17 additions & 3 deletions src/DTO/Zoho/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@

namespace App\DTO\Zoho;

class Tax
use Override;

class Tax implements ZohoSingleResultInterface
{
/**
* @param non-empty-string|int $taxId
*/
public function __construct(
private string $taxId,
private string|int $taxId,
private string $taxName,
private float $taxPercentage,
)
{
}

public function getTaxId(): string
/**
* @return non-empty-string|int
*/
public function getTaxId(): string|int
{
return $this->taxId;
}
Expand All @@ -28,4 +36,10 @@ public function getTaxPercentage(): float
{
return $this->taxPercentage;
}

#[Override]
public function getId(): string
{
return (string)$this->getTaxId();
}
}
20 changes: 18 additions & 2 deletions src/DTO/Zoho/Taxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@

namespace App\DTO\Zoho;

class Taxes
use LogicException;

/**
* @implements ZohoMappingInterface<Tax>
*/
class Taxes implements ZohoMappingInterface
{
/**
* @param list<Tax> $taxes
*/
public function __construct(
public int $code,
public string $message,
public array $taxes,
private array $taxes,
private ?Tax $tax = null,
)
{
}

public function getOne(): object
{
return $this->tax ?? throw new LogicException();
}

public function getMany(): array
{
return $this->taxes;
}
}
17 changes: 14 additions & 3 deletions src/DTO/Zoho/Warehouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,33 @@

namespace App\DTO\Zoho;

class Warehouse
class Warehouse implements ZohoSingleResultInterface
{
/**
* @param non-empty-string|int $warehouseId
*/
public function __construct(
private string $warehouseId,
private string|int $warehouseId,
private string $warehouseName,
)
{
}

/**
* @return non-empty-string
*/
public function getWarehouseId(): string
{
return $this->warehouseId;
return (string)$this->warehouseId;
}

public function getName(): string
{
return $this->warehouseName;
}

public function getId(): string
{
return (string)$this->warehouseId;
}
}
20 changes: 18 additions & 2 deletions src/DTO/Zoho/Warehouses.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@

namespace App\DTO\Zoho;

class Warehouses
use LogicException;

/**
* @implements ZohoMappingInterface<Warehouse>
*/
class Warehouses implements ZohoMappingInterface
{
/**
* @param list<Warehouse> $warehouses
*/
public function __construct(
public int $code,
public string $message,
public array $warehouses,
private ?Warehouse $warehouse = null,
public array $warehouses = [],
)
{
}

public function getOne(): object
{
return $this->warehouse ?? throw new LogicException();
}

public function getMany(): array
{
return $this->warehouses;
}
}
21 changes: 21 additions & 0 deletions src/DTO/Zoho/ZohoMappingInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\DTO\Zoho;

/**
* @template T of ZohoSingleResultInterface
*/
interface ZohoMappingInterface
{
/**
* @return T
*/
public function getOne(): object;

/**
* @return list<T>
*/
public function getMany(): array;
}
13 changes: 13 additions & 0 deletions src/DTO/Zoho/ZohoSingleResultInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\DTO\Zoho;

interface ZohoSingleResultInterface
{
/**
* @return non-empty-string
*/
public function getId(): string;
}
3 changes: 3 additions & 0 deletions src/Entity/IdTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ trait IdTrait
{
protected ?UuidInterface $id = null;

/**
* @return non-empty-string
*/
public function getId(): string
{
$id = $this->id ??= $this->doCreateUuid();
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/Product/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public function setDescription(?string $description): void
}

#[Override]
/**
* @return non-empty-string|null
*/
public function getZohoId(): ?string
{
$zohoId = $this->zohoId;
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/ZohoAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@

namespace App\Entity;

use App\Entity\Company\Company;

interface ZohoAwareInterface
{
public function getCompany(): Company;

/**
* @return non-empty-string|null
*/
public function getZohoId(): ?string;

/**
* @return non-empty-string
*/
public function getId(): string;
}
Loading
Loading