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

AlterDemoDataJob::alterAccountData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 6
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