-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Model added with updated return type and tests #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f935eb
557dc82
6fe856e
c205b47
12a3fa8
a657068
f7cedad
e38a57e
4a23699
07c3b34
78c6d18
eac4042
e986d01
dc52b4f
2a4c4a5
350de58
de5c845
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,10 +7,12 @@ | |||||||
| use GuzzleHttp\Client; | ||||||||
| use HamroCDN\Contracts\HamroCDNContract; | ||||||||
| use HamroCDN\Exceptions\HamroCDNException; | ||||||||
| use HamroCDN\Models\Upload; | ||||||||
| use HamroCDN\Traits\HasConfigValues; | ||||||||
| use HamroCDN\Traits\Requestable; | ||||||||
|
|
||||||||
| /** | ||||||||
| * @phpstan-import-type HamroCDNObject from Upload | ||||||||
| * @phpstan-import-type HamroCDNData from HamroCDNContract | ||||||||
| * @phpstan-import-type HamroCDNObjectWithPagination from HamroCDNContract | ||||||||
| */ | ||||||||
|
|
@@ -37,37 +39,46 @@ public function __construct(?string $apiKey = null, ?string $baseUrl = null, ?Cl | |||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * @return HamroCDNObjectWithPagination | ||||||||
| * | ||||||||
| * @throws HamroCDNException | ||||||||
|
||||||||
| * @throws HamroCDNException | |
| * @throws HamroCDNException | |
| * @return array{data: array<Upload>, meta: array{total: int, per_page: int, page: int}} |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return type documentation. Consider adding @return Upload to match the interface documentation style and clarify what is returned.
| * @throws HamroCDNException | |
| * @throws HamroCDNException | |
| * @return Upload |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return type documentation. Consider adding @return Upload to match the interface documentation style and clarify what is returned.
| * @throws HamroCDNException | |
| * @throws HamroCDNException | |
| * @return Upload |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return type documentation. Consider adding @return Upload to match the interface documentation style and clarify what is returned.
| * @throws HamroCDNException | |
| * @throws HamroCDNException | |
| * @return Upload |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace HamroCDN\Models; | ||
|
|
||
| /** | ||
| * @phpstan-type HamroCDNFile array{ | ||
| * url: string, | ||
| * size: int | ||
| * } | ||
| */ | ||
| final class File | ||
| { | ||
| public function __construct( | ||
| private string $url, | ||
| private int $size | ||
| ) {} | ||
|
|
||
| /** @param HamroCDNFile $data */ | ||
| public static function fromArray(array $data): self | ||
| { | ||
| return new self( | ||
| $data['url'], | ||
| (int) $data['size'], | ||
| ); | ||
| } | ||
|
|
||
| public function getUrl(): string | ||
| { | ||
| return $this->url; | ||
| } | ||
|
|
||
| public function getSize(): int | ||
| { | ||
| return $this->size; | ||
| } | ||
|
|
||
| /** @return HamroCDNFile */ | ||
| public function toArray(): array | ||
| { | ||
| return [ | ||
| 'url' => $this->url, | ||
| 'size' => $this->size, | ||
| ]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace HamroCDN\Models; | ||
|
|
||
| use Carbon\Carbon; | ||
|
|
||
| /** | ||
| * @phpstan-import-type HamroCDNUser from User | ||
| * @phpstan-import-type HamroCDNFile from File | ||
| * | ||
| * @phpstan-type HamroCDNObject array{ | ||
| * nanoId: string, | ||
| * user: HamroCDNUser|null, | ||
| * delete_at: string|Carbon|null, | ||
| * original: HamroCDNFile | ||
| * } | ||
| * @phpstan-type UploadWithPagination array{ | ||
| * data: array<Upload>, | ||
| * meta: array{total: int, per_page: int, page: int} | ||
| * } | ||
| */ | ||
| final class Upload | ||
| { | ||
| public function __construct( | ||
| private string $nanoId, | ||
| private ?User $user, | ||
| private ?Carbon $deleteAt, | ||
| private File $original | ||
| ) {} | ||
|
|
||
| /** @param HamroCDNObject $data */ | ||
| public static function fromArray(array $data): self | ||
| { | ||
| $user = null; | ||
| if (isset($data['user'])) { | ||
| $user = User::fromArray($data['user']); | ||
| } | ||
|
|
||
| $original = File::fromArray($data['original']); | ||
|
|
||
| return new self( | ||
| $data['nanoId'], | ||
| $user, | ||
| isset($data['delete_at']) ? new Carbon($data['delete_at']) : null, | ||
| $original | ||
| ); | ||
| } | ||
|
|
||
| public function getNanoId(): string | ||
| { | ||
| return $this->nanoId; | ||
| } | ||
|
|
||
| public function getUser(): ?User | ||
| { | ||
| return $this->user; | ||
| } | ||
|
|
||
| public function getDeleteAt(): ?Carbon | ||
| { | ||
| return $this->deleteAt; | ||
| } | ||
|
|
||
| public function getOriginal(): File | ||
| { | ||
| return $this->original; | ||
| } | ||
|
|
||
| /** @return HamroCDNObject */ | ||
| public function toArray(): array | ||
| { | ||
| return [ | ||
| 'nanoId' => $this->nanoId, | ||
| 'user' => $this->user?->toArray(), | ||
| 'delete_at' => $this->deleteAt, | ||
| 'original' => $this->original->toArray(), | ||
| ]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace HamroCDN\Models; | ||
|
|
||
| /** | ||
| * @phpstan-type HamroCDNUser array{ | ||
| * name: string, | ||
| * email: string | ||
| * } | ||
| */ | ||
| final class User | ||
| { | ||
| public function __construct( | ||
| private string $name, | ||
| private string $email | ||
| ) {} | ||
|
|
||
| /** @param HamroCDNUser $data */ | ||
| public static function fromArray(array $data): self | ||
| { | ||
| return new self( | ||
| $data['name'], | ||
| $data['email'], | ||
| ); | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return $this->name; | ||
| } | ||
|
|
||
| public function getEmail(): string | ||
| { | ||
| return $this->email; | ||
| } | ||
|
|
||
| /** @return HamroCDNUser */ | ||
| public function toArray(): array | ||
| { | ||
| return [ | ||
| 'name' => $this->name, | ||
| 'email' => $this->email, | ||
| ]; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.