Skip to content

Commit 688df6f

Browse files
Merge pull request #12 from edwinvdpol/feature/arguments-return-types
Argument- and return typehints
2 parents 2dd38fd + 6d890ca commit 688df6f

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

src/Casts/TimezonedDatetime.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Whitecube\LaravelTimezones\Facades\Timezone;
66
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
77
use Carbon\Carbon;
8+
use Carbon\CarbonInterface;
9+
use Carbon\CarbonTimeZone;
810
use DateTime;
911
use Illuminate\Support\Facades\Config;
1012
use Illuminate\Database\Eloquent\Model;
@@ -39,7 +41,7 @@ public function __construct(?string $format = null)
3941
* @param array $attributes
4042
* @return \Carbon\CarbonInterface
4143
*/
42-
public function get($model, $key, $value, $attributes)
44+
public function get(Model $model, string $key, mixed $value, array $attributes)
4345
{
4446
if(!$value && $value !== 0) {
4547
return null;
@@ -63,7 +65,7 @@ public function get($model, $key, $value, $attributes)
6365
* @param array $attributes
6466
* @return string
6567
*/
66-
public function set($model, $key, $value, $attributes)
68+
public function set(Model $model, string $key, mixed $value, array $attributes)
6769
{
6870
if(!$value && $value !== 0) {
6971
return null;
@@ -98,7 +100,7 @@ protected function isTimestamp(Model $model, string $key): bool
98100
* @param \Illuminate\Database\Eloquent\Model $model
99101
* @return \Carbon\CarbonInterface
100102
*/
101-
public function asDateTime($value, $timezone, $model)
103+
public function asDateTime(mixed $value, CarbonTimeZone $timezone, Model $model): CarbonInterface
102104
{
103105
$date = (new DatetimeParser)->parse($value, $this->format ?? $model->getDateFormat());
104106

src/Concerns/HasTimezonedTimestamps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait HasTimezonedTimestamps
1313
* @param string $key
1414
* @return bool
1515
*/
16-
protected function isDateAttribute($key)
16+
protected function isDateAttribute($key): bool
1717
{
1818
return (in_array($key, $this->getDates(), true) ||
1919
$this->isDateCastable($key)) &&

src/DatetimeParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function parse(mixed $value, ?string $format): CarbonInterface
3434
*
3535
* @return string
3636
*/
37-
public function getDateFormat()
37+
public function getDateFormat(): ?string
3838
{
3939
return $this->format;
4040
}

src/Timezone.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(string $default)
4444
* @param mixed $timezone
4545
* @return void
4646
*/
47-
public function set($timezone = null)
47+
public function set(mixed $timezone = null): void
4848
{
4949
$this->setCurrent($timezone);
5050
}
@@ -55,7 +55,7 @@ public function set($timezone = null)
5555
* @param mixed $timezone
5656
* @return void
5757
*/
58-
public function setCurrent($timezone)
58+
public function setCurrent(mixed $timezone): void
5959
{
6060
$this->current = $this->makeTimezone($timezone);
6161
}
@@ -76,7 +76,7 @@ public function current(): CarbonTimeZone
7676
* @param mixed $timezone
7777
* @return void
7878
*/
79-
public function setStorage($timezone)
79+
public function setStorage(mixed $timezone): void
8080
{
8181
$this->storage = $this->makeTimezone($timezone);
8282
}
@@ -108,7 +108,7 @@ public function now(): CarbonInterface
108108
* @param null|callable $maker
109109
* @return \Carbon\CarbonInterface
110110
*/
111-
public function date($value, callable $maker = null): CarbonInterface
111+
public function date(mixed $value, callable $maker = null): CarbonInterface
112112
{
113113
return $this->makeDateWithCurrent($value, $maker);
114114
}
@@ -120,7 +120,7 @@ public function date($value, callable $maker = null): CarbonInterface
120120
* @param null|callable $maker
121121
* @return \Carbon\CarbonInterface
122122
*/
123-
public function store($value, callable $maker = null): CarbonInterface
123+
public function store(mixed $value, callable $maker = null): CarbonInterface
124124
{
125125
return $this->makeDateWithStorage($value, $maker);
126126
}
@@ -154,7 +154,7 @@ protected function convertToStorage(CarbonInterface $date): CarbonInterface
154154
* @param null|callable $maker
155155
* @return \Carbon\CarbonInterface
156156
*/
157-
protected function makeDateWithCurrent($value, callable $maker = null): CarbonInterface
157+
protected function makeDateWithCurrent(mixed $value, callable $maker = null): CarbonInterface
158158
{
159159
return is_a($value, CarbonInterface::class)
160160
? $this->convertToCurrent($value)
@@ -168,7 +168,7 @@ protected function makeDateWithCurrent($value, callable $maker = null): CarbonIn
168168
* @param null|callable $maker
169169
* @return \Carbon\CarbonInterface
170170
*/
171-
protected function makeDateWithStorage($value, callable $maker = null): CarbonInterface
171+
protected function makeDateWithStorage(mixed $value, callable $maker = null): CarbonInterface
172172
{
173173
return is_a($value, CarbonInterface::class)
174174
? $this->convertToStorage($value)
@@ -183,7 +183,7 @@ protected function makeDateWithStorage($value, callable $maker = null): CarbonIn
183183
* @param null|callable $maker
184184
* @return \Carbon\CarbonInterface
185185
*/
186-
protected function makeDate($value, CarbonTimeZone $timezone, callable $maker = null): CarbonInterface
186+
protected function makeDate(mixed $value, CarbonTimeZone $timezone, callable $maker = null): CarbonInterface
187187
{
188188
return ($maker)
189189
? call_user_func($maker, $value, $timezone)
@@ -196,7 +196,7 @@ protected function makeDate($value, CarbonTimeZone $timezone, callable $maker =
196196
* @param mixed $value
197197
* @return \Carbon\CarbonTimeZone
198198
*/
199-
protected function makeTimezone($value): CarbonTimeZone
199+
protected function makeTimezone(mixed $value): CarbonTimeZone
200200
{
201201
if(! is_a($value, CarbonTimeZone::class)) {
202202
$value = new CarbonTimeZone($value);

0 commit comments

Comments
 (0)