Completed
Push — master ( 0f05a9...994973 )
by ARCANEDEV
06:19
created

Expression   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 82
c 0
b 0
f 0
wmc 4
lcom 2
cbo 2
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A offset() 0 7 2
A wrap() 0 4 1
1
<?php namespace Arcanedev\LaravelMetrics\Expressions\TrendDateFormat;
2
3
use Arcanedev\LaravelMetrics\Expressions\Expression as BaseExpression;
4
use Cake\Chronos\Chronos;
5
use DateTime;
6
use DateTimeZone;
7
use Illuminate\Database\Eloquent\Builder;
8
9
/**
10
 * Class     Expression
11
 *
12
 * @package  Arcanedev\LaravelMetrics\Expressions\TrendDateFormat
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
abstract class Expression extends BaseExpression
16
{
17
    /* -----------------------------------------------------------------
18
     |  Properties
19
     | -----------------------------------------------------------------
20
     */
21
22
    /**
23
     * The query builder being used to build the trend.
24
     *
25
     * @var \Illuminate\Database\Query\Builder
26
     */
27
    public $query;
28
29
    /**
30
     * The unit being measured.
31
     *
32
     * @var string
33
     */
34
    public $unit;
35
36
    /**
37
     * The users's local timezone.
38
     *
39
     * @var string
40
     */
41
    public $timezone;
42
43
    /* -----------------------------------------------------------------
44
     |  Constructor
45
     | -----------------------------------------------------------------
46
     */
47
48
    /**
49
     * Create a new raw query expression.
50
     *
51
     * @param  mixed                                  $value
52
     * @param  string                                 $unit
53
     * @param  \Illuminate\Database\Eloquent\Builder  $query
54
     * @param  string                                 $timezone
55
     *
56
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
57
     */
58 168
    public function __construct($value, string $unit, Builder $query, $timezone)
59
    {
60 168
        parent::__construct($value);
61
62 168
        $this->unit     = $unit;
63 168
        $this->query    = $query;
0 ignored issues
show
Documentation Bug introduced by
It seems like $query of type object<Illuminate\Database\Eloquent\Builder> is incompatible with the declared type object<Illuminate\Database\Query\Builder> of property $query.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64 168
        $this->timezone = $timezone;
65 168
    }
66
67
    /* -----------------------------------------------------------------
68
     |  Other Methods
69
     | -----------------------------------------------------------------
70
     */
71
72
    /**
73
     * Get the timezone offset for the user's timezone.
74
     *
75
     * @return int
76
     */
77 168
    public function offset()
78
    {
79 168
        if ($this->timezone)
80 80
            return (new DateTime(Chronos::now()->format('Y-m-d H:i:s'), new DateTimeZone($this->timezone)))->getOffset() / 60 / 60;
81
82 88
        return 0;
83
    }
84
85
    /**
86
     * Wrap the given value using the query's grammar.
87
     *
88
     * @param  string  $value
89
     *
90
     * @return string
91
     */
92 168
    protected function wrap($value)
93
    {
94 168
        return $this->query->getQuery()->getGrammar()->wrap($value);
95
    }
96
}
97