|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Spatie\Harvest\Resources; |
| 4 | + |
| 5 | +use Carbon\CarbonImmutable; |
| 6 | + |
| 7 | +class ProjectResource |
| 8 | +{ |
| 9 | + public function __construct( |
| 10 | + public int $id, |
| 11 | + public object $client, |
| 12 | + public string $name, |
| 13 | + public string $code, |
| 14 | + public bool $isActive, |
| 15 | + public bool $isBillable, |
| 16 | + public bool $isFixedFee, |
| 17 | + public string $billBy, |
| 18 | + public ?float $hourlyRate, |
| 19 | + public ?float $budget, |
| 20 | + public string $budgetBy, |
| 21 | + public bool $budgetIsMonthly, |
| 22 | + public bool $notifyWhenOverBudget, |
| 23 | + public ?float $overBudgetNotificationPercentage, |
| 24 | + public ?CarbonImmutable $overBudgetNotificationDate, |
| 25 | + public bool $showBudgetToAll, |
| 26 | + public ?float $costBudget, |
| 27 | + public bool $costBudgetIncludeExpenses, |
| 28 | + public ?float $fee, |
| 29 | + public ?string $notes, |
| 30 | + public ?CarbonImmutable $startsOn, |
| 31 | + public ?CarbonImmutable $endsOn, |
| 32 | + public CarbonImmutable $createdAt, |
| 33 | + public CarbonImmutable $updatedAt, |
| 34 | + ) {} |
| 35 | + |
| 36 | + /** @param array<string, mixed> $response */ |
| 37 | + public static function createFromResponse(array $response): self |
| 38 | + { |
| 39 | + return new self( |
| 40 | + id: $response['id'], |
| 41 | + client: (object) $response['client'], |
| 42 | + name: $response['name'], |
| 43 | + code: $response['code'], |
| 44 | + isActive: $response['is_active'], |
| 45 | + isBillable: $response['is_billable'], |
| 46 | + isFixedFee: $response['is_fixed_fee'], |
| 47 | + billBy: $response['bill_by'], |
| 48 | + hourlyRate: $response['hourly_rate'] ?? null, |
| 49 | + budget: $response['budget'] ?? null, |
| 50 | + budgetBy: $response['budget_by'], |
| 51 | + budgetIsMonthly: $response['budget_is_monthly'], |
| 52 | + notifyWhenOverBudget: $response['notify_when_over_budget'], |
| 53 | + overBudgetNotificationPercentage: $response['over_budget_notification_percentage'] ?? null, |
| 54 | + overBudgetNotificationDate: isset($response['over_budget_notification_date']) ? CarbonImmutable::parse($response['over_budget_notification_date']) : null, |
| 55 | + showBudgetToAll: $response['show_budget_to_all'], |
| 56 | + costBudget: $response['cost_budget'] ?? null, |
| 57 | + costBudgetIncludeExpenses: $response['cost_budget_include_expenses'], |
| 58 | + fee: $response['fee'] ?? null, |
| 59 | + notes: !empty($response['notes']) ? $response['notes'] : null, |
| 60 | + startsOn: isset($response['starts_on']) ? CarbonImmutable::parse($response['starts_on']) : null, |
| 61 | + endsOn: isset($response['ends_on']) ? CarbonImmutable::parse($response['ends_on']) : null, |
| 62 | + createdAt: CarbonImmutable::parse($response['created_at']), |
| 63 | + updatedAt: CarbonImmutable::parse($response['updated_at']), |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
0 commit comments