Completed
Push — master ( 6ffd4c...f02542 )
by Ricardo
02:35
created

Import::issuesWithPager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Integrations\Connectors\Gitlab;
4
5
use Log;
6
use App\Models\User;
7
use Fabrica\Models\Code\Project;
8
use Fabrica\Bundle\CoreBundle\EventDispatcher\FabricaEvents;
9
use Fabrica\Bundle\CoreBundle\EventDispatcher\Event\ProjectEvent;
10
11
/**
12
 * https://github.com/GitLabPHP/Client/blob/9.18/lib/Gitlab/Api/Projects.php
13
 */
14
class Import extends Gitlab
15
{
16
    public function handle($output = false)
17
    {
18
        $this->projects($output);
19
    }
20
    
21
    public function projects($output)
22
    {
23
        $projects = $this->_connection->api('projects')->all([
24
            'owned' => true
25
        ]);
26
27
        foreach ($projects as $project) {
28
            try {
29
                if (!$projectModel = Project::where(['projectPathKey' => $project['path_with_namespace']])->first()) {
30
                    $this->info('Importando Projeto: '.$project['path_with_namespace']);
31
                    $projectModel = new Project();
32
                    $projectModel->setName($project['name']);
33
                    $projectModel->setSlug($project['path_with_namespace']);
34
            
35
                    $projectModel->save();
36
            
37
                    $event = new ProjectEvent($projectModel);
38
                    event($event);
39
                }
40
41
            } catch (\Throwable $th) {
42
                
43
                dd(
44
                    'ImportGitlab',
45
                    $project,
46
                    $project['name'],
47
                    $project['path_with_namespace'],
48
                    $th->getMessage()
49
                );
50
            }
51
        }
52
    }
53
    public function issuesWithPager($output)
54
    {
55
        $pager = new \Gitlab\ResultPager($this->_connection);
56
        $issues = $pager->fetchAll($client->issues(), 'all', [null, ['state' => 'closed']]);
0 ignored issues
show
Bug introduced by
The variable $client does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Unused Code introduced by
$issues is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
58
        // @todo
59
    }
60
}
61