@@ -468,6 +468,7 @@ private function getCacheKey(string $scope, string $value): string
468468 private function saveRemediations (array $ decisions ): array
469469 {
470470 $ errors = [];
471+ $ count = 0 ;
471472 foreach ($ decisions as $ decision ) {
472473 $ remediation = $ this ->formatRemediationFromDecision ($ decision );
473474 $ type = $ remediation [0 ];
@@ -492,9 +493,16 @@ private function saveRemediations(array $decisions): array
492493 }
493494 $ cacheKey = $ this ->getCacheKey ($ decision ['scope ' ], $ address ->toString ());
494495 $ this ->addRemediationToCacheItem ($ cacheKey , $ type , $ exp , $ id );
496+ ++$ count ;
495497 } elseif (Constants::SCOPE_RANGE === $ decision ['scope ' ]) {
496498 $ range = Subnet::parseString ($ decision ['value ' ]);
497-
499+ if (null === $ range ) {
500+ $ this ->logger ->warning ('' , [
501+ 'type ' => 'INVALID_RANGE_TO_ADD_FROM_REMEDIATION ' ,
502+ 'decision ' => $ decision ,
503+ ]);
504+ continue ;
505+ }
498506 $ addressType = $ range ->getAddressType ();
499507 $ isIpv6 = (Type::T_IPv6 === $ addressType );
500508 if ($ isIpv6 || ($ range ->getNetworkPrefix () < 24 )) {
@@ -527,13 +535,15 @@ private function saveRemediations(array $decisions): array
527535 throw new BouncerException ($ message );
528536 }
529537 } while (0 !== strcmp ($ address ->getComparableString (), $ comparableEndAddress ));
538+ ++$ count ;
530539 } elseif (Constants::SCOPE_COUNTRY === $ decision ['scope ' ]) {
531540 $ cacheKey = $ this ->getCacheKey ($ decision ['scope ' ], $ decision ['value ' ]);
532541 $ this ->addRemediationToCacheItem ($ cacheKey , $ type , $ exp , $ id );
542+ ++$ count ;
533543 }
534544 }
535545
536- return ['success ' => $ this ->commit (), 'errors ' => $ errors ];
546+ return ['success ' => $ this ->commit (), 'errors ' => $ errors, ' count ' => $ count ];
537547 }
538548
539549 /**
@@ -570,7 +580,13 @@ private function removeRemediations(array $decisions): array
570580 }
571581 } elseif (Constants::SCOPE_RANGE === $ decision ['scope ' ]) {
572582 $ range = Subnet::parseString ($ decision ['value ' ]);
573-
583+ if (null === $ range ) {
584+ $ this ->logger ->warning ('' , [
585+ 'type ' => 'INVALID_RANGE_TO_REMOVE_FROM_REMEDIATION ' ,
586+ 'decision ' => $ decision ,
587+ ]);
588+ continue ;
589+ }
574590 $ addressType = $ range ->getAddressType ();
575591 $ isIpv6 = (Type::T_IPv6 === $ addressType );
576592 if ($ isIpv6 || ($ range ->getNetworkPrefix () < 24 )) {
@@ -751,8 +767,15 @@ public function pullUpdates(): array
751767 $ nbNew = 0 ;
752768 if ($ newDecisions ) {
753769 $ saveResult = $ this ->saveRemediations ($ newDecisions );
754- $ addErrors = $ saveResult ['errors ' ];
755- $ nbNew = \count ($ newDecisions );
770+ if (!empty ($ saveResult ['success ' ])){
771+ $ addErrors = $ saveResult ['errors ' ]??0 ;
772+ $ nbNew = $ saveResult ['count ' ]??0 ;
773+ }
774+ else {
775+ $ this ->logger ->warning ('' , [
776+ 'type ' => 'CACHE_UPDATED_FAILED ' ,
777+ 'message ' => 'Something went wrong while committing to cache adapter ' ]);
778+ }
756779 }
757780
758781 $ this ->logger ->debug ('' , ['type ' => 'CACHE_UPDATED ' , 'deleted ' => $ nbDeleted , 'new ' => $ nbNew ]);
0 commit comments