Passed
Push — master ( 4b0d05...471523 )
by Arthur
103:49 queued 98:11
created

AlterDemoDataJob::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Authorization\Entities\Role;
16
use Modules\Machine\Contracts\MachineServiceContract;
17
use Modules\Machine\Services\MachineService;
18
use Modules\User\Entities\User;
19
20
class AlterDemoDataJob extends Job
21
{
22
    /**
23
     * @var MachineService
24
     */
25
    protected $machineService;
26
27
    /**
28
     * @var AccountService
29
     */
30
    protected $accountService;
31
32
    /**
33
     * @var Auth0ServiceContract
34
     */
35
    protected $userService;
36
37 58
    public function __construct()
38
    {
39 58
        $this->machineService = app()->make(MachineServiceContract::class);
40 58
        $this->accountService = app()->make(AccountServiceContract::class);
41 58
        $this->userService = app()->make(Auth0ServiceContract::class);
42 58
    }
43
44
    public function handle()
45
    {
46
        $this->alterMachineData();
47
    }
48
49
    protected function alterMachineData()
50
    {
51
        foreach ($this->machineService->getByUserId($this->userService->getTestUser(Role::ADMIN)) as $machine) {
52
            $this->machineService->heartbeat($machine, [
53
                'cpu_usage'    => rand(0, 100),
54
                'memory_usage' => rand(1, $machine->memory_available),
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->userService->getTestUser(Role::ADMIN)) as $account) {
63
            $this->accountService->heartbeat($account, [
64
                'cpu_usage'    => rand(0, 100),
65
                'memory_usage' => rand(1, $account->memory_available),
66
            ]);
67
            $this->accountService->update($account, ['online' => (bool) rand(0, 1)]);
68
        }
69
    }
70
}
71