mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-06 23:16:33 +02:00
PHP7 Strategy
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user