1111
1212namespace EventEngine \Data ;
1313
14+ /**
15+ * Trait ImmutableRecordLogic
16+ * @package EventEngine\Data
17+ *
18+ * @psalm-immutable
19+ */
1420trait ImmutableRecordLogic
1521{
1622 /**
@@ -36,7 +42,7 @@ private function init(): void
3642 * @param array $recordData
3743 * @return self
3844 */
39- public static function fromRecordData (array $ recordData )
45+ public static function fromRecordData (array $ recordData ): self
4046 {
4147 return new self ($ recordData );
4248 }
@@ -45,7 +51,7 @@ public static function fromRecordData(array $recordData)
4551 * @param array $nativeData
4652 * @return self
4753 */
48- public static function fromArray (array $ nativeData )
54+ public static function fromArray (array $ nativeData ): self
4955 {
5056 return new self (null , $ nativeData );
5157 }
@@ -73,7 +79,7 @@ private function __construct(array $recordData = null, array $nativeData = null)
7379 * @param array $recordData
7480 * @return self
7581 */
76- public function with (array $ recordData )
82+ public function with (array $ recordData ): self
7783 {
7884 $ copy = clone $ this ;
7985 $ copy ->setRecordData ($ recordData );
@@ -127,15 +133,15 @@ public function equals(ImmutableRecord $other): bool
127133 return $ this ->toArray () === $ other ->toArray ();
128134 }
129135
130- private function setRecordData (array $ recordData )
136+ private function setRecordData (array $ recordData ): void
131137 {
132138 foreach ($ recordData as $ key => $ value ) {
133139 $ this ->assertType ($ key , $ value );
134140 $ this ->{$ key } = $ value ;
135141 }
136142 }
137143
138- private function setNativeData (array $ nativeData )
144+ private function setNativeData (array $ nativeData ): void
139145 {
140146 $ recordData = [];
141147 $ arrayPropItemTypeMap = self ::getArrayPropItemTypeMapFromMethodOrCache ();
@@ -182,7 +188,7 @@ private function setNativeData(array $nativeData)
182188 $ this ->setRecordData ($ recordData );
183189 }
184190
185- private function assertAllNotNull ()
191+ private function assertAllNotNull (): void
186192 {
187193 foreach (self ::$ __propTypeMap as $ key => [$ type , $ isNative , $ isNullable ]) {
188194 if (null === $ this ->{$ key } && ! $ isNullable ) {
@@ -195,7 +201,7 @@ private function assertAllNotNull()
195201 }
196202 }
197203
198- private function assertType (string $ key , $ value )
204+ private function assertType (string $ key , $ value ): void
199205 {
200206 if (! isset (self ::$ __propTypeMap [$ key ])) {
201207 throw new \InvalidArgumentException (\sprintf (
@@ -264,7 +270,7 @@ private function isType(string $type, string $key, $value): bool
264270 }
265271 }
266272
267- private static function buildPropTypeMap ()
273+ private static function buildPropTypeMap (): array
268274 {
269275 $ refObj = new \ReflectionClass (__CLASS__ );
270276
@@ -383,12 +389,12 @@ private static function getArrayPropItemTypeMapFromMethodOrCache(): array
383389 }
384390
385391 /**
386- * @var array
392+ * @var array|null
387393 */
388394 private static $ __propTypeMap ;
389395
390396 /**
391- * @var array
397+ * @var array|null
392398 */
393399 private static $ __arrayPropItemTypeMap ;
394400}
0 commit comments