Passed
Push — master ( b4b8e8...3089dd )
by Arthur
26:17 queued 02:28
created

AlterDemoDataJob   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 23.81%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 50
ccs 5
cts 21
cp 0.2381
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A alterMachineData() 0 8 2
A alterAccountData() 0 8 2
A __construct() 0 5 1
A handle() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 28.10.18
6
 * Time: 17:25.
7
 */
8
9
namespace Modules\Demo\Jobs;
10
11
use Foundation\Abstracts\Jobs\Job;
12
use Modules\Account\Contracts\AccountServiceContract;
13
use Modules\Account\Services\AccountService;
14
use Modules\Auth0\Contracts\Auth0ServiceContract;
15
use Modules\Auth0\Services\Auth0Service;
16
use Modules\Auth0\Traits\Auth0TestUser;
17
use Modules\Machine\Contracts\MachineServiceContract;
18
use Modules\Machine\Services\MachineService;
19
20
class AlterDemoDataJob extends Job
21
{
22
    use Auth0TestUser;
0 ignored issues
show
Bug introduced by
The trait Modules\Auth0\Traits\Auth0TestUser requires the property $id_token which is not provided by Modules\Demo\Jobs\AlterDemoDataJob.
Loading history...
23
24
    /**
25
     * @var MachineService
26
     */
27
    protected $machineService;
28
29
    /**
30
     * @var AccountService
31
     */
32
    protected $accountService;
33
34
    /**
35
     * @var Auth0Service
36
     */
37
    protected $userService;
38
39 90
    public function __construct()
40
    {
41 90
        $this->machineService = app()->make(MachineServiceContract::class);
42 90
        $this->accountService = app()->make(AccountServiceContract::class);
43 90
        $this->userService = app()->make(Auth0ServiceContract::class);
44 90
    }
45
46
    public function handle()
47
    {
48
        $this->alterMachineData();
49
    }
50
51
    protected function alterMachineData()
52
    {
53
        foreach ($this->machineService->getByUserId($this->getTestUser()->id) as $machine) {
54
            $this->machineService->heartbeat($machine, [
55
                'cpu_usage'    => rand(0, 100),
56
                'memory_usage' => rand(1, $machine->memory_available),
57
            ]);
58
            $this->machineService->update($machine, ['online' => (bool) rand(0, 1)]);
59
        }
60
    }
61
62
    protected function alterAccountData()
63
    {
64
        foreach ($this->accountService->getByUserId($this->getTestUser()->id) as $account) {
65
            $this->accountService->heartbeat($account, [
66
                'cpu_usage'    => rand(0, 100),
67
                'memory_usage' => rand(1, $account->memory_available),
68
            ]);
69
            $this->accountService->update($account, ['online' => (bool) rand(0, 1)]);
70
        }
71
    }
72
}
73