|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace XTwitterScraper\APIKeys\APIKeyListResponse; |
| 6 | + |
| 7 | +use XTwitterScraper\Core\Attributes\Optional; |
| 8 | +use XTwitterScraper\Core\Attributes\Required; |
| 9 | +use XTwitterScraper\Core\Concerns\SdkModel; |
| 10 | +use XTwitterScraper\Core\Contracts\BaseModel; |
| 11 | + |
| 12 | +/** |
| 13 | + * @phpstan-type KeyShape = array{ |
| 14 | + * id: string, |
| 15 | + * createdAt: \DateTimeInterface, |
| 16 | + * isActive: bool, |
| 17 | + * name: string, |
| 18 | + * prefix: string, |
| 19 | + * lastUsedAt?: \DateTimeInterface|null, |
| 20 | + * } |
| 21 | + */ |
| 22 | +final class Key implements BaseModel |
| 23 | +{ |
| 24 | + /** @use SdkModel<KeyShape> */ |
| 25 | + use SdkModel; |
| 26 | + |
| 27 | + #[Required] |
| 28 | + public string $id; |
| 29 | + |
| 30 | + #[Required] |
| 31 | + public \DateTimeInterface $createdAt; |
| 32 | + |
| 33 | + #[Required] |
| 34 | + public bool $isActive; |
| 35 | + |
| 36 | + #[Required] |
| 37 | + public string $name; |
| 38 | + |
| 39 | + #[Required] |
| 40 | + public string $prefix; |
| 41 | + |
| 42 | + #[Optional] |
| 43 | + public ?\DateTimeInterface $lastUsedAt; |
| 44 | + |
| 45 | + /** |
| 46 | + * `new Key()` is missing required properties by the API. |
| 47 | + * |
| 48 | + * To enforce required parameters use |
| 49 | + * ``` |
| 50 | + * Key::with(id: ..., createdAt: ..., isActive: ..., name: ..., prefix: ...) |
| 51 | + * ``` |
| 52 | + * |
| 53 | + * Otherwise ensure the following setters are called |
| 54 | + * |
| 55 | + * ``` |
| 56 | + * (new Key) |
| 57 | + * ->withID(...) |
| 58 | + * ->withCreatedAt(...) |
| 59 | + * ->withIsActive(...) |
| 60 | + * ->withName(...) |
| 61 | + * ->withPrefix(...) |
| 62 | + * ``` |
| 63 | + */ |
| 64 | + public function __construct() |
| 65 | + { |
| 66 | + $this->initialize(); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Construct an instance from the required parameters. |
| 71 | + * |
| 72 | + * You must use named parameters to construct any parameters with a default value. |
| 73 | + */ |
| 74 | + public static function with( |
| 75 | + string $id, |
| 76 | + \DateTimeInterface $createdAt, |
| 77 | + bool $isActive, |
| 78 | + string $name, |
| 79 | + string $prefix, |
| 80 | + ?\DateTimeInterface $lastUsedAt = null, |
| 81 | + ): self { |
| 82 | + $self = new self; |
| 83 | + |
| 84 | + $self['id'] = $id; |
| 85 | + $self['createdAt'] = $createdAt; |
| 86 | + $self['isActive'] = $isActive; |
| 87 | + $self['name'] = $name; |
| 88 | + $self['prefix'] = $prefix; |
| 89 | + |
| 90 | + null !== $lastUsedAt && $self['lastUsedAt'] = $lastUsedAt; |
| 91 | + |
| 92 | + return $self; |
| 93 | + } |
| 94 | + |
| 95 | + public function withID(string $id): self |
| 96 | + { |
| 97 | + $self = clone $this; |
| 98 | + $self['id'] = $id; |
| 99 | + |
| 100 | + return $self; |
| 101 | + } |
| 102 | + |
| 103 | + public function withCreatedAt(\DateTimeInterface $createdAt): self |
| 104 | + { |
| 105 | + $self = clone $this; |
| 106 | + $self['createdAt'] = $createdAt; |
| 107 | + |
| 108 | + return $self; |
| 109 | + } |
| 110 | + |
| 111 | + public function withIsActive(bool $isActive): self |
| 112 | + { |
| 113 | + $self = clone $this; |
| 114 | + $self['isActive'] = $isActive; |
| 115 | + |
| 116 | + return $self; |
| 117 | + } |
| 118 | + |
| 119 | + public function withName(string $name): self |
| 120 | + { |
| 121 | + $self = clone $this; |
| 122 | + $self['name'] = $name; |
| 123 | + |
| 124 | + return $self; |
| 125 | + } |
| 126 | + |
| 127 | + public function withPrefix(string $prefix): self |
| 128 | + { |
| 129 | + $self = clone $this; |
| 130 | + $self['prefix'] = $prefix; |
| 131 | + |
| 132 | + return $self; |
| 133 | + } |
| 134 | + |
| 135 | + public function withLastUsedAt(\DateTimeInterface $lastUsedAt): self |
| 136 | + { |
| 137 | + $self = clone $this; |
| 138 | + $self['lastUsedAt'] = $lastUsedAt; |
| 139 | + |
| 140 | + return $self; |
| 141 | + } |
| 142 | +} |
0 commit comments