diff --git a/src/DateRange.php b/src/DateRange.php index d7308a7..2a66ddf 100644 --- a/src/DateRange.php +++ b/src/DateRange.php @@ -2,23 +2,24 @@ namespace Danoha; -class DateRange { +class DateRange +{ - /** @var \DateTime|NULL */ - protected $from; + /** @var \DateTime|NULL */ + protected $from; - /** @var \DateTime|NULL */ - protected $to; + /** @var \DateTime|NULL */ + protected $to; - /** - * @param \DateTime|NULL $from - * @param \DateTime|NULL $to - */ + /** + * @param \DateTime|NULL $from + * @param \DateTime|NULL $to + */ public function __construct(\DateTime $from = NULL, \DateTime $to = NULL) { - $this->from = $from; - $this->to = $to; - } + $this->from = $from; + $this->to = $to; + } /** * @return \DateTime|NULL diff --git a/src/DateRangeCollection.php b/src/DateRangeCollection.php index 4b19ab8..afcffdc 100644 --- a/src/DateRangeCollection.php +++ b/src/DateRangeCollection.php @@ -3,19 +3,21 @@ namespace Danoha; -class DateRangeCollection { +class DateRangeCollection +{ - /** @var DateRange[] */ + /** @var DateRange[] */ protected $ranges = []; - /** - * @param array $collection + /** + * @param array $collection * @throws \InvalidArgumentException - */ - public function __construct($collection) { - foreach ($collection as $item) { - $this->ranges[] = DateRange::wrap($item); - } + */ + public function __construct($collection) + { + foreach ($collection as $item) { + $this->ranges[] = DateRange::wrap($item); + } usort($this->ranges, function (DateRange $a, DateRange $b) { $fromA = $a->getFrom(); @@ -53,16 +55,17 @@ public function __construct($collection) { return 0; }); - } + } /** * @return array */ - public function unwrap() { + public function unwrap() + { return array_map(function (DateRange $range) { return $range->unwrap(); }, $this->ranges); - } + } /** * @return DateRange[] @@ -168,7 +171,7 @@ public function join($collection = NULL) } return new static(array_filter($ranges)); - } + } /** * @param array|self $subtrahends diff --git a/tests/DateRange/Wrap.phpt b/tests/DateRange/Wrap.phpt index e38e058..5452022 100644 --- a/tests/DateRange/Wrap.phpt +++ b/tests/DateRange/Wrap.phpt @@ -3,14 +3,14 @@ require_once './../bootstrap.php'; use Tester\Assert; -Assert::same(\Danoha\DateRange::class, get_class(\Danoha\DateRange::wrap([ 'from' => NULL, 'to' => NULL, ]))); +Assert::same(\Danoha\DateRange::class, get_class(\Danoha\DateRange::wrap(['from' => NULL, 'to' => NULL,]))); -$range = \Danoha\DateRange::wrap([ 'from' => NULL, 'to' => NULL, ]); +$range = \Danoha\DateRange::wrap(['from' => NULL, 'to' => NULL,]); Assert::same($range, \Danoha\DateRange::wrap($range)); $from = new \DateTime('2016-01-01'); $to = new \DateTime('2017-01-01'); -$range = \Danoha\DateRange::wrap([ 'from' => $from, 'to' => $to, ]); +$range = \Danoha\DateRange::wrap(['from' => $from, 'to' => $to,]); $range2 = new \Danoha\DateRange($from, $to); Assert::same($from, $range->getFrom()); Assert::same($to, $range->getTo()); @@ -21,15 +21,15 @@ Assert::same([ 'to' => $to, ], $range->unwrap()); -Assert::same(NULL, \Danoha\DateRange::wrap([ new \DateTime('2016-01-01'), NULL, ])->getTo()); -Assert::same(NULL, \Danoha\DateRange::wrap([ NULL, new \DateTime('2016-01-01'), ])->getFrom()); +Assert::same(NULL, \Danoha\DateRange::wrap([new \DateTime('2016-01-01'), NULL,])->getTo()); +Assert::same(NULL, \Danoha\DateRange::wrap([NULL, new \DateTime('2016-01-01'),])->getFrom()); Assert::throws(function () { - \Danoha\DateRange::wrap([ 'asd' => '', ]); + \Danoha\DateRange::wrap(['asd' => '',]); }, InvalidArgumentException::class, 'Expected array with from and to or exactly 2 items'); Assert::throws(function () { - \Danoha\DateRange::wrap([ 'asd', ]); + \Danoha\DateRange::wrap(['asd',]); }, InvalidArgumentException::class, 'Expected array with from and to or exactly 2 items'); diff --git a/tests/DateRangeCollection/Wrap.phpt b/tests/DateRangeCollection/Wrap.phpt index cdab7cd..cac8e02 100644 --- a/tests/DateRangeCollection/Wrap.phpt +++ b/tests/DateRangeCollection/Wrap.phpt @@ -8,7 +8,7 @@ Assert::same(\Danoha\DateRangeCollection::class, get_class($coll1)); $from = new \DateTime; $coll2 = [ - [ 'from' => $from, 'to' => NULL, ], + ['from' => $from, 'to' => NULL,], ]; Assert::same($coll2, (new \Danoha\DateRangeCollection($coll2))->unwrap());