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
|
|
|
/** |
11
|
|
|
* Transform records in tracks collection |
12
|
|
|
* |
13
|
|
|
* @param Tracks $tracks The tracks collection |
|
|
|
|
14
|
|
|
* @return Collection The tracks collection after transform |
15
|
|
|
*/ |
16
|
|
|
public function transform(Tracks $track) |
17
|
|
|
{ |
18
|
|
|
$track->meta = ($track->meta) ? json_decode($track->meta) : null; |
|
|
|
|
19
|
|
|
$track->status = $this->getTrackStatus($track); |
|
|
|
|
20
|
|
|
$track->statusTime = $this->getTrackStatusTime($track); |
|
|
|
|
21
|
|
|
|
22
|
|
|
return $track; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Transform records in tracks collection |
27
|
|
|
* |
28
|
|
|
* @param Collection $tracks The tracks collection |
29
|
|
|
* @return Collection The tracks collection after transform |
30
|
|
|
*/ |
31
|
|
|
public function transforms(Collection $tracks) |
32
|
|
|
{ |
33
|
|
|
return $tracks->each(function ($track) { |
34
|
|
|
$track = $this->transform($track); |
|
|
|
|
35
|
|
|
}); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Transform records in tracks collection as paginate |
40
|
|
|
* |
41
|
|
|
* @param Collection $tracks The tracks collection |
42
|
|
|
* @return LengthAwarePaginator The tracks LengthAwarePaginator after transform |
43
|
|
|
*/ |
44
|
|
|
public function transformPaginator(LengthAwarePaginator $tracks) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$queryString = []; |
47
|
|
|
parse_str($_SERVER['QUERY_STRING'], $queryString); |
48
|
|
|
$tracksCollecton = new Collection($tracks->items()); |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
return new LengthAwarePaginator($this->transforms($tracksCollecton), $tracks->total(), $tracks->perPage(), $tracks->currentPage(), ['path' => \URL::current(), 'query' => $queryString]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get current Status as text, tracking by sequential of status datetime |
56
|
|
|
* |
57
|
|
|
* @param $track The track object |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function getTrackStatus($track) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$sequentialStatus = ['failed_at', 'succeed_at', 'process_at', 'queue_at']; |
63
|
|
|
|
64
|
|
|
foreach ($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
|
|
|
$sequentialStatus = ['failed_at', 'succeed_at', 'process_at', 'queue_at']; |
82
|
|
|
|
83
|
|
|
foreach ($sequentialStatus as $status) { |
84
|
|
|
if (!is_null($track->{$status})) { |
85
|
|
|
return $track->{$status}; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
throw new Exception("Can't find the right column to track the Qwatcher", 1); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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.