1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenCafe\Tools; |
4
|
|
|
|
5
|
|
|
use OpenCafe\Tools\Lang; |
6
|
|
|
use OpenCafe\Datium; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Calculate Time ago with current date difference |
10
|
|
|
* |
11
|
|
|
* @package OpenCafe\Datium |
12
|
|
|
* @since Jun 17, 2016 |
13
|
|
|
*/ |
14
|
|
|
class SimpleDiff |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Used language to setted for simple difference |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $language; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* class final result |
25
|
|
|
* @var object |
26
|
|
|
*/ |
27
|
|
|
private $result; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private $blockList; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* SimpleDiff Class constructure |
36
|
|
|
* |
37
|
|
|
* @param DateTime $time_difference The time to calculate with now |
|
|
|
|
38
|
|
|
* @param string $lang Language |
|
|
|
|
39
|
|
|
*/ |
40
|
|
|
public function __construct($start, $end, $difference ) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
$this->language = 'en'; |
44
|
|
|
|
45
|
|
|
$this->result = $difference; |
46
|
|
|
|
47
|
|
|
$this->blockList = [ |
48
|
|
|
'just-now' |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Return difference period as an object |
55
|
|
|
* |
56
|
|
|
* @return object |
57
|
|
|
*/ |
58
|
|
|
public function all() |
59
|
|
|
{ |
60
|
|
|
|
61
|
|
|
return $result->result; |
|
|
|
|
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Read ago config file |
67
|
|
|
* |
68
|
|
|
* @param integer $date date index in ago config file |
|
|
|
|
69
|
|
|
* @param string $type duration type on ago config file |
70
|
|
|
*/ |
71
|
|
|
public function read( $value, $type ) |
72
|
|
|
{ |
73
|
|
|
|
74
|
|
|
$config = include __DIR__ . '/config/diff.php'; |
75
|
|
|
|
76
|
|
|
if( $this->result->invert ) { |
77
|
|
|
|
78
|
|
|
$time = ' ' . Lang::get( $this->language, 'remaining' ); |
79
|
|
|
|
80
|
|
|
} else { |
81
|
|
|
|
82
|
|
|
$time = ' ' . Lang::get( $this->language, 'ago' ); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if( isset( $config[ $type ][ $value ] ) && in_array( |
87
|
|
|
|
88
|
|
|
$config[ $type ][ $value ], |
89
|
|
|
|
90
|
|
|
$this->blockList |
91
|
|
|
|
92
|
|
|
) ) { |
93
|
|
|
|
94
|
|
|
$time = null; |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if( array_key_exists( $value, $config[ $type ] ) ) { |
99
|
|
|
|
100
|
|
|
$str = Lang::get( $this->language, $config[ $type ][ $value ] ) |
101
|
|
|
. $time; |
102
|
|
|
|
103
|
|
|
return $str; |
104
|
|
|
|
105
|
|
|
} else { |
106
|
|
|
|
107
|
|
|
return Lang::getNumbers( $this->language, $value ) . " " . Lang::get( |
108
|
|
|
$this->language, |
109
|
|
|
$config[ $type ][ '*' ] |
110
|
|
|
) . $time; |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Show priority of duration |
118
|
|
|
* |
119
|
|
|
* @param integer $date date index in ago config file |
120
|
|
|
* @param string $type duration type on ago config file |
121
|
|
|
*/ |
122
|
|
|
public function priority( $date, $type ) |
123
|
|
|
{ |
124
|
|
|
|
125
|
|
|
if( $date != 0 ) { |
126
|
|
|
|
127
|
|
|
return $this->read( $date, $type ); |
128
|
|
|
|
129
|
|
|
} else { |
130
|
|
|
|
131
|
|
|
return false; |
132
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function lang( $value ) |
138
|
|
|
{ |
139
|
|
|
|
140
|
|
|
$this->language = $value; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Return fainal SimpleDiff result |
148
|
|
|
* |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
|
|
public function get() |
152
|
|
|
{ |
153
|
|
|
|
154
|
|
|
$duration = [ |
155
|
|
|
'year' => $this->result->year, |
156
|
|
|
'month' => $this->result->month, |
157
|
|
|
'day' => $this->result->day, |
158
|
|
|
'hour' => $this->result->hour, |
159
|
|
|
'minute' => $this->result->minute, |
160
|
|
|
'second' => $this->result->second |
161
|
|
|
]; |
162
|
|
|
|
163
|
|
|
foreach( $duration as $index => $value ) { |
164
|
|
|
|
165
|
|
|
if( $this->priority( $value, $index ) != false ) { |
|
|
|
|
166
|
|
|
|
167
|
|
|
return $this->priority( $value, $index ); |
168
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.