Passed
Pull Request — master (#35)
by
unknown
02:49
created

Timezone::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 4
1
<?php
2
3
namespace JamesMills\LaravelTimezone\Casts;
4
5
use Carbon\Carbon;
6
use Exception;
7
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Dat...loquent\CastsAttributes was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Illuminate\Database\Eloquent\Model;
9
use JamesMills\LaravelTimezone\Facades\Timezone as TimezoneFacade;
10
use JamesMills\LaravelTimezone\Traits\TimezoneTrait;
11
12
class Timezone implements CastsAttributes
13
{
14
    use TimezoneTrait;
15
    /**
16
     * Transform the attribute from the underlying model values.
17
     *
18
     * @param  Model  $model
19
     * @param  string  $key
20
     * @param  mixed  $value
21
     * @param  array  $attributes
22
     * @return Carbon
23
     * @throws Exception
24
     */
25
    public function get($model, string $key, $value, array $attributes)
26
    {
27
        return Carbon::parse($value)
28
            ->setTimezone($this->getUserTimezone());
29
    }
30
31
    /**
32
     * Transform the attribute to its underlying model values.
33
     *
34
     * @param  Model  $model
35
     * @param  string  $key
36
     * @param  mixed  $value
37
     * @param  array  $attributes
38
     * @return Carbon
39
     */
40
    public function set($model, string $key, $value, array $attributes)
41
    {
42
        return TimezoneFacade::convertFromLocal($value);
0 ignored issues
show
Bug introduced by
The method convertFromLocal() does not exist on JamesMills\LaravelTimezone\Facades\Timezone. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        return TimezoneFacade::/** @scrutinizer ignore-call */ convertFromLocal($value);
Loading history...
43
    }
44
}
45