Passed
Push — master ( 1fd74f...a7048c )
by Dan Michael O.
03:15
created

SyncUsers::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\User;
6
use Illuminate\Console\Command;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
use Scriptotek\Alma\Client as AlmaClient;
0 ignored issues
show
Bug introduced by
The type Scriptotek\Alma\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class SyncUsers extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'bibrex:sync-users';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Sync all users';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @param AlmaClient $alma
30
     */
31
    public function __construct(AlmaClient $alma)
32
    {
33
        parent::__construct();
34
        $this->alma = $alma;
0 ignored issues
show
Bug Best Practice introduced by
The property alma does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
    }
36
37
    /**
38
     * Update a single user
39
     *
40
     * @param User $user
41
     */
42
    protected function processUser(User $user)
43
    {
44
        echo " - $user->name: ";
45
46
        if ($user->in_alma) {
47
            if ($user->updateFromAlma($this->alma)) {
48
                if ($user->isDirty()) {
49
                    \Log::info(sprintf(
50
                        'Oppdaterte brukeren <a href="%s">%s</a> fra Alma.',
51
                        action('UsersController@getShow', $user->id),
0 ignored issues
show
Bug introduced by
The function action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

51
                        /** @scrutinizer ignore-call */ 
52
                        action('UsersController@getShow', $user->id),
Loading history...
52
                        $user->name
53
                    ));
54
55
                    $this->info('oppdatert');
56
                } else {
57
                    $this->line('ingen endringer');
58
                }
59
            } else {
60
                \Log::info(sprintf(
61
                    'Brukeren <a href="%s">%s</a> ble ikke lenger funnet i Alma!',
62
                    action('UsersController@getShow', $user->id),
63
                    $user->name
64
                ));
65
66
                $this->warn('ikke i Alma lenger');
67
            }
68
        } else {
69
            if ($user->updateFromAlma($this->alma)) {
70
                \Log::info(sprintf(
71
                    'Lenket brukeren <a href="%s">%s</a> til en Alma-bruker.',
72
                    action('UsersController@getShow', $user->id),
73
                    $user->name
74
                ));
75
76
                $this->info('lenket til Alma-bruker');
77
            } else {
78
                $this->line('ikke i Alma');
79
            }
80
        }
81
        $user->save();
82
    }
83
84
    /**
85
     * Execute the console command.
86
     *
87
     * @return mixed
88
     */
89
    public function handle()
90
    {
91
        foreach (User::get() as $user) {
92
            $this->processUser($user);
93
        }
94
    }
95
}
96