Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/Model/Paginated.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,29 @@ public static function fromArray(array $payload, ?callable $mapItem = null): sel
$rawMeta = is_array($payload['meta'] ?? null) ? $payload['meta'] : [];
/** @var array<int, mixed> $rawData */
$rawData = is_array($payload['data'] ?? null) ? $payload['data'] : [];
$meta = PaginationMeta::fromArray($rawMeta);

$items = [];
// Ramos separados para o PHPStan inferir o parâmetro genérico de cada
// caminho: self<array<string, mixed>> sem mapper, self<U> com mapper —
// batendo com o tipo de retorno condicional declarado acima.
if ($mapItem === null) {
$rows = [];
foreach ($rawData as $item) {
/** @var array<string, mixed> $row */
$row = is_array($item) ? $item : [];
$rows[] = $row;
}

return new self($meta, $rows);
}

$mapped = [];
foreach ($rawData as $item) {
/** @var array<string, mixed> $row */
$row = is_array($item) ? $item : [];
$items[] = $mapItem !== null ? $mapItem($row) : $row;
$mapped[] = $mapItem($row);
}

return new self(PaginationMeta::fromArray($rawMeta), $items);
return new self($meta, $mapped);
}
}
15 changes: 14 additions & 1 deletion src/SMSGoError.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
*/
final class SMSGoError extends RuntimeException
{
/**
* Código estável do erro (ex.: `validation_error`, `insufficient_balance`).
*
* Sobrescreve `Exception::$code` (herdada sem tipo nativo e readwrite), por
* isso é declarada aqui **sem tipo nativo e sem `readonly`** — do contrário o
* PHP/PHPStan acusam "readonly overrides readwrite" e "should not have a
* native type". O tipo real é `string`, definido via PHPDoc.
*
* @var string
*/
public $code; // phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint

/**
* @param int $status Status HTTP (0 em falha de rede/transporte).
* @param string $code Código estável do erro.
Expand All @@ -27,10 +39,11 @@ final class SMSGoError extends RuntimeException
public function __construct(
string $message,
public readonly int $status,
public readonly string $code,
string $code,
public readonly mixed $details = null,
public readonly ?array $errors = null,
) {
parent::__construct($message);
$this->code = $code;
}
}
Loading