Files
hr/app/DTOs/Import/BonusRowDto.php
2026-07-30 17:24:40 +05:00

40 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\DTOs\Import;
readonly class BonusRowDto
{
public function __construct(
public string $employeeNumber,
public ?string $bonusDate,
public ?string $bonusType,
public ?float $amount,
public ?string $reason,
) {}
/**
* @param array<string, mixed> $row
*/
public static function fromMappedRow(array $row): self
{
return new self(
employeeNumber: (string) ($row['employee_number'] ?? ''),
bonusDate: self::nullableString($row['bonus_date'] ?? null),
bonusType: self::nullableString($row['bonus_type'] ?? null),
amount: isset($row['amount']) && $row['amount'] !== '' ? (float) $row['amount'] : null,
reason: self::nullableString($row['reason'] ?? null),
);
}
private static function nullableString(mixed $value): ?string
{
if ($value === null || $value === '') {
return null;
}
return (string) $value;
}
}