Passed
Branch main (b90ec4)
by Thierry
20:23 queued 14:04
created

ConvertPoolProperties::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
nc 2
nop 0
dl 0
loc 19
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Siak\Tontine\Model\Pool;
7
8
class ConvertPoolProperties extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'pools:convert';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Convert pool properties';
23
24
    /**
25
     * Execute the console command.
26
     *
27
      * @return int
28
     */
29
    public function handle()
30
    {
31
        $pools = Pool::get();
32
        foreach($pools as $pool)
33
        {
34
            $currProperties = $pool->properties;
35
            $nextProperties = ['deposit' => [], 'remit' => []];
36
            $nextProperties['deposit']['fixed'] = $currProperties['deposit']['fixed'] ?? true;
37
            $nextProperties['deposit']['lendable'] = $currProperties['remit']['lendable'] ?? false;
38
            $nextProperties['remit']['planned'] = $currProperties['remit']['planned'] ?? true;
39
            $nextProperties['remit']['auction'] = $currProperties['remit']['auction'] ?? false;
40
41
            $currProperties['deposit'] = $nextProperties['deposit'];
42
            $currProperties['remit'] = $nextProperties['remit'];
43
            $pool->properties = $currProperties;
44
            $pool->save();
45
        }
46
47
        return Command::SUCCESS;
48
    }
49
}
50