Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| GroupOlxTransactionType | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
13 | |
100.00% |
1 / 1 |
| label | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
| usesListPrice | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| usesRentalPrice | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| tryFromPurpose | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Publishing\Connectors\GroupOlx\Domain\Enums; |
| 6 | |
| 7 | /** |
| 8 | * TransactionType oficial VRSync (Grupo OLX). |
| 9 | * |
| 10 | * @see https://developers.grupozap.com/feeds/vrsync/elements/listing.html |
| 11 | */ |
| 12 | enum GroupOlxTransactionType: string |
| 13 | { |
| 14 | case ForSale = 'For Sale'; |
| 15 | case ForRent = 'For Rent'; |
| 16 | case SaleRent = 'Sale/Rent'; |
| 17 | |
| 18 | public function label(): string |
| 19 | { |
| 20 | return match ($this) { |
| 21 | self::ForSale => 'Venda', |
| 22 | self::ForRent => 'Aluguel', |
| 23 | self::SaleRent => 'Venda e Aluguel', |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | public function usesListPrice(): bool |
| 28 | { |
| 29 | return $this === self::ForSale || $this === self::SaleRent; |
| 30 | } |
| 31 | |
| 32 | public function usesRentalPrice(): bool |
| 33 | { |
| 34 | return $this === self::ForRent || $this === self::SaleRent; |
| 35 | } |
| 36 | |
| 37 | public static function tryFromPurpose(string $purpose): ?self |
| 38 | { |
| 39 | $normalized = mb_strtolower(trim($purpose)); |
| 40 | |
| 41 | return match ($normalized) { |
| 42 | 'venda', 'for sale', 'sale' => self::ForSale, |
| 43 | 'aluguel', 'for rent', 'rent', 'locação', 'locacao' => self::ForRent, |
| 44 | 'venda e aluguel', 'sale/rent', 'sale / rent' => self::SaleRent, |
| 45 | default => self::tryFrom(trim($purpose)), |
| 46 | }; |
| 47 | } |
| 48 | } |