Created
June 24, 2022 09:18
-
-
Save nyamsprod/af49f73749f2a61e7618d844d8f4f1f3 to your computer and use it in GitHub Desktop.
type-hint and PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getReport(CarbonInterface $start, CarbonInterface $end): Report | |
{ | |
return Report::query() | |
->whereDate('status_date', '>=', $start) | |
->whereDate('status_date', '<', $end) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getReport(DateTimeInterface $start, DateTimeInterface $end): Report | |
{ | |
return Report::query() | |
->whereDate('status_date', '>=', $start) | |
->whereDate('status_date', '<', $end) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function changeDate(Carbon $date): Carbon | |
{ | |
return $date->addDays(3); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function changeDate(CarbonImmutable $date): CarbonImmutable | |
{ | |
return $date->addDays(3); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface DateChanger | |
{ | |
public function changeDate(DateTimeImmutable $date): DateTimeImmutable; | |
} | |
final class CarbonChanger implements DateChanger | |
{ | |
public function changeDate(DateTimeImmutable $date): DateTimeImmutable | |
{ | |
return CarbonImmutable::fromInterface($date)->addDays(3); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getReport(Carbon $start, Carbon $end): Report | |
{ | |
return Report::query() | |
->whereDate('status_date', '>=', $start) | |
->whereDate('status_date', '<', $end) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment