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