@@ -36,7 +36,7 @@ private function init(): void
3636 * @param array $recordData
3737 * @return self
3838 */
39- public static function fromRecordData (array $ recordData )
39+ public static function fromRecordData (array $ recordData ): self
4040 {
4141 return new self ($ recordData );
4242 }
@@ -45,7 +45,7 @@ public static function fromRecordData(array $recordData)
4545 * @param array $nativeData
4646 * @return self
4747 */
48- public static function fromArray (array $ nativeData )
48+ public static function fromArray (array $ nativeData ): self
4949 {
5050 return new self (null , $ nativeData );
5151 }
@@ -73,7 +73,7 @@ private function __construct(array $recordData = null, array $nativeData = null)
7373 * @param array $recordData
7474 * @return self
7575 */
76- public function with (array $ recordData )
76+ public function with (array $ recordData ): self
7777 {
7878 $ copy = clone $ this ;
7979 $ copy ->setRecordData ($ recordData );
@@ -94,24 +94,24 @@ public function toArray(): array
9494 case ImmutableRecord::PHP_TYPE_BOOL :
9595 case ImmutableRecord::PHP_TYPE_ARRAY :
9696 if (\array_key_exists ($ key , $ arrayPropItemTypeMap ) && ! self ::isScalarType ($ arrayPropItemTypeMap [$ key ])) {
97- if ($ isNullable && $ this ->{$ key }() === null ) {
97+ if ($ isNullable && $ this ->{$ key } === null ) {
9898 $ nativeData [$ key ] = null ;
9999 continue 2 ;
100100 }
101101
102102 $ nativeData [$ key ] = \array_map (function ($ item ) use ($ key , &$ arrayPropItemTypeMap ) {
103103 return $ this ->voTypeToNative ($ item , $ key , $ arrayPropItemTypeMap [$ key ]);
104- }, $ this ->{$ key }() );
104+ }, $ this ->{$ key });
105105 } else {
106- $ nativeData [$ key ] = $ this ->{$ key }() ;
106+ $ nativeData [$ key ] = $ this ->{$ key };
107107 }
108108 break ;
109109 default :
110- if ($ isNullable && $ this ->{$ key }() === null ) {
110+ if ($ isNullable && (! isset ( $ this ->{$ key })) ) {
111111 $ nativeData [$ key ] = null ;
112112 continue 2 ;
113113 }
114- $ nativeData [$ key ] = $ this ->voTypeToNative ($ this ->{$ key }() , $ key , $ type );
114+ $ nativeData [$ key ] = $ this ->voTypeToNative ($ this ->{$ key }, $ key , $ type );
115115 }
116116 }
117117
@@ -120,22 +120,22 @@ public function toArray(): array
120120
121121 public function equals (ImmutableRecord $ other ): bool
122122 {
123- if (get_class ($ this ) !== get_class ($ other )) {
123+ if (get_class ($ this ) !== get_class ($ other )) {
124124 return false ;
125125 }
126126
127127 return $ this ->toArray () === $ other ->toArray ();
128128 }
129129
130- private function setRecordData (array $ recordData )
130+ private function setRecordData (array $ recordData ): void
131131 {
132132 foreach ($ recordData as $ key => $ value ) {
133133 $ this ->assertType ($ key , $ value );
134134 $ this ->{$ key } = $ value ;
135135 }
136136 }
137137
138- private function setNativeData (array $ nativeData )
138+ private function setNativeData (array $ nativeData ): void
139139 {
140140 $ recordData = [];
141141 $ arrayPropItemTypeMap = self ::getArrayPropItemTypeMapFromMethodOrCache ();
@@ -182,10 +182,10 @@ private function setNativeData(array $nativeData)
182182 $ this ->setRecordData ($ recordData );
183183 }
184184
185- private function assertAllNotNull ()
185+ private function assertAllNotNull (): void
186186 {
187187 foreach (self ::$ __propTypeMap as $ key => [$ type , $ isNative , $ isNullable ]) {
188- if (null === $ this ->{$ key } && ! $ isNullable ) {
188+ if (! isset ( $ this ->{$ key }) && ! $ isNullable ) {
189189 throw new \InvalidArgumentException (\sprintf (
190190 'Missing record data for key %s of record %s. ' ,
191191 $ key ,
@@ -195,7 +195,7 @@ private function assertAllNotNull()
195195 }
196196 }
197197
198- private function assertType (string $ key , $ value )
198+ private function assertType (string $ key , $ value ): void
199199 {
200200 if (! isset (self ::$ __propTypeMap [$ key ])) {
201201 throw new \InvalidArgumentException (\sprintf (
@@ -264,7 +264,7 @@ private function isType(string $type, string $key, $value): bool
264264 }
265265 }
266266
267- private static function buildPropTypeMap ()
267+ private static function buildPropTypeMap (): array
268268 {
269269 $ refObj = new \ReflectionClass (__CLASS__ );
270270
@@ -384,12 +384,12 @@ private static function getArrayPropItemTypeMapFromMethodOrCache(): array
384384 }
385385
386386 /**
387- * @var array
387+ * @var array|null
388388 */
389389 private static $ __propTypeMap ;
390390
391391 /**
392- * @var array
392+ * @var array|null
393393 */
394394 private static $ __arrayPropItemTypeMap ;
395395}
0 commit comments