Skip to content

Commit bed4b8a

Browse files
Merge pull request #10 from edwinvdpol/feature/consistent-docblocks
Consistent docblocks
2 parents b054f40 + 0412039 commit bed4b8a

File tree

7 files changed

+21
-116
lines changed

7 files changed

+21
-116
lines changed

src/Casts/ImmutableTimezonedDatetime.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@
22

33
namespace Whitecube\LaravelTimezones\Casts;
44

5+
use Illuminate\Database\Eloquent\Model;
6+
57
class ImmutableTimezonedDatetime extends TimezonedDatetime
68
{
79
/**
810
* Cast the given value.
9-
*
10-
* @param \Illuminate\Database\Eloquent\Model $model
11-
* @param string $key
12-
* @param mixed $value
13-
* @param array $attributes
14-
* @return array
1511
*/
16-
public function get($model, $key, $value, $attributes)
12+
public function get(Model $model, string $key, mixed $value, array $attributes)
1713
{
1814
if($date = parent::get($model, $key, $value, $attributes)) {
1915
return $date->toImmutable();

src/Casts/TimezonedDatetime.php

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@
1515
class TimezonedDatetime implements CastsAttributes
1616
{
1717
/**
18-
* A developer-specific format to use for string parsing
19-
*
20-
* @var null|string
18+
* A developer-specific format to use for string parsing.
2119
*/
2220
protected ?string $format;
2321

2422
/**
2523
* Create a new casting instance.
26-
*
27-
* @param null|string $format
28-
* @return void
2924
*/
3025
public function __construct(?string $format = null)
3126
{
@@ -35,10 +30,6 @@ public function __construct(?string $format = null)
3530
/**
3631
* Cast the given value.
3732
*
38-
* @param \Illuminate\Database\Eloquent\Model $model
39-
* @param string $key
40-
* @param mixed $value
41-
* @param array $attributes
4233
* @return \Carbon\CarbonInterface
4334
*/
4435
public function get(Model $model, string $key, mixed $value, array $attributes)
@@ -50,19 +41,15 @@ public function get(Model $model, string $key, mixed $value, array $attributes)
5041
if ($this->isTimestamp($model, $key)) {
5142
$value = Carbon::parse($value)->format($this->format ?? $model->getDateFormat());
5243
}
53-
44+
5445
$original = Timezone::store($value, fn($raw, $tz) => $this->asDateTime($raw, $tz, $model));
5546

5647
return Timezone::date($original);
5748
}
58-
49+
5950
/**
6051
* Prepare the given value for storage.
6152
*
62-
* @param \Illuminate\Database\Eloquent\Model $model
63-
* @param string $key
64-
* @param mixed $value
65-
* @param array $attributes
6653
* @return string
6754
*/
6855
public function set(Model $model, string $key, mixed $value, array $attributes)
@@ -81,24 +68,15 @@ public function set(Model $model, string $key, mixed $value, array $attributes)
8168
}
8269

8370
/**
84-
* Check if the given key is part of the model's known timestamps
85-
*
86-
* @param Model $model
87-
* @param string $key
88-
* @return bool
71+
* Check if the given key is part of the model's known timestamps.
8972
*/
9073
protected function isTimestamp(Model $model, string $key): bool
9174
{
9275
return $model->usesTimestamps() && in_array($key, $model->getDates());
9376
}
94-
77+
9578
/**
96-
* Create a new date value from raw material
97-
*
98-
* @param mixed $value
99-
* @param Carbon\CarbonTimeZone $timezone
100-
* @param \Illuminate\Database\Eloquent\Model $model
101-
* @return \Carbon\CarbonInterface
79+
* Create a new date value from raw material.
10280
*/
10381
public function asDateTime(mixed $value, CarbonTimeZone $timezone, Model $model): CarbonInterface
10482
{
@@ -112,15 +90,11 @@ public function asDateTime(mixed $value, CarbonTimeZone $timezone, Model $model)
11290
}
11391

11492
/**
115-
* Check if the provided value contains timezone information
116-
*
117-
* @param mixed $value
118-
* @return bool
93+
* Check if the provided value contains timezone information.
11994
*/
12095
protected function hasTimezone(mixed $value): bool
12196
{
12297
return (is_string($value) && array_key_exists('zone', date_parse($value)))
12398
|| (is_a($value, DateTime::class) && $value->getTimezone());
12499
}
125-
126100
}

src/Concerns/HasTimezonedTimestamps.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,16 @@ trait HasTimezonedTimestamps
99
{
1010
/**
1111
* Determine if the given attribute is a date or date castable.
12-
*
13-
* @param string $key
14-
* @return bool
1512
*/
16-
protected function isDateAttribute($key): bool
13+
protected function isDateAttribute(string $key): bool
1714
{
1815
return (in_array($key, $this->getDates(), true) ||
1916
$this->isDateCastable($key)) &&
2017
! $this->hasTimezonedDatetimeCast($key);
2118
}
2219

2320
/**
24-
* Check if key is a timezoned datetime cast
25-
*
26-
* @param string $key
27-
* @return bool
21+
* Check if key is a timezoned datetime cast.
2822
*/
2923
protected function hasTimezonedDatetimeCast(string $key): bool
3024
{
@@ -37,8 +31,8 @@ protected function hasTimezonedDatetimeCast(string $key): bool
3731
$castClassName = explode(':', $cast)[0];
3832

3933
return in_array(
40-
$castClassName,
34+
$castClassName,
4135
[TimezonedDatetime::class, ImmutableTimezonedDatetime::class]
4236
);
4337
}
44-
}
38+
}

src/DatetimeParser.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@ class DatetimeParser
1010
use HasAttributes;
1111

1212
/**
13-
* The model's date storage format
13+
* The model's date storage format.
1414
*/
1515
protected ?string $format;
1616

1717
/**
18-
* Parse the value into a carbon instance
19-
*
20-
* @param mixed $value
21-
* @param null|string $format
22-
* @return CarbonInterface
18+
* Parse the value into a carbon instance.
2319
*/
2420
public function parse(mixed $value, ?string $format): CarbonInterface
2521
{
@@ -28,11 +24,8 @@ public function parse(mixed $value, ?string $format): CarbonInterface
2824
return $this->asDateTime($value);
2925
}
3026

31-
3227
/**
3328
* Get the format for database stored dates.
34-
*
35-
* @return string
3629
*/
3730
public function getDateFormat(): ?string
3831
{

src/Facades/Timezone.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ class Timezone extends Facade
1818
{
1919
/**
2020
* Get the registered name of the component.
21+
*
22+
* @return string
2123
*/
22-
public static function getFacadeAccessor(): string
24+
public static function getFacadeAccessor()
2325
{
2426
return \Whitecube\LaravelTimezones\Timezone::class;
2527
}

src/ServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class ServiceProvider extends BaseServiceProvider
99
{
1010
/**
1111
* Register any application services.
12-
*
13-
* @return void
1412
*/
1513
public function register()
1614
{

src/Timezone.php

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,16 @@ class Timezone
1212
use Macroable;
1313

1414
/**
15-
* The app's current display & manipulation timezone
16-
*
17-
* @var \Carbon\CarbonTimeZone
15+
* The app's current display & manipulation timezone.
1816
*/
1917
protected CarbonTimeZone $current;
2018
/**
21-
* The app's current storage timezone
22-
*
23-
* @var \Carbon\CarbonTimeZone
19+
* The app's current storage timezone.
2420
*/
2521
protected CarbonTimeZone $storage;
2622

2723
/**
2824
* Create a new singleton instance.
29-
*
30-
* @param string $default
31-
* @return void
3225
*/
3326
public function __construct(string $default)
3427
{
@@ -40,9 +33,6 @@ public function __construct(string $default)
4033
* @alias setCurrent
4134
*
4235
* Set the current application timezone.
43-
*
44-
* @param mixed $timezone
45-
* @return void
4636
*/
4737
public function set(mixed $timezone = null): void
4838
{
@@ -51,9 +41,6 @@ public function set(mixed $timezone = null): void
5141

5242
/**
5343
* Set the current application timezone.
54-
*
55-
* @param mixed $timezone
56-
* @return void
5744
*/
5845
public function setCurrent(mixed $timezone): void
5946
{
@@ -62,8 +49,6 @@ public function setCurrent(mixed $timezone): void
6249

6350
/**
6451
* Return the current application timezone.
65-
*
66-
* @return \Carbon\CarbonTimeZone
6752
*/
6853
public function current(): CarbonTimeZone
6954
{
@@ -72,9 +57,6 @@ public function current(): CarbonTimeZone
7257

7358
/**
7459
* Set the current database timezone.
75-
*
76-
* @param mixed $timezone
77-
* @return void
7860
*/
7961
public function setStorage(mixed $timezone): void
8062
{
@@ -83,8 +65,6 @@ public function setStorage(mixed $timezone): void
8365

8466
/**
8567
* Return the current application timezone.
86-
*
87-
* @return \Carbon\CarbonTimeZone
8868
*/
8969
public function storage(): CarbonTimeZone
9070
{
@@ -93,8 +73,6 @@ public function storage(): CarbonTimeZone
9373

9474
/**
9575
* Get the current timezoned date.
96-
*
97-
* @return \Carbon\CarbonInterface
9876
*/
9977
public function now(): CarbonInterface
10078
{
@@ -103,10 +81,6 @@ public function now(): CarbonInterface
10381

10482
/**
10583
* Configure given date for the application's current timezone.
106-
*
107-
* @param mixed $value
108-
* @param null|callable $maker
109-
* @return \Carbon\CarbonInterface
11084
*/
11185
public function date(mixed $value, callable $maker = null): CarbonInterface
11286
{
@@ -115,10 +89,6 @@ public function date(mixed $value, callable $maker = null): CarbonInterface
11589

11690
/**
11791
* Configure given date for the database storage timezone.
118-
*
119-
* @param mixed $value
120-
* @param null|callable $maker
121-
* @return \Carbon\CarbonInterface
12292
*/
12393
public function store(mixed $value, callable $maker = null): CarbonInterface
12494
{
@@ -127,9 +97,6 @@ public function store(mixed $value, callable $maker = null): CarbonInterface
12797

12898
/**
12999
* Duplicate the given date and shift its timezone to the application's current timezone.
130-
*
131-
* @param \Carbon\CarbonInterface
132-
* @return \Carbon\CarbonInterface
133100
*/
134101
protected function convertToCurrent(CarbonInterface $date): CarbonInterface
135102
{
@@ -138,9 +105,6 @@ protected function convertToCurrent(CarbonInterface $date): CarbonInterface
138105

139106
/**
140107
* Duplicate the given date and shift its timezone to the database's storage timezone.
141-
*
142-
* @param \Carbon\CarbonInterface
143-
* @return \Carbon\CarbonInterface
144108
*/
145109
protected function convertToStorage(CarbonInterface $date): CarbonInterface
146110
{
@@ -149,10 +113,6 @@ protected function convertToStorage(CarbonInterface $date): CarbonInterface
149113

150114
/**
151115
* Create or configure date using the application's current timezone.
152-
*
153-
* @param mixed $value
154-
* @param null|callable $maker
155-
* @return \Carbon\CarbonInterface
156116
*/
157117
protected function makeDateWithCurrent(mixed $value, callable $maker = null): CarbonInterface
158118
{
@@ -163,10 +123,6 @@ protected function makeDateWithCurrent(mixed $value, callable $maker = null): Ca
163123

164124
/**
165125
* Create or configure date using the database's storage timezone.
166-
*
167-
* @param mixed $value
168-
* @param null|callable $maker
169-
* @return \Carbon\CarbonInterface
170126
*/
171127
protected function makeDateWithStorage(mixed $value, callable $maker = null): CarbonInterface
172128
{
@@ -177,11 +133,6 @@ protected function makeDateWithStorage(mixed $value, callable $maker = null): Ca
177133

178134
/**
179135
* Create a date using the provided timezone.
180-
*
181-
* @param mixed $value
182-
* @param \Carbon\CarbonTimeZone $timezone
183-
* @param null|callable $maker
184-
* @return \Carbon\CarbonInterface
185136
*/
186137
protected function makeDate(mixed $value, CarbonTimeZone $timezone, callable $maker = null): CarbonInterface
187138
{
@@ -192,9 +143,6 @@ protected function makeDate(mixed $value, CarbonTimeZone $timezone, callable $ma
192143

193144
/**
194145
* Create a Carbon timezone from given value.
195-
*
196-
* @param mixed $value
197-
* @return \Carbon\CarbonTimeZone
198146
*/
199147
protected function makeTimezone(mixed $value): CarbonTimeZone
200148
{

0 commit comments

Comments
 (0)