|
1
|
|
|
<?php namespace Maqe\Qwatcher\Tracks\Transformers; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Eloquent\Collection; |
|
4
|
|
|
use Maqe\Qwatcher\Tracks\Tracks; |
|
5
|
|
|
use Maqe\Qwatcher\Tracks\Transformers\TrackTransformerInterface; |
|
6
|
|
|
use Illuminate\Pagination\LengthAwarePaginator; |
|
7
|
|
|
|
|
8
|
|
|
class TrackTransformer implements TrackTransformerInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected $sequentialStatus = ['succeed_at', 'failed_at', 'process_at', 'queue_at']; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Transform records in tracks collection |
|
14
|
|
|
* |
|
15
|
|
|
* @param Tracks $tracks The tracks collection |
|
|
|
|
|
|
16
|
|
|
* @return Collection The tracks collection after transform |
|
17
|
|
|
*/ |
|
18
|
|
|
public function transform(Tracks $track) |
|
19
|
|
|
{ |
|
20
|
|
|
$track->meta = ($track->meta) ? json_decode($track->meta) : null; |
|
|
|
|
|
|
21
|
|
|
$track->status = $this->getTrackStatus($track); |
|
|
|
|
|
|
22
|
|
|
$track->statusTime = $this->getTrackStatusTime($track); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
return $track; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Transform records in tracks collection |
|
29
|
|
|
* |
|
30
|
|
|
* @param Collection $tracks The tracks collection |
|
31
|
|
|
* @return Collection The tracks collection after transform |
|
32
|
|
|
*/ |
|
33
|
|
|
public function transforms(Collection $tracks) |
|
34
|
|
|
{ |
|
35
|
|
|
return $tracks->each(function ($track) { |
|
36
|
|
|
$track = $this->transform($track); |
|
|
|
|
|
|
37
|
|
|
}); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Transform records in tracks collection as paginate |
|
42
|
|
|
* |
|
43
|
|
|
* @param Collection $tracks The tracks collection |
|
44
|
|
|
* @return LengthAwarePaginator The tracks LengthAwarePaginator after transform |
|
45
|
|
|
*/ |
|
46
|
|
|
public function transformPaginator(LengthAwarePaginator $tracks) |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
$queryString = []; |
|
49
|
|
|
parse_str($_SERVER['QUERY_STRING'], $queryString); |
|
50
|
|
|
$tracksCollecton = new Collection($tracks->items()); |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
return new LengthAwarePaginator($this->transforms($tracksCollecton), $tracks->total(), $tracks->perPage(), $tracks->currentPage(), ['path' => \URL::current(), 'query' => $queryString]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get current Status as text, tracking by sequential of status datetime |
|
58
|
|
|
* |
|
59
|
|
|
* @param $track The track object |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
View Code Duplication |
public function getTrackStatus($track) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
foreach ($this->sequentialStatus as $status) { |
|
65
|
|
|
if (!is_null($track->{$status})) { |
|
66
|
|
|
return substr($status, 0, -3); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
throw new Exception("Can't find the right column to track the Qwatcher", 1); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get current Status prias text, tracking by sequential of status datetime |
|
75
|
|
|
* |
|
76
|
|
|
* @param $track The track object |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
View Code Duplication |
public function getTrackStatusTime($track) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
foreach ($this->sequentialStatus as $status) { |
|
82
|
|
|
if (!is_null($track->{$status})) { |
|
83
|
|
|
return $track->{$status}; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
throw new Exception("Can't find the right column to track the Qwatcher", 1); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
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
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.