Skip to content

Commit

Permalink
better type hints and phpdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Mar 8, 2019
1 parent 84a864f commit 5c50f00
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 100 deletions.
23 changes: 15 additions & 8 deletions src/AbstractDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function __toString(): string
}

/**
* @param \DateTimeInterface $dateTime
*
* @return static
*/
public static function createFromDateTime(\DateTimeInterface $dateTime): self
Expand All @@ -50,8 +48,6 @@ public static function createFromDateTime(\DateTimeInterface $dateTime): self
}

/**
* @param int $timestamp
*
* @return static
*/
public static function createFromTimestamp(int $timestamp): self
Expand All @@ -62,13 +58,12 @@ public static function createFromTimestamp(int $timestamp): self
}

/**
* @param string $format
* @param string $dateTime
* @param \DateTimeZone $timezone
* @param string $format
* @param string $dateTime
*
* @return static
*/
public static function createFromFormat($format, $dateTime, $timezone = null): self
public static function createFromFormat($format, $dateTime, \DateTimeZone $timezone = null): self
{
$class = static::getClass();

Expand Down Expand Up @@ -139,21 +134,33 @@ public function getWeekday(): int
return (int) $this->format('w');
}

/**
* @return static
*/
public function addYears(int $years): DateTimeInterface
{
return $this->modify($years.' years');
}

/**
* @return static
*/
public function addMonths(int $months): DateTimeInterface
{
return $this->modify($months.' months');
}

/**
* @return static
*/
public function addWeeks(int $weeks): DateTimeInterface
{
return $this->modify($weeks.' weeks');
}

/**
* @return static
*/
public function addDays(int $days): DateTimeInterface
{
return $this->modify($days.' days');
Expand Down
45 changes: 4 additions & 41 deletions src/DateTimeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,80 +15,40 @@

interface DateTimeInterface extends \DateTimeInterface
{
/**
* @return string
*/
public function __toString(): string;

/**
* @return string
*/
public function formatIso(): string;

/**
* @param string $format
*
* @return string
*/
public function formatLocalized(string $format): string;

/**
* @param int $format
* @param int $timeFormat
*
* @return string
*/
public function formatIntl(int $format = null, int $timeFormat = null): string;

/**
* @return \DateTime
*/
public function toMutable(): \DateTime;

/**
* @return int
*/
public function getYear(): int;

/**
* @return int
*/
public function getMonth(): int;

/**
* @return int
*/
public function getDay(): int;

/**
* @return int
*/
public function getWeekday(): int;

/**
* @param int $years
*
* @return static
*/
public function addYears(int $years): self;

/**
* @param int $months
*
* @return static
*/
public function addMonths(int $months): self;

/**
* @param int $weeks
*
* @return static
*/
public function addWeeks(int $weeks): self;

/**
* @param int $days
*
* @return static
*/
public function addDays(int $days): self;
Expand Down Expand Up @@ -171,7 +131,10 @@ public function setDate($year, $month, $day);
public function setISODate($year, $week, $day = 1);

/**
* @param \DateInterval $interval
* @param int $hour
* @param int $minute
* @param int $second
* @param int $microseconds
*
* @return static
*/
Expand Down
12 changes: 0 additions & 12 deletions src/Holidays/HolidaysInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,11 @@

interface HolidaysInterface
{
/**
* @param DateTimeInterface $dateTime
*
* @return bool
*/
public function isHoliday(DateTimeInterface $dateTime): bool;

/**
* @param DateTimeInterface $dateTime
*
* @return bool
*/
public function isWorkday(DateTimeInterface $dateTime): bool;

/**
* @param int|string $year
*
* @return Date[]
*/
public function getHolidays(int $year): array;
Expand Down
2 changes: 1 addition & 1 deletion src/Range/AbstractDateTimeRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function diff(): \DateInterval
return $this->start->diff($this->end);
}

public function diffWorkdays(HolidaysInterface $holidays = null): int
public function diffWorkdays(?HolidaysInterface $holidays = null): int
{
return $this->start->diffWorkdays($this->end, $holidays);
}
Expand Down
39 changes: 1 addition & 38 deletions src/Range/DateTimeRangeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,25 @@

interface DateTimeRangeInterface
{
/**
* @return DateTimeInterface
*/
public function getStart(): DateTimeInterface;

/**
* @return DateTimeInterface
*/
public function getEnd(): DateTimeInterface;

/**
* @return \DateInterval
*/
public function diff(): \DateInterval;

/**
* @param null|HolidaysInterface $holidays
*
* @return int
*/
public function diffWorkdays(HolidaysInterface $holidays = null): int;
public function diffWorkdays(?HolidaysInterface $holidays = null): int;

/**
* @return bool
*/
public function isSameYear(): bool;

/**
* @return bool
*/
public function isSameMonth(): bool;

/**
* @return bool
*/
public function isSameDay(): bool;

/**
* @return bool
*/
public function isWholeYear(): bool;

/**
* @return bool
*/
public function isWholeMonth(): bool;

/**
* @return bool
*/
public function isWholeDay(): bool;

/**
* @param DateTimeInterface $dateTime
*
* @return bool
*/
public function contains(DateTimeInterface $dateTime): bool;
}

0 comments on commit 5c50f00

Please sign in to comment.