Passed
Push — master ( c13b73...f2713c )
by Arthur
05:06
created

AlterDemoDataJob   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 49
rs 10
c 0
b 0
f 0
ccs 0
cts 15
cp 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A alterMachineData() 0 8 2
A boot() 0 5 1
A alterAccountData() 0 8 2
A handle() 0 4 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\Machine\Contracts\MachineServiceContract;
16
use Modules\Machine\Services\MachineService;
17
use Modules\User\Entities\User;
18
19
class AlterDemoDataJob extends Job
20
{
21
    /**
22
     * @var MachineService
23
     */
24
    protected $machineService;
25
26
    /**
27
     * @var AccountService
28
     */
29
    protected $accountService;
30
31
    /**
32
     * @var User
33
     */
34
    protected $user;
35
36
    public function handle()
37
    {
38
        $this->boot();
39
        $this->alterMachineData();
40
    }
41
42
    protected function boot()
43
    {
44
        $this->machineService = app()->make(MachineServiceContract::class);
45
        $this->accountService = app()->make(AccountServiceContract::class);
46
        $this->user = app()->make(Auth0ServiceContract::class)->getTestUser();
47
    }
48
49
    protected function alterMachineData()
50
    {
51
        foreach ($this->machineService->getByUserId($this->user->id) as $machine) {
52
            $this->machineService->heartbeat($machine, [
53
                'cpu_usage'    => rand(0, 100),
54
                'memory_usage' => rand(1, $machine->memory_available),
0 ignored issues
show
Bug introduced by
The property memory_available does not seem to exist on Modules\Machine\Entities\Machine. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
55
            ]);
56
            $this->machineService->update($machine, ['online' => (bool) rand(0, 1)]);
57
        }
58
    }
59
60
    protected function alterAccountData()
61
    {
62
        foreach ($this->accountService->getByUserId($this->user->id) as $account) {
63
            $this->accountService->heartbeat($account, [
64
                'cpu_usage'    => rand(0, 100),
65
                'memory_usage' => rand(1, $account->memory_available),
0 ignored issues
show
Bug introduced by
The property memory_available does not seem to exist on Modules\Account\Entities\Account. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
66
            ]);
67
            $this->accountService->update($account, ['online' => (bool) rand(0, 1)]);
68
        }
69
    }
70
}
71