Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 15 |
DockerAbstract | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 15 |
run | n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||||
save | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
update | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 8 |
|||
removeOldData | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\DockerScale\Retriever\Providers; |
4 | |
5 | use Illuminate\Support\Facades\Log; |
6 | |
7 | abstract class DockerAbstract implements DockerInterface |
8 | { |
9 | use DockerCmdTrait; |
10 | |
11 | protected $model = ''; |
12 | |
13 | protected $matchUpdate = []; |
14 | |
15 | abstract public function run(); |
16 | |
17 | protected function save(array $data) |
18 | { |
19 | try { |
20 | return $this->model::create($data); |
21 | } catch (\Exception $e) { |
22 | Log::debug('Unable to save ' . $this->model . ' : ' . var_export([$e->getMessage(), $data], true)); |
23 | return []; |
24 | } |
25 | } |
26 | |
27 | protected function update(array $data) |
28 | { |
29 | try { |
30 | $matchThese = []; |
31 | foreach ($data as $key => $value) { |
32 | if (in_array($key, $this->matchUpdate)) { |
33 | $matchThese[$key] = $value; |
34 | } |
35 | } |
36 | |
37 | return $this->model::updateOrCreate($matchThese,$data); |
38 | } catch (\Exception $e) { |
39 | Log::debug('Unable to update ' . $this->model . ' : ' . var_export([$e->getMessage(), $data], true)); |
40 | return []; |
41 | } |
42 | } |
43 | |
44 | protected function removeOldData() |
45 | { |
46 | $weekAgo = (new \DateTime('-1 week'))->format('Y-m-d H:i:s'); |
47 | $this->model::where('updated_at', '<=', $weekAgo)->delete(); |
48 | } |
49 | } |