Skip to content

Commit 8833338

Browse files
committed
Merge branch 'main' into pr/10
2 parents f3bd302 + b054f40 commit 8833338

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
.DS_Store
44
Thumbs.db
55
composer.lock
6-
.phpunit.result.cache
6+
.phpunit.cache
77
.swp
88
*.map

phpunit.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
colors="true"
6+
cacheDirectory=".phpunit.cache"
67
>
78
<testsuites>
89
<testsuite name="Test Suite">
910
<directory suffix="Test.php">./tests</directory>
1011
</testsuite>
1112
</testsuites>
12-
<coverage processUncoveredFiles="true">
13+
<source>
1314
<include>
1415
<directory suffix=".php">./app</directory>
1516
<directory suffix=".php">./src</directory>
1617
</include>
17-
</coverage>
18+
</source>
1819
</phpunit>

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
@@ -33,7 +33,7 @@ public function parse(mixed $value, ?string $format): CarbonInterface
3333
*
3434
* @return string
3535
*/
36-
public function getDateFormat()
36+
public function getDateFormat(): ?string
3737
{
3838
return $this->format;
3939
}

src/Facades/Timezone.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
use Illuminate\Support\Facades\Facade;
66

7+
/**
8+
* @method static void set(mixed $timezone = null)
9+
* @method static void setCurrent(mixed $timezone = null)
10+
* @method static \Carbon\CarbonTimeZone current()
11+
* @method static void setStorage(mixed $timezone = null)
12+
* @method static \Carbon\CarbonTimeZone storage()
13+
* @method static \Carbon\CarbonInterface now()
14+
* @method static \Carbon\CarbonInterface date(mixed $value, callable|null $maker)
15+
* @method static \Carbon\CarbonInterface store(mixed $value, callable|null $maker)
16+
*/
717
class Timezone extends Facade
818
{
919
/**

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)