Connector   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 120
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getPrimary() 0 4 1
A getConnection() 0 4 1
A setError() 0 9 1
A getError() 0 4 1
A getErrorCode() 0 4 1
A get() 0 7 1
A getCodeForPrimaryKey() 0 11 1
B registerAll() 0 38 6
1
<?php
2
3
namespace Integrations\Connectors;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Log;
7
use App\Models\User;
8
9
use Integrations\Models\Token;
10
use Support\Components\Coders\Parser\ParseClass;
11
use Muleta\Utils\Debugger\ErrorHelper;
12
use Integrations\Models\Integration as IntegrationModel;
13
use ReflectionGenerator;
14
use Exception;
15
use Muleta\Utils\Extratores\ClasserExtractor;
16
use Muleta\Contracts\Output\OutputableTrait;
17
18
class Connector
19
{
20
    use OutputableTrait;
21
22
    protected $_connection = null;
23
24
    protected $_token = null;
25
26
    private $error = null;
27
28
    private $errorCode = null;
29
30
    public function __construct($token = false)
31
    {
32
        $this->_token = $token;
33
        $this->_connection = $this->getConnection($this->_token);
34
    }
35
36
    /**
37
     * Recupera connecção com a integração
38
     */
39
    public static function getPrimary()
40
    {
41
        return static::$ID;
42
    }
43
44
    /**
45
     * Recupera connecção com a integração
46
     */
47
    protected function getConnection($token = false)
48
    {
49
        return $this;
50
    }
51
52
    public function setError($errorMessage, $code = 0)
53
    {
54
        $this->error = $errorMessage;
55
        $this->errorCode = $code;
56
57
        
58
        var_dump($errorMessage);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($errorMessage); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
59
        throw new \Exception($errorMessage);
60
    }
61
62
    public function getError()
63
    {
64
        return $this->error;
65
    }
66
67
    public function getErrorCode()
68
    {
69
        return $this->errorCode;
70
    }
71
72
    /**
73
     * Recupera dados em cima de um get de uma api
74
     */
75
    public function get($path)
76
    {
77
        // @todo Fazer resultar um object em cia de um path
78
        $url = $this->url.$path;
0 ignored issues
show
Unused Code introduced by
$url 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...
79
        $result = [];
80
        return $result;
81
    }
82
83
    /**
84
     * Recupera dados em cima de um get de uma api
85
     */
86
    public static function getCodeForPrimaryKey()
87
    {
88
        $integration = IntegrationModel::createIfNotExistAndReturn(
89
            [
90
            'id' => static::$ID,
91
            'name' => ClasserExtractor::getClassName(static::class),
92
            'code' => static::class,
93
            ]
94
        );
95
        return $integration->id;
96
    }
97
    
98
    public static function registerAll()
99
    {
100
        $realPath = __DIR__.'/';
101
        
102
        collect(scandir($realPath))
103
            ->each(
104
                function ($item) use ($realPath) {
105
                    if (in_array($item, ['.', '..'])) { return;
106
                    }
107
                    if (is_dir($realPath . $item)) {
108
                        $modelName = __NAMESPACE__.'\\'.$item.'\\'.$item;
109
                   
110
                        IntegrationModel::createIfNotExistAndReturn(
111
                            [
112
                            'id' =>  call_user_func(array($modelName, 'getPrimary')),
113
                            'name' => ClasserExtractor::getClassName($modelName),
114
                            'code' => $modelName,
115
                            ]
116
                        );
117
                    }
118
119
                    if (is_file($realPath . $item) && $item!=='Connector.php') {
120
                        Log::channel('sitec-integrations')->warning(
121
                            ErrorHelper::tratarMensagem(
122
                                'Não deveria ter arquivo nessa pasta: '.$realPath . $item
123
                            )
124
                        );
125
126
                        try {
127
                            throw new Exception('Não deveria ter arquivo nessa pasta: '.$realPath . $item);
128
                        } catch(Exception $e) {
129
                            dd('Connector', $e->getTrace(), $e->getMessage(), 'Deu Ruim Integrations');
130
                        }
131
                    
132
                    }
133
                }
134
            );
135
    }
136
137
}
138