From d555d31e9daa27884e36fe859e065b66931b02fa Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 20 May 2019 02:00:00 +0100 Subject: [PATCH] Remove old methods --- .../src/TwigExtension/TalksExtension.php | 57 ++++++------------- .../TwigExtension/TalksExtensionTest.php | 10 ++-- 2 files changed, 21 insertions(+), 46 deletions(-) diff --git a/src/Talks/src/TwigExtension/TalksExtension.php b/src/Talks/src/TwigExtension/TalksExtension.php index 6e44a70c..0e58bc89 100644 --- a/src/Talks/src/TwigExtension/TalksExtension.php +++ b/src/Talks/src/TwigExtension/TalksExtension.php @@ -29,9 +29,7 @@ class TalksExtension extends AbstractExtension public function getFunctions() { return [ - new TwigFunction('getAllTalks', [$this, 'getAll']), - new TwigFunction('getUpcomingTalks', [$this, 'getUpcoming']), - new TwigFunction('getPastTalks', [$this, 'getPast']), + new TwigFunction('getTalks', [$this, 'getTalks']), ]; } @@ -42,44 +40,6 @@ class TalksExtension extends AbstractExtension ]; } - /** - * Get all upcoming and previous talks. - * - * @param ProxySourceCollection|array $talks All talk nodes. - * - * @return Collection A sorted collection of talks. - */ - public function getAll($talks): Collection - { - return collect($talks)->sortBy(function ($talk) { - return $this->getLastDate($talk); - }); - } - - /** - * Get all upcoming talks. - * - * @param ProxySourceCollection|array $talks All talk nodes. - * - * @return Collection A sorted collection of talks. - */ - public function getUpcoming($talks): Collection - { - return $this->getAll($talks); - } - - /** - * Get all past talks. - * - * @param ProxySourceCollection|array $talks All talk nodes. - * - * @return Collection A sorted collection of talks. - */ - public function getPast($talks): Collection - { - return $this->getAll($talks); - } - /** * {@inheritdoc} */ @@ -88,6 +48,21 @@ class TalksExtension extends AbstractExtension return 'app.talks'; } + /** + * Get all upcoming and previous talks. + * + * @param ProxySourceCollection|array $talks All talk nodes. + * + * @return Collection A sorted collection of talks. + */ + public function getTalks($talks): Collection + { + return collect($talks)->sortBy(function ($talk) { + return $this->getLastDate($talk); + }); + } + + public function getEvents(Collection $talks): Collection { return $talks->flatMap(function ($talk): array { diff --git a/src/Talks/tests/TwigExtension/TalksExtensionTest.php b/src/Talks/tests/TwigExtension/TalksExtensionTest.php index 4bf75468..2d5f3370 100644 --- a/src/Talks/tests/TwigExtension/TalksExtensionTest.php +++ b/src/Talks/tests/TwigExtension/TalksExtensionTest.php @@ -40,7 +40,7 @@ class TalksExtensionTest extends TestCase ], ]; - $this->assertCount(2, $this->extension->getAll([$talkA, $talkB])); + $this->assertCount(2, $this->extension->getTalks([$talkA, $talkB])); } /** @test */ @@ -69,7 +69,7 @@ class TalksExtensionTest extends TestCase ]; $unorderedTalks = [$talkC, $talkA, $talkB]; - $orderedTalks = $this->extension->getAll($unorderedTalks); + $orderedTalks = $this->extension->getTalks($unorderedTalks); $this->assertEquals([$talkC, $talkA, $talkB], $orderedTalks->toArray()); } @@ -91,7 +91,7 @@ class TalksExtensionTest extends TestCase ], ]; - $talks = $this->extension->getAll([$pastTalk, $futureTalk]); + $talks = $this->extension->getTalks([$pastTalk, $futureTalk]); $filtered = $this->extension->filterPast($talks); $this->assertCount(1, $filtered); @@ -122,7 +122,7 @@ class TalksExtensionTest extends TestCase ], ]; - $talks = $this->extension->getAll([$pastTalk, $todayTalk, $futureTalk]); + $talks = $this->extension->getTalks([$pastTalk, $todayTalk, $futureTalk]); $filtered = $this->extension->filterUpcoming($talks); $this->assertCount(2, $filtered); @@ -140,7 +140,7 @@ class TalksExtensionTest extends TestCase ], ]; - $talks = $this->extension->getAll([$talk]); + $talks = $this->extension->getTalks([$talk]); $this->assertCount(1, $this->extension->filterUpcoming($talks)); $this->assertEmpty($this->extension->filterPast($talks));