src/Connector/PowerOffice/Model/Factory/PowerOfficeFactory.php line 37

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2022 TECLA Consulting Group oü.
  5.  * All rights reserved.
  6.  *
  7.  * This unpublished material is proprietary to TECLA Consulting Group oü.
  8.  * All rights reserved. The methods and
  9.  * techniques described herein are considered trade secrets
  10.  * and/or confidential. Reproduction or distribution, in whole
  11.  * or in part, is forbidden except by express written permission
  12.  * of TECLA Consulting Group oü.
  13.  *
  14.  * @author    Matúš Sýkorjak <matus@tecla.no>
  15.  * @copyright 2022 TECLA Consulting Group oü
  16.  */
  17. namespace App\Connector\PowerOffice\Model\Factory;
  18. use App\Connector\PowerOffice\Dto\PowerOfficeDto;
  19. use App\Connector\PowerOffice\Model\Identity\PowerOfficeId;
  20. use App\Connector\PowerOffice\Model\PowerOffice;
  21. use App\Connector\PowerOffice\Model\PowerOfficeInterface;
  22. use App\Contact\Model\ContactInterface;
  23. use App\Contact\Repository\ContactRepositoryInterface;
  24. final class PowerOfficeFactory implements PowerOfficeFactoryInterface
  25. {
  26.     private ContactRepositoryInterface $contactRepository;
  27.     public function __construct(ContactRepositoryInterface $contactRepository)
  28.     {
  29.         $this->contactRepository $contactRepository;
  30.     }
  31.     public function create(
  32.         ContactInterface $contact,
  33.         string $apiClientKey null,
  34.         ?int $pullInvoicesFromNumber null,
  35.         ?string $accessToken null,
  36.         ?\DateTimeImmutable $accessTokenExpiresAt null,
  37.         ?string $refreshToken null
  38.     ): PowerOfficeInterface {
  39.         return new PowerOffice(
  40.             PowerOfficeId::create(),
  41.             $contact,
  42.             $apiClientKey,
  43.             $pullInvoicesFromNumber,
  44.             $accessToken,
  45.             $accessTokenExpiresAt,
  46.             $refreshToken
  47.         );
  48.     }
  49.     public function createFromDto(PowerOfficeDto $dto): PowerOfficeInterface
  50.     {
  51.         return $this->create(
  52.             $this->contactRepository->find($dto->getContact()),
  53.             $dto->getApiClientKey(),
  54.             $dto->getPullInvoicesFromNumber(),
  55.             $dto->getAccessToken(),
  56.             $dto->getAccessTokenExpiresAt(),
  57.             $dto->getRefreshToken()
  58.         );
  59.     }
  60. }