GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 698fd2...95f32c )
by Christian
10:54 queued 08:21
created

IndexHydrateCommand   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 82
ccs 36
cts 36
cp 1
rs 10
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 29 5
A __construct() 0 4 1
A hydrate() 0 20 4
1
<?php
2
3
namespace Omatech\Enigma\Commands;
4
5
use HaydenPierce\ClassFinder\ClassFinder;
6
use Illuminate\Console\Command;
7
use Illuminate\Database\Eloquent\Model;
8
use Omatech\Enigma\Database\Eloquent\HasEnigma;
9
use Omatech\Enigma\Enigma;
10
use Omatech\Enigma\Exceptions\InvalidClassException;
11
12
class IndexHydrateCommand extends Command
13
{
14
    private $enigma;
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'enigma:hydrate { namespace : Fully qualified namespace }';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Rehydrate the indexes given a namespace';
29
30 63
    public function __construct(Enigma $enigma)
31
    {
32 63
        parent::__construct();
33 63
        $this->enigma = $enigma;
34 63
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @param Enigma $enigma
40
     * @return mixed
41
     * @throws InvalidClassException
42
     */
43 8
    public function handle()
44
    {
45 8
        $namespace = $this->argument('namespace');
46 8
        $foundClasses = ClassFinder::getClassesInNamespace($namespace, ClassFinder::RECURSIVE_MODE);
0 ignored issues
show
Bug introduced by
It seems like $namespace can also be of type string[]; however, parameter $namespace of HaydenPierce\ClassFinder...getClassesInNamespace() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $foundClasses = ClassFinder::getClassesInNamespace(/** @scrutinizer ignore-type */ $namespace, ClassFinder::RECURSIVE_MODE);
Loading history...
47
48 8
        $classes = [];
49 8
        foreach ($foundClasses as $class) {
50 8
            if (isset(class_uses($class)[HasEnigma::class]) === true) {
51 8
                $classes[] = $class;
52
            }
53
        }
54
55 8
        $choice = (array) $this->choice(
56 8
            'Which models would you like to hydrate?',
57 8
            array_merge([0 => 'All'], $classes),
58 8
            0,
59 8
            null,
60 8
            true
61
        );
62
63 8
        if (array_search('All', $choice) !== false) {
64 4
            $choice = $classes;
65
        }
66
67 8
        foreach ($choice as $class) {
68 8
            $this->hydrate(new $class);
69
        }
70
71 4
        $this->info('The index hydratation has been finished.');
72 4
    }
73
74 8
    private function hydrate(Model $model)
75
    {
76 8
        $enigmaEncryptable = $model->getEnigmaEncryptable();
77
78 8
        $this->info(get_class($model)."\n");
79 8
        $bar = $this->output->createProgressBar($model::count());
0 ignored issues
show
Bug introduced by
It seems like $model::count() can also be of type Illuminate\Database\Eloquent\Builder; however, parameter $max of Symfony\Component\Consol...le::createProgressBar() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
        $bar = $this->output->createProgressBar(/** @scrutinizer ignore-type */ $model::count());
Loading history...
80 8
        $bar->start();
81
82
        $model::chunk(100, function ($rows) use ($enigmaEncryptable, $bar) {
83 8
            foreach ($rows as $row) {
84 8
                foreach ($enigmaEncryptable as $column) {
85 8
                    if ($row->{$column} !== null) {
86 8
                        $this->enigma->hydrateAsModel($row, $column, $row->{$column});
87
                    }
88
                }
89 8
                $bar->advance();
90
            }
91 8
        });
92 8
        $bar->finish();
93 8
        $this->info("\n");
94 8
    }
95
}
96