PHP7 Strategy

This commit is contained in:
Dominik Liebler
2016-09-22 11:02:03 +02:00
parent 9b9eee5a4c
commit 36f3df8fbb
5 changed files with 47 additions and 53 deletions

View File

@@ -5,17 +5,16 @@ namespace DesignPatterns\Behavioral\Strategy;
class DateComparator implements ComparatorInterface
{
/**
* {@inheritdoc}
* @param mixed $a
* @param mixed $b
*
* @return int
*/
public function compare($a, $b)
public function compare($a, $b): int
{
$aDate = new \DateTime($a['date']);
$bDate = new \DateTime($b['date']);
if ($aDate == $bDate) {
return 0;
}
return $aDate < $bDate ? -1 : 1;
return $aDate <=> $bDate;
}
}