From 0a34e92a5b6814a3687c9249295b5ebede1d985e Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sun, 11 Apr 2021 16:45:37 +0200 Subject: [PATCH] Remove genders that are null --- src/Api.php | 2 +- src/Gender.php | 18 +++++------------- tests/Unit/PullGenderTest.php | 13 ------------- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/Api.php b/src/Api.php index 822f411..c78f857 100644 --- a/src/Api.php +++ b/src/Api.php @@ -156,7 +156,7 @@ class Api { public function genders(): Collection { return collect($this->http()->get(self::$url."/ica/rest/baseadmin/geschlecht")['data'])->map(function($gender) { return Gender::fromNami($gender); - }); + })->filter(fn($gender) => !$gender->isNull); } public function nationalities(): Collection { diff --git a/src/Gender.php b/src/Gender.php index 1372b9d..e2a12ac 100644 --- a/src/Gender.php +++ b/src/Gender.php @@ -14,22 +14,14 @@ class Gender extends Model implements Nullable { } public static function fromNami($item) { - $item = collect($item) - ->only(['descriptor', 'id']) - ->mapWithKeys(function($item,$key) { - if ($key == 'id') { return ['id' => $item]; } - return ['name' => $item]; - })->toArray(); - - return (new self($item)); - } - - public function getNameAttribute() { - return ucfirst($this->attributes['name']); + return new self([ + 'id' => $item['id'], + 'name' => ucfirst($item['descriptor']) + ]); } public function getIsNullAttribute() { - return $this->attributes['id'] == self::getNullValue(); + return $this->id == self::getNullValue(); } } diff --git a/tests/Unit/PullGenderTest.php b/tests/Unit/PullGenderTest.php index 585fd22..b20974a 100644 --- a/tests/Unit/PullGenderTest.php +++ b/tests/Unit/PullGenderTest.php @@ -21,7 +21,6 @@ class PullGenderTest extends TestCase Nami::login(); $this->assertEquals([ - 23 => 'Keine Angabe', 19 => 'Männlich', 20 => 'Weiblich' ], Nami::genders()->pluck('name', 'id')->toArray()); @@ -29,16 +28,4 @@ class PullGenderTest extends TestCase Http::assertSentCount(3); } - public function test_a_gender_can_be_null() { - Http::fake(array_merge($this->login(), $this->fakeGenders())); - - $this->setCredentials(); - - Nami::login(); - - $this->assertEquals([true, false, false], Nami::genders()->pluck('isNull')->toArray()); - - Http::assertSentCount(3); - } - }