Remove old methods

This commit is contained in:
Oliver Davies 2019-05-20 02:00:00 +01:00
parent 7f48563806
commit d555d31e9d
2 changed files with 21 additions and 46 deletions

View file

@ -29,9 +29,7 @@ class TalksExtension extends AbstractExtension
public function getFunctions() public function getFunctions()
{ {
return [ return [
new TwigFunction('getAllTalks', [$this, 'getAll']), new TwigFunction('getTalks', [$this, 'getTalks']),
new TwigFunction('getUpcomingTalks', [$this, 'getUpcoming']),
new TwigFunction('getPastTalks', [$this, 'getPast']),
]; ];
} }
@ -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} * {@inheritdoc}
*/ */
@ -88,6 +48,21 @@ class TalksExtension extends AbstractExtension
return 'app.talks'; 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 public function getEvents(Collection $talks): Collection
{ {
return $talks->flatMap(function ($talk): array { return $talks->flatMap(function ($talk): array {

View file

@ -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 */ /** @test */
@ -69,7 +69,7 @@ class TalksExtensionTest extends TestCase
]; ];
$unorderedTalks = [$talkC, $talkA, $talkB]; $unorderedTalks = [$talkC, $talkA, $talkB];
$orderedTalks = $this->extension->getAll($unorderedTalks); $orderedTalks = $this->extension->getTalks($unorderedTalks);
$this->assertEquals([$talkC, $talkA, $talkB], $orderedTalks->toArray()); $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); $filtered = $this->extension->filterPast($talks);
$this->assertCount(1, $filtered); $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); $filtered = $this->extension->filterUpcoming($talks);
$this->assertCount(2, $filtered); $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->assertCount(1, $this->extension->filterUpcoming($talks));
$this->assertEmpty($this->extension->filterPast($talks)); $this->assertEmpty($this->extension->filterPast($talks));