Passed
Pull Request — master (#35)
by
unknown
05:29 queued 02:20
created

Timezone   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 1
b 0
f 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 3 1
A get() 0 4 1
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
    /**
17
     * Transform the attribute from the underlying model values.
18
     *
19
     * @param  Model  $model
20
     * @param  string  $key
21
     * @param  mixed  $value
22
     * @param  array  $attributes
23
     * @return Carbon
24
     * @throws Exception
25
     */
26
    public function get($model, string $key, $value, array $attributes)
27
    {
28
        return Carbon::parse($value)
29
            ->setTimezone($this->getUserTimezone());
30
    }
31
32
    /**
33
     * Transform the attribute to its underlying model values.
34
     *
35
     * @param  Model  $model
36
     * @param  string  $key
37
     * @param  mixed  $value
38
     * @param  array  $attributes
39
     * @return Carbon
40
     */
41
    public function set($model, string $key, $value, array $attributes)
42
    {
43
        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

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