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

56 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\DTOs\Import;
readonly class EmployeeRowDto
{
public function __construct(
public string $employeeNumber,
public string $fullName,
public ?string $nationalId,
public ?string $gender,
public ?string $birthDate,
public ?string $phone,
public ?string $address,
public ?string $department,
public ?string $position,
public ?string $shift,
public ?string $employmentStatus,
public ?string $hireDate,
public ?string $notes,
) {}
/**
* @param array<string, mixed> $row
*/
public static function fromMappedRow(array $row): self
{
return new self(
employeeNumber: (string) ($row['employee_number'] ?? ''),
fullName: (string) ($row['full_name'] ?? ''),
nationalId: self::nullableString($row['national_id'] ?? null),
gender: self::nullableString($row['gender'] ?? null),
birthDate: self::nullableString($row['birth_date'] ?? null),
phone: self::nullableString($row['phone'] ?? null),
address: self::nullableString($row['address'] ?? null),
department: self::nullableString($row['department'] ?? null),
position: self::nullableString($row['position'] ?? null),
shift: self::nullableString($row['shift'] ?? null),
employmentStatus: self::nullableString($row['employment_status'] ?? null),
hireDate: self::nullableString($row['hire_date'] ?? null),
notes: self::nullableString($row['notes'] ?? null),
);
}
private static function nullableString(mixed $value): ?string
{
if ($value === null || $value === '') {
return null;
}
return (string) $value;
}
}