Skip to content

Commit e24a3ba

Browse files
committed
Fix Promotion Model
1 parent f030e18 commit e24a3ba

2 files changed

Lines changed: 24 additions & 32 deletions

File tree

src/Client.php

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,13 @@ public function getOperatorsByCountryIso(string $countryIso, bool $suggestedAmou
416416
$operators = [];
417417

418418
if ($response != null && $response->getContent() != null) {
419-
foreach ($response->getContent() as $jsonCollection) {
420419

421-
if (!is_array($jsonCollection)) {
420+
foreach ($response->getContent() as $operatorsResponse) {
422421

423-
$operators[] = Operator::fromResponseData($jsonCollection);
422+
if (!is_array($operatorsResponse)) continue;
424423

425-
}
426-
else {
427-
foreach ($jsonCollection as $json) {
428-
$operators[] = Operator::fromResponseData($json);
429-
}
424+
foreach ($operatorsResponse as $data) {
425+
$operators[] = Operator::fromResponseData($data);
430426
}
431427
}
432428
}
@@ -452,17 +448,12 @@ public function getPromotions(int $page = 1, int $size = 50) : ?array {
452448
$promotions = [];
453449

454450
if ($response != null && $response->getContent() != null) {
455-
foreach ($response->getContent() as $jsonCollection) {
456-
457-
if (!is_array($jsonCollection)) {
451+
foreach ($response->getContent() as $promotionsResponse) {
458452

459-
$promotions[] = Promotion::fromResponseData($jsonCollection);
453+
if (!is_array($promotionsResponse)) continue;
460454

461-
}
462-
else {
463-
foreach ($jsonCollection as $json) {
464-
$promotions[] = Promotion::fromResponseData($json);
465-
}
455+
foreach ($promotionsResponse as $data) {
456+
$promotions[] = Promotion::fromResponseData($data);
466457
}
467458
}
468459
}
@@ -482,11 +473,11 @@ public function getPromotionsByCountryIso(string $country_iso) : ?array {
482473
$promotions = [];
483474

484475
if ($response != null && $response->getContent() != null) {
485-
foreach ($response->getContent() as $jsonCollection) {
486-
if (!is_array($jsonCollection)) continue;
476+
foreach ($response->getContent() as $promotionsResponse) {
477+
if (!is_array($promotionsResponse)) continue;
487478

488-
foreach ($jsonCollection as $json) {
489-
$promotions[] = Promotion::fromResponseData($json);
479+
foreach ($promotionsResponse as $data) {
480+
$promotions[] = Promotion::fromResponseData($data);
490481
}
491482
}
492483
}
@@ -506,11 +497,11 @@ public function getPromotionsByOperator(int $operator_id) : ?array {
506497
$promotions = [];
507498

508499
if ($response != null && $response->getContent() != null) {
509-
foreach ($response->getContent() as $jsonCollection) {
510-
if (!is_array($jsonCollection)) continue;
500+
foreach ($response->getContent() as $promotionsResponse) {
501+
if (!is_array($promotionsResponse)) continue;
511502

512-
foreach ($jsonCollection as $json) {
513-
$promotions[] = Promotion::fromResponseData($json);
503+
foreach ($promotionsResponse as $data) {
504+
$promotions[] = Promotion::fromResponseData($data);
514505
}
515506
}
516507
}
@@ -552,12 +543,11 @@ public function getTransactions(DateTimeInterface $start_date_time, DateTimeInte
552543
$transactions = [];
553544

554545
if ($response != null && $response->getContent() != null) {
555-
foreach ($response->getContent() as $jsonCollection) {
556-
557-
if (!is_array($jsonCollection)) continue;
546+
foreach ($response->getContent() as $transactionsResponse) {
547+
if (!is_array($transactionsResponse)) continue;
558548

559-
foreach ($jsonCollection as $json) {
560-
$transactions[] = Transaction::fromResponseData($json);
549+
foreach ($transactionsResponse as $data) {
550+
$transactions[] = Transaction::fromResponseData($data);
561551
}
562552
}
563553
}

src/Model/Promotion.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Promotion
4040

4141
public static function fromResponseData($data) : ?Promotion
4242
{
43+
if (!$data) return null;
44+
4345
$promotion = new Promotion();
4446

4547
foreach ($data as $key => $value) {
@@ -71,7 +73,7 @@ public function getPromotionId(): int
7173
* @param int $promotion_id
7274
* @return Promotion
7375
*/
74-
public function setPromotionId(int $promotion_id): Promotion
76+
public function setPromotionId(?int $promotion_id): Promotion
7577
{
7678
$this->promotion_id = $promotion_id;
7779
return $this;
@@ -89,7 +91,7 @@ public function getOperatorId(): int
8991
* @param int $operator_id
9092
* @return Promotion
9193
*/
92-
public function setOperatorId(int $operator_id): Promotion
94+
public function setOperatorId(?int $operator_id): Promotion
9395
{
9496
$this->operator_id = $operator_id;
9597
return $this;

0 commit comments

Comments
 (0)