55namespace CasParser \Core \Concerns ;
66
77use CasParser \Core \Contracts \BaseModel ;
8- use CasParser \Core \Contracts \BasePage ;
98use CasParser \Core \Conversion ;
109use CasParser \Core \Conversion \CoerceState ;
1110use CasParser \Core \Conversion \Contracts \Converter ;
1514/**
1615 * @internal
1716 *
18- * @template-covariant Data of array<string, mixed>
17+ * @template-covariant Shape of array<string, mixed>
1918 */
2019trait SdkModel
2120{
@@ -41,12 +40,12 @@ public function __serialize(): array
4140 /**
4241 * @internal
4342 *
44- * @param array<mixed> $data
43+ * @param array<string, mixed> $data
4544 */
4645 public function __unserialize (array $ data ): void
4746 {
4847 foreach ($ data as $ key => $ value ) {
49- $ this ->offsetSet ($ key , value: $ value );
48+ $ this ->offsetSet ($ key , value: $ value ); // @phpstan-ignore-line
5049 }
5150 }
5251
@@ -73,12 +72,14 @@ public function __toString(): string
7372 * a native class property, indicating an omitted value,
7473 * or a property overridden with an incongruent type
7574 *
75+ * @return value-of<Shape>
76+ *
7677 * @throws \Exception
7778 */
7879 public function __get (string $ key ): mixed
7980 {
8081 if (!array_key_exists ($ key , array: self ::$ converter ->properties )) {
81- throw new \Exception ("Property ' {$ key }' does not exist in {$ this }::class " );
82+ throw new \RuntimeException ("Property ' {$ key }' does not exist in {$ this }::class " );
8283 }
8384
8485 // The unset property was overridden by a value with an incongruent type.
@@ -91,11 +92,11 @@ public function __get(string $key): mixed
9192
9293 // An optional property which was unset to be omitted from serialized is being accessed.
9394 // Return null to match user's expectations.
94- return null ;
95+ return null ; // @phpstan-ignore-line
9596 }
9697
9798 /**
98- * @return Data
99+ * @return Shape
99100 */
100101 public function toArray (): array
101102 {
@@ -104,6 +105,8 @@ public function toArray(): array
104105
105106 /**
106107 * @internal
108+ *
109+ * @param key-of<Shape> $offset
107110 */
108111 public function offsetExists (mixed $ offset ): bool
109112 {
@@ -130,26 +133,32 @@ public function offsetExists(mixed $offset): bool
130133
131134 /**
132135 * @internal
136+ *
137+ * @param key-of<Shape> $offset
138+ *
139+ * @return value-of<Shape>
133140 */
134141 public function &offsetGet (mixed $ offset ): mixed
135142 {
136143 if (!is_string ($ offset )) { // @phpstan-ignore-line
137144 throw new \InvalidArgumentException ;
138145 }
139146
140- if (!$ this ->offsetExists ($ offset )) {
141- return null ;
147+ if (!$ this ->offsetExists ($ offset )) { // @phpstan-ignore-line
148+ return null ; // @phpstan-ignore-line
142149 }
143150
144151 if (array_key_exists ($ offset , array: $ this ->_data )) {
145- return $ this ->_data [$ offset ];
152+ return $ this ->_data [$ offset ]; // @phpstan-ignore-line
146153 }
147154
148- return $ this ->{$ offset };
155+ return $ this ->{$ offset }; // @phpstan-ignore-line
149156 }
150157
151158 /**
152159 * @internal
160+ *
161+ * @param key-of<Shape> $offset
153162 */
154163 public function offsetSet (mixed $ offset , mixed $ value ): void
155164 {
@@ -163,9 +172,9 @@ public function offsetSet(mixed $offset, mixed $value): void
163172
164173 $ coerced = Conversion::coerce ($ type , value: $ value , state: new CoerceState (translateNames: false ));
165174
166- if (property_exists ($ this , property: $ offset )) {
175+ if (property_exists ($ this , property: $ offset )) { // @phpstan-ignore-line
167176 try {
168- $ this ->{$ offset } = $ coerced ;
177+ $ this ->{$ offset } = $ coerced ; // @phpstan-ignore-line
169178 unset($ this ->_data [$ offset ]);
170179
171180 return ;
@@ -179,14 +188,16 @@ public function offsetSet(mixed $offset, mixed $value): void
179188
180189 /**
181190 * @internal
191+ *
192+ * @param key-of<Shape> $offset
182193 */
183194 public function offsetUnset (mixed $ offset ): void
184195 {
185196 if (!is_string ($ offset )) { // @phpstan-ignore-line
186197 throw new \InvalidArgumentException ;
187198 }
188199
189- if (property_exists ($ this , property: $ offset )) {
200+ if (property_exists ($ this , property: $ offset )) { // @phpstan-ignore-line
190201 unset($ this ->{$ offset });
191202 }
192203
@@ -205,7 +216,7 @@ public function jsonSerialize(): array
205216 /**
206217 * @param array<string, mixed> $data
207218 */
208- public static function fromArray (array $ data ): self
219+ public static function fromArray (array $ data ): static
209220 {
210221 return self ::converter ()->from ($ data ); // @phpstan-ignore-line
211222 }
@@ -249,7 +260,7 @@ private function unsetOptionalProperties(): void
249260 */
250261 private static function serialize (mixed $ value ): mixed
251262 {
252- if ($ value instanceof BaseModel || $ value instanceof BasePage ) {
263+ if ($ value instanceof BaseModel) {
253264 return $ value ->toArray ();
254265 }
255266
0 commit comments