@@ -272,7 +272,7 @@ public function getReadInfo(string $class, string $property, array $context = []
272
272
/**
273
273
* {@inheritdoc}
274
274
*/
275
- public function getWriteInfo (string $ class , string $ property , array $ context = []): PropertyWriteInfo
275
+ public function getWriteInfo (string $ class , string $ property , array $ context = []): ? PropertyWriteInfo
276
276
{
277
277
try {
278
278
$ reflClass = new \ReflectionClass ($ class );
@@ -308,10 +308,10 @@ public function getWriteInfo(string $class, string $property, array $context = [
308
308
$ mutator ->setRemoverInfo (new PropertyWriteInfo (PropertyWriteInfo::TYPE_METHOD , $ removerAccessName , $ this ->getWriteVisiblityForMethod ($ removerMethod ), $ removerMethod ->isStatic ()));
309
309
310
310
return $ mutator ;
311
- } else {
312
- $ errors = array_merge ($ errors , $ adderAndRemoverErrors );
313
311
}
314
312
313
+ $ errors = array_merge ($ errors , $ adderAndRemoverErrors );
314
+
315
315
foreach ($ this ->mutatorPrefixes as $ mutatorPrefix ) {
316
316
$ methodName = $ mutatorPrefix .$ camelized ;
317
317
@@ -330,12 +330,14 @@ public function getWriteInfo(string $class, string $property, array $context = [
330
330
331
331
$ getsetter = lcfirst ($ camelized );
332
332
333
- [$ accessible , $ methodAccessibleErrors ] = $ this ->isMethodAccessible ($ reflClass , $ getsetter , 1 );
334
- if ($ allowGetterSetter && $ accessible ) {
335
- $ method = $ reflClass ->getMethod ($ getsetter );
333
+ if ($ allowGetterSetter ) {
334
+ [$ accessible , $ methodAccessibleErrors ] = $ this ->isMethodAccessible ($ reflClass , $ getsetter , 1 );
335
+ if ($ accessible ) {
336
+ $ method = $ reflClass ->getMethod ($ getsetter );
337
+
338
+ return new PropertyWriteInfo (PropertyWriteInfo::TYPE_METHOD , $ getsetter , $ this ->getWriteVisiblityForMethod ($ method ), $ method ->isStatic ());
339
+ }
336
340
337
- return new PropertyWriteInfo (PropertyWriteInfo::TYPE_METHOD , $ getsetter , $ this ->getWriteVisiblityForMethod ($ method ), $ method ->isStatic ());
338
- } else {
339
341
$ errors = array_merge ($ errors , $ methodAccessibleErrors );
340
342
}
341
343
@@ -348,25 +350,27 @@ public function getWriteInfo(string $class, string $property, array $context = [
348
350
[$ accessible , $ methodAccessibleErrors ] = $ this ->isMethodAccessible ($ reflClass , '__set ' , 2 );
349
351
if ($ accessible ) {
350
352
return new PropertyWriteInfo (PropertyWriteInfo::TYPE_PROPERTY , $ property , PropertyWriteInfo::VISIBILITY_PUBLIC , false );
351
- } else {
352
- $ errors = array_merge ($ errors , $ methodAccessibleErrors );
353
353
}
354
354
355
- [$ accessible , $ methodAccessibleErrors ] = $ this ->isMethodAccessible ($ reflClass , '__call ' , 2 );
356
- if ($ allowMagicCall && $ accessible ) {
357
- return new PropertyWriteInfo (PropertyWriteInfo::TYPE_METHOD , 'set ' .$ camelized , PropertyWriteInfo::VISIBILITY_PUBLIC , false );
358
- } else {
355
+ $ errors = array_merge ($ errors , $ methodAccessibleErrors );
356
+
357
+ if ($ allowMagicCall ) {
358
+ [$ accessible , $ methodAccessibleErrors ] = $ this ->isMethodAccessible ($ reflClass , '__call ' , 2 );
359
+ if ($ accessible ) {
360
+ return new PropertyWriteInfo (PropertyWriteInfo::TYPE_METHOD , 'set ' .$ camelized , PropertyWriteInfo::VISIBILITY_PUBLIC , false );
361
+ }
362
+
359
363
$ errors = array_merge ($ errors , $ methodAccessibleErrors );
360
364
}
361
365
362
366
if (!$ allowAdderRemover && null !== $ adderAccessName && null !== $ removerAccessName ) {
363
- $ errors = array_merge ( $ errors , [ sprintf (
367
+ $ errors[] = sprintf (
364
368
'The property "%s" in class "%s" can be defined with the methods "%s()" but ' .
365
369
'the new value must be an array or an instance of \Traversable ' ,
366
370
$ property ,
367
371
$ reflClass ->getName (),
368
372
implode ('()", " ' , [$ adderAccessName , $ removerAccessName ])
369
- )]) ;
373
+ );
370
374
}
371
375
372
376
$ noneProperty = new PropertyWriteInfo ();
@@ -626,7 +630,7 @@ private function getPropertyName(string $methodName, array $reflectionProperties
626
630
private function findAdderAndRemover (\ReflectionClass $ reflClass , array $ singulars ): array
627
631
{
628
632
if (!\is_array ($ this ->arrayMutatorPrefixes ) && 2 !== \count ($ this ->arrayMutatorPrefixes )) {
629
- return null ;
633
+ return [ null , null , []] ;
630
634
}
631
635
632
636
[$ addPrefix , $ removePrefix ] = $ this ->arrayMutatorPrefixes ;
@@ -642,7 +646,9 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, array $singula
642
646
643
647
if ($ addMethodFound && $ removeMethodFound ) {
644
648
return [$ addMethod , $ removeMethod , []];
645
- } elseif ($ addMethodFound && !$ removeMethodFound ) {
649
+ }
650
+
651
+ if ($ addMethodFound && !$ removeMethodFound ) {
646
652
$ errors [] = sprintf ('The add method "%s" in class "%s" was found, but the corresponding remove method "%s" was not found ' , $ addMethod , $ reflClass ->getName (), $ removeMethod );
647
653
} elseif (!$ addMethodFound && $ removeMethodFound ) {
648
654
$ errors [] = sprintf ('The remove method "%s" in class "%s" was found, but the corresponding add method "%s" was not found ' , $ removeMethod , $ reflClass ->getName (), $ addMethod );
0 commit comments