Add getSponsors body, Sponsor model

This commit is contained in:
Oliver Davies 2019-05-20 22:13:45 +01:00
parent e3ba387f86
commit 83d21c1c10
2 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,33 @@
<?php
namespace App\Sponsors\Model;
class Sponsor
{
/** @var array */
private $data = [];
private function __construct(array $sponsorData)
{
$this->data = $sponsorData;
}
public static function create(array $sponsorData): self
{
return new static($sponsorData);
}
public function isConfirmed(): bool
{
if (!isset($this->data['confirmed'])) {
return false;
}
return $this->data['confirmed'];
}
public function getData(): array
{
return $this->data;
}
}

View file

@ -22,5 +22,12 @@ class SponsorsExtension extends AbstractExtension
public function getSponsors(array $sponsorData, string $level): array
{
return collect($sponsorData[$level])
->map(function ($sponsor) {
return Sponsor::create($sponsor);
})
->filter->isConfirmed()
->map->getData()
->toArray();
}
}