Completed
Push — master ( c8cc17...80abe0 )
by Ricardo
01:25
created

PersonService::import()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.9297
c 0
b 0
f 0
cc 6
nc 32
nop 1
1
<?php
2
3
namespace Telefonica\Services;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Facades\Config;
7
use Informate\Models\Refund;
8
use SierraTecnologia\Crypto\Services\Crypto;
9
use Telefonica\Repositories\PersonRepository;
10
use Telefonica\Models\Actors\Person;
11
use Muleta\Utils\Modificators\StringModificator;
12
13
class PersonService
14
{
15
    public function __construct(
16
        PersonRepository $personRepository
17
    ) {
18
        $this->repo = $personRepository;
0 ignored issues
show
Bug introduced by
The property repo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    /**
22
     * @todo Terminar de Fazer
23
     *  "Nome Artístico/ apelido" => ""                                                                                                                                                                                                             
24
  "Nome Completo" => "Paulo Gonçalves Júnior "                                                                                                                                                                                                
25
  "Nascimento " => "01/07/1988"                                                                                                                                                                                                               
26
  "Idade" => "32 anos "                                                                                                                                                                                                                       
27
  "Sexo / Identificação de Gênero" => "Masculino"                                                                                                                                                                                             
28
  "Endereço Completo" => "Rua Mercúrio 479 Casa 1"                                                                                                                                                                                            
29
  "Bairro" => "Pavuna "                                                                                                                                                                                                                       
30
  "Cidade" => "Rio de Janeiro "                                                                                                                                                                                                               
31
  "Telefone que mais usa" => "21982899701"                                                                                                                                                                                                    
32
  "Profissão" => "Produtor Cultural e Dançarino"                                                                                                                                                                                              
33
  "Grau de Escolaridade" => "Segundo Grau Completo (5ª a 3ºano)"                                                                                                                                                                              
34
  "Curso técnico? " => " Gestão Cultural Pela Instituição Idea e Produção Cultural Pela Produtora Burburinho Cultural  ( Em Andamento)"                                                                                                       
35
  "Fala Inglês?" => "Entendo um Pouco"                                                                                                                                                                                                        
36
  "Fala Espanhol?" => "Entendo um Pouco"                                                                                                                                                                                                      
37
  "Fala Francês?" => "Nada"                                                                                                                                                                                                                   
38
  "Fala Alemão?" => "Nada"                                                                                                                                                                                                                    
39
  "Você tem DRT? " => "Não "                                                                                                                                                                                                                  
40
  " RG" => "21.551.582-6"                                                                                                                                                                                                                     
41
  "CPF" => "133.546.337-27"                                                                                                                                                                                                                   
42
  "Você tem MEI? " => "Não "                                                                                                                                                                                                                  
43
  "Agência e conta" => "Agência:0001 Conta Corrente: 20939021-8  Banco: Nubank "                                                                                                                                                              
44
  " PIX" => "Pix: 133.546.337-27"
45
  "Cargos na RUA?" => "Produção Executiva, Dançarina(o)"
46
  "Peso?" => "80 kg"
47
  "Calça?" => "Tamanho G"
48
  " Blusa?" => "Tamanho G"
49
  "Altura?" => "1.68"
50
  "Nº sapato?" => "Numeração  40"
51
  "Redes Sociais." => "Estou no Instagram como @lilp_king. Instale o aplicativo para seguir minhas fotos e vídeos. https://www.instagram.com/invites/contact/?i=g0zjwr5kwk4h&utm_content=wedbxz"
52
53
     */
54
    public static function import($data)
55
    {   
56
        $registerData = [];
57
        if (isset($data['Nome'])) {
58
            $registerData['name'] = $data["Nome"];
59
        }
60
        if (isset($data['Nome Completo'])) {
61
            $registerData['name'] = $data["Nome Completo"];
62
        }
63
        if (isset($data['CPF'])) {
64
            $registerData['cpf'] = $data["CPF"];
65
        }
66
        if (isset($data['Nascimento'])) {
67
            $registerData['birthday'] = $data["Nascimento"];
68
        }
69
        $code = $registerData['code'] = StringModificator::cleanCodeSlug($registerData['name']);
70
71
        if (\Telefonica\Models\Actors\Person::find($code)) {
72
            return true;
73
        }
74
        $person = Person::createIfNotExistAndReturn($registerData);
0 ignored issues
show
Unused Code introduced by
$person 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...
75
        return true;
76
    }
77
78
    /**
79
     * Get all Persons.
80
     *
81
     * @return Collection
82
     */
83
    public function all()
84
    {
85
        return $this->repo->all();
86
    }
87
88
    /**
89
     * Get all Persons.
90
     *
91
     * @return Illuminate\Pagination\LengthAwarePaginator
92
     */
93
    public function paginated()
94
    {
95
        return $this->repo->paginated(\Illuminate\Support\Facades\Config::get('siravel.pagination', 25));
96
    }
97
98
    /**
99
     * Find the Person by ID.
100
     *
101
     * @param int $id
102
     *
103
     * @return Persons
104
     */
105
    public function find($id)
106
    {
107
        return $this->repo->find($id);
108
    }
109
110
    /**
111
     * Search the orders.
112
     *
113
     * @param array $payload
114
     *
115
     * @return Collection
116
     */
117
    public function search($payload)
118
    {
119
        return $this->repo->search($payload, \Illuminate\Support\Facades\Config::get('siravel.pagination', 25));
120
    }
121
122
    /**
123
     * Create an order.
124
     *
125
     * @param array $payload
126
     *
127
     * @return Persons
128
     */
129
    public function create($payload)
130
    {
131
        $order = $this->repo->store($payload);
132
133
        $this->logistics->orderCreated($order);
0 ignored issues
show
Bug introduced by
The property logistics does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
134
135
        return $order;
136
    }
137
138
    /**
139
     * Update an order.
140
     *
141
     * @param int   $id
142
     * @param array $payload
143
     *
144
     * @return Persons
145
     */
146
    public function update($id, $payload)
147
    {
148
        $order = $this->find($id);
149
150
        if (isset($payload['is_shipped']) && $payload['is_shipped'] !== false) {
151
            $this->logistics->shipPerson($order);
152
        }
153
154
        return $this->repo->update($order, $payload);
155
    }
156
157
    /**
158
     * Cancel an order.
159
     *
160
     * @param int $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
161
     *
162
     * @return Persons
163
     */
164
    public function cancel($orderId)
165
    {
166
        $order = $this->repo->find($orderId);
167
168
        if ($order->status != 'complete') {
169
            $this->logistics->cancelPerson($order);
170
171
            if ($order->hasActivePersonItems()) {
172
                $refund = $this->transactions->refund($order->transaction('uuid'), $order->remainingValue());
0 ignored issues
show
Bug introduced by
The property transactions does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
173
174
                if ($refund) {
175
                    $refundRecord = app(Refund::class)->create(
176
                        [
177
                        'transaction_id' => $order->transaction('id'),
178
                        'provider_id' => $refund->id,
179
                        'uuid' => Crypto::uuid(),
180
                        'amount' => $refund->amount,
181
                        'provider' => 'SierraTecnologia',
182
                        'charge' => $refund->charge,
183
                        'currency' => $refund->currency,
184
                        ]
185
                    );
186
187
                    foreach ($order->items as $item) {
188
                        $item->update(
189
                            [
190
                            'was_refunded' => true,
191
                            'status' => 'cancelled',
192
                            'refund_id' => $refundRecord->id,
193
                            ]
194
                        );
195
                    }
196
197
                    return $this->update(
198
                        $order->id,
199
                        [
200
                        'status' => 'cancelled',
201
                        'is_shipped' => false,
202
                        ]
203
                    );
204
                }
205
            }
206
        }
207
208
        return false;
209
    }
210
}
211