src/BusinessFeature/Yclients/Dto/LocationDto.php line 15

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slivki\BusinessFeature\Yclients\Dto;
  4. use JsonSerializable;
  5. use OpenApi\Annotations as OA;
  6. use Nelmio\ApiDocBundle\Annotation\Model;
  7. use Slivki\BusinessFeature\Yclients\HttpClient\Response\CompanyResponse;
  8. use function array_map;
  9. use function sprintf;
  10. final class LocationDto implements JsonSerializable
  11. {
  12.     /**
  13.      * @var array<PhoneNumberDto>
  14.      *
  15.      * @OA\Property(
  16.      *     property="phoneNumbers",
  17.      *     type="array",
  18.      *     @OA\Items(
  19.      *        ref=@Model(type=PhoneNumberDto::class)
  20.      *     )
  21.      * ),
  22.      */
  23.     private array $phoneNumbers;
  24.     /**
  25.      * @var string[]
  26.      *
  27.      * @OA\Property(
  28.      *     property="geoLocation",
  29.      *     type="array",
  30.      *     @OA\Items(
  31.      *      type="string",
  32.      *      description="Широта и долгота в виде массива [широта, долгота]"
  33.      *    ),
  34.      * )
  35.      */
  36.     private array $geoLocation;
  37.     /**
  38.      * @var string
  39.      *
  40.      * @OA\Property(
  41.      *     property="address",
  42.      *     type="string",
  43.      *     description="Адрес",
  44.      *     example="г. Минск, ул. Ленина, д. 1"
  45.      * )
  46.      */
  47.     private string $address;
  48.     /**
  49.      * @var string
  50.      *
  51.      * @OA\Property(
  52.      *     property="workingHours",
  53.      *     type="string",
  54.      *     description="Часы работы",
  55.      *     example="Пн-Пт: 9:00-18:00, Сб-Вс: выходной"
  56.      * )
  57.      */
  58.     private string $workingHours;
  59.     /**
  60.      * @var string
  61.      *
  62.      * @OA\Property(
  63.      *     property="description",
  64.      *     type="string",
  65.      *     description="Описание",
  66.      *     example="Описание филиала"
  67.      * )
  68.      */
  69.     private string $description;
  70.     public function __construct(
  71.         array $phoneNumbers,
  72.         array $geoLocation,
  73.         string $address,
  74.         string $workingHours,
  75.         string $description
  76.     ) {
  77.         $this->phoneNumbers $phoneNumbers;
  78.         $this->geoLocation $geoLocation;
  79.         $this->address $address;
  80.         $this->workingHours $workingHours;
  81.         $this->description $description;
  82.     }
  83.     public static function createFromCompany(CompanyResponse $companyResponse): LocationDto
  84.     {
  85.         return new self(
  86.             array_map(static fn (string $phone): PhoneNumberDto => new PhoneNumberDto(str_replace(['-'' '], ''$phone), ''), $companyResponse->getPhones()),
  87.             [sprintf('%f,%f'$companyResponse->getCoordinateLat(), $companyResponse->getCoordinateLon())],
  88.             sprintf('%s, %s'$companyResponse->getCity(), $companyResponse->getAddress()),
  89.             $companyResponse->getSchedule(),
  90.             $companyResponse->getShortDescr(),
  91.         );
  92.     }
  93.     public function getPhoneNumbers(): array
  94.     {
  95.         return $this->phoneNumbers;
  96.     }
  97.     public function getGeoLocation(): array
  98.     {
  99.         return $this->geoLocation;
  100.     }
  101.     public function getAddress(): string
  102.     {
  103.         return $this->address;
  104.     }
  105.     public function getWorkingHours(): string
  106.     {
  107.         return $this->workingHours;
  108.     }
  109.     public function getDescription(): string
  110.     {
  111.         return $this->description;
  112.     }
  113.     public function jsonSerialize(): array
  114.     {
  115.         return [
  116.             'phoneNumbers' => $this->phoneNumbers,
  117.             'geoLocation' => $this->geoLocation,
  118.             'address' => $this->address,
  119.             'workingHours' => $this->workingHours,
  120.             'description' => $this->description,
  121.         ];
  122.     }
  123. }