Completed
Push — master ( df4948...3b59f8 )
by Michael
02:51
created

CharacterSheet   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 342
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 12
c 1
b 0
f 1
lcom 1
cbo 5
dl 0
loc 342
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A preserveToCertificates() 0 19 1
A preserveToCharacterSheet() 0 47 1
A preserveToCorporationRoles() 0 20 1
A preserveToCorporationRolesAtBase() 0 20 1
A preserveToCorporationRolesAtHQ() 0 20 1
A preserveToCorporationRolesAtOther() 0 20 1
A preserveToCorporationTitles() 0 20 1
A preserveToImplants() 0 20 1
A preserveToJumpCloneImplants() 0 21 1
A preserveToJumpClones() 0 22 1
A preserveToSkills() 0 22 1
1
<?php
2
/**
3
 * Contains class CharacterSheet.
4
 *
5
 * PHP version 5.4
6
 *
7
 * LICENSE:
8
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
9
 * which can be used to access the Eve Online API data and place it into a
10
 * database.
11
 * Copyright (C) 2016 Michael Cummings
12
 *
13
 * This program is free software: you can redistribute it and/or modify it
14
 * under the terms of the GNU Lesser General Public License as published by the
15
 * Free Software Foundation, either version 3 of the License, or (at your
16
 * option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21
 * for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public License
24
 * along with this program. If not, see
25
 * <http://www.gnu.org/licenses/>.
26
 *
27
 * You should be able to find a copy of this license in the LICENSE.md file. A
28
 * copy of the GNU GPL should also be available in the GNU-GPL.md file.
29
 *
30
 * @copyright 2016 Michael Cummings
31
 * @license   http://www.gnu.org/copyleft/lesser.html GNU LGPL
32
 * @author    Michael Cummings <[email protected]>
33
 */
34
namespace Yapeal\EveApi\Char;
35
36
use Yapeal\Log\Logger;
37
use Yapeal\Sql\PreserverTrait;
38
use Yapeal\Xml\EveApiReadWriteInterface;
39
40
/**
41
 * Class CharacterSheet
42
 */
43
class CharacterSheet extends CharSection
44
{
45
    use PreserverTrait;
46
    /** @noinspection MagicMethodsValidityInspection */
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        $this->mask = 8;
53
        $this->preserveTos = [
54
            'preserveToCertificates',
55
            'preserveToCharacterSheet',
56
            'preserveToCorporationRoles',
57
            'preserveToCorporationRolesAtBase',
58
            'preserveToCorporationRolesAtHQ',
59
            'preserveToCorporationRolesAtOther',
60
            'preserveToCorporationTitles',
61
            'preserveToImplants',
62
            'preserveToJumpCloneImplants',
63
            'preserveToJumpClones',
64
            'preserveToSkills'
65
        ];
66
    }
67
    /**
68
     * @param EveApiReadWriteInterface $data
69
     *
70
     * @return self Fluent interface.
71
     * @throws \LogicException
72
     */
73
    protected function preserveToCertificates(EveApiReadWriteInterface $data)
74
    {
75
        $tableName = 'charCertificates';
76
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
77
        $sql = $this->getCsq()
78
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
79
        $this->getYem()
80
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
81
        $this->getPdo()
82
            ->exec($sql);
83
        $columnDefaults = [
84
            'certificateID' => null,
85
            'ownerID' => $ownerID
86
        ];
87
        $xPath = '//certificates/row';
88
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
89
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
90
        return $this;
91
    }
92
    /**
93
     * @param EveApiReadWriteInterface $data
94
     *
95
     * @return self Fluent interface.
96
     * @throws \LogicException
97
     */
98
    protected function preserveToCharacterSheet(EveApiReadWriteInterface $data)
99
    {
100
        $tableName = 'charCharacterSheet';
101
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
102
        $sql = $this->getCsq()
103
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
104
        $this->getYem()
105
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
106
        $this->getPdo()
107
            ->exec($sql);
108
        $columnDefaults = [
109
            'allianceID' => null,
110
            'allianceName' => '',
111
            'ancestry' => null,
112
            'ancestryID' => null,
113
            'balance' => '0.0',
114
            'bloodLine' => null,
115
            'bloodLineID' => null,
116
            'characterID' => null,
117
            'cloneJumpDate' => '1970-01-01 00:00:01',
118
            'cloneName' => '',
119
            'cloneSkillPoints' => null,
120
            'cloneTypeID' => null,
121
            'corporationID' => null,
122
            'corporationName' => '',
123
            'DoB' => null,
124
            'factionID' => null,
125
            'factionName' => '',
126
            'freeRespecs' => null,
127
            'freeSkillPoints' => null,
128
            'gender' => null,
129
            'homeStationID' => null,
130
            'jumpActivation' => null,
131
            'jumpFatigue' => null,
132
            'jumpLastUpdate' => '1970-01-01 00:00:01',
133
            'lastRespecDate' => '1970-01-01 00:00:01',
134
            'lastTimedRespec' => '1970-01-01 00:00:01',
135
            'name' => '',
136
            'ownerID' => $ownerID,
137
            'race' => null,
138
            'remoteStationDate' => '1970-01-01 00:00:01'
139
        ];
140
        $xPath = '//result/child::*[not(*|@*|self::dataTime)]';
141
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
142
        $this->valuesPreserveData($elements, $columnDefaults, $tableName);
143
        return $this;
144
    }
145
    /**
146
     * @param EveApiReadWriteInterface $data
147
     *
148
     * @return self Fluent interface.
149
     * @throws \LogicException
150
     */
151
    protected function preserveToCorporationRoles(EveApiReadWriteInterface $data)
152
    {
153
        $tableName = 'charCorporationRoles';
154
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
155
        $sql = $this->getCsq()
156
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
157
        $this->getYem()
158
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
159
        $this->getPdo()
160
            ->exec($sql);
161
        $columnDefaults = [
162
            'ownerID' => $ownerID,
163
            'roleID' => null,
164
            'roleName' => ''
165
        ];
166
        $xPath = '//corporationRoles/row';
167
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
168
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
169
        return $this;
170
    }
171
    /**
172
     * @param EveApiReadWriteInterface $data
173
     *
174
     * @return self Fluent interface.
175
     * @throws \LogicException
176
     */
177
    protected function preserveToCorporationRolesAtBase(EveApiReadWriteInterface $data)
178
    {
179
        $tableName = 'charCorporationRolesAtBase';
180
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
181
        $sql = $this->getCsq()
182
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
183
        $this->getYem()
184
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
185
        $this->getPdo()
186
            ->exec($sql);
187
        $columnDefaults = [
188
            'ownerID' => $ownerID,
189
            'roleID' => null,
190
            'roleName' => ''
191
        ];
192
        $xPath = '//corporationRolesAtBase/row';
193
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
194
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
195
        return $this;
196
    }
197
    /**
198
     * @param EveApiReadWriteInterface $data
199
     *
200
     * @return self Fluent interface.
201
     * @throws \LogicException
202
     */
203
    protected function preserveToCorporationRolesAtHQ(EveApiReadWriteInterface $data)
204
    {
205
        $tableName = 'charCorporationRolesAtHQ';
206
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
207
        $sql = $this->getCsq()
208
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
209
        $this->getYem()
210
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
211
        $this->getPdo()
212
            ->exec($sql);
213
        $columnDefaults = [
214
            'ownerID' => $ownerID,
215
            'roleID' => null,
216
            'roleName' => ''
217
        ];
218
        $xPath = '//corporationRolesAtHQ/row';
219
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
220
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
221
        return $this;
222
    }
223
    /**
224
     * @param EveApiReadWriteInterface $data
225
     *
226
     * @return self Fluent interface.
227
     * @throws \LogicException
228
     */
229
    protected function preserveToCorporationRolesAtOther(EveApiReadWriteInterface $data)
230
    {
231
        $tableName = 'charCorporationRolesAtOther';
232
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
233
        $sql = $this->getCsq()
234
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
235
        $this->getYem()
236
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
237
        $this->getPdo()
238
            ->exec($sql);
239
        $columnDefaults = [
240
            'ownerID' => $ownerID,
241
            'roleID' => null,
242
            'roleName' => ''
243
        ];
244
        $xPath = '//corporationRolesAtOther/row';
245
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
246
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
247
        return $this;
248
    }
249
    /**
250
     * @param EveApiReadWriteInterface $data
251
     *
252
     * @return self Fluent interface.
253
     * @throws \LogicException
254
     */
255
    protected function preserveToCorporationTitles(EveApiReadWriteInterface $data)
256
    {
257
        $tableName = 'charCorporationTitles';
258
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
259
        $sql = $this->getCsq()
260
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
261
        $this->getYem()
262
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
263
        $this->getPdo()
264
            ->exec($sql);
265
        $columnDefaults = [
266
            'ownerID' => $ownerID,
267
            'titleID' => null,
268
            'titleName' => ''
269
        ];
270
        $xPath = '//corporationTitles/row';
271
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
272
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
273
        return $this;
274
    }
275
    /**
276
     * @param EveApiReadWriteInterface $data
277
     *
278
     * @return self Fluent interface.
279
     * @throws \LogicException
280
     */
281
    protected function preserveToImplants(EveApiReadWriteInterface $data)
282
    {
283
        $tableName = 'charImplants';
284
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
285
        $sql = $this->getCsq()
286
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
287
        $this->getYem()
288
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
289
        $this->getPdo()
290
            ->exec($sql);
291
        $columnDefaults = [
292
            'ownerID' => $ownerID,
293
            'typeID' => null,
294
            'typeName' => ''
295
        ];
296
        $xPath = '//implants/row';
297
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
298
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
299
        return $this;
300
    }
301
    /**
302
     * @param EveApiReadWriteInterface $data
303
     *
304
     * @return self Fluent interface.
305
     * @throws \LogicException
306
     */
307
    protected function preserveToJumpCloneImplants(EveApiReadWriteInterface $data)
308
    {
309
        $tableName = 'charJumpCloneImplants';
310
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
311
        $sql = $this->getCsq()
312
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
313
        $this->getYem()
314
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
315
        $this->getPdo()
316
            ->exec($sql);
317
        $columnDefaults = [
318
            'jumpCloneID' => null,
319
            'ownerID' => $ownerID,
320
            'typeID' => null,
321
            'typeName' => ''
322
        ];
323
        $xPath = '//jumpCloneImplants/row';
324
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
325
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
326
        return $this;
327
    }
328
    /**
329
     * @param EveApiReadWriteInterface $data
330
     *
331
     * @return self Fluent interface.
332
     * @throws \LogicException
333
     */
334
    protected function preserveToJumpClones(EveApiReadWriteInterface $data)
335
    {
336
        $tableName = 'charJumpClones';
337
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
338
        $sql = $this->getCsq()
339
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
340
        $this->getYem()
341
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
342
        $this->getPdo()
343
            ->exec($sql);
344
        $columnDefaults = [
345
            'cloneName' => '',
346
            'jumpCloneID' => null,
347
            'locationID' => null,
348
            'ownerID' => $ownerID,
349
            'typeID' => null
350
        ];
351
        $xPath = '//jumpClones/row';
352
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
353
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
354
        return $this;
355
    }
356
    /**
357
     * @param EveApiReadWriteInterface $data
358
     *
359
     * @return self Fluent interface.
360
     * @throws \LogicException
361
     */
362
    protected function preserveToSkills(EveApiReadWriteInterface $data)
363
    {
364
        $tableName = 'charSkills';
365
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
366
        $sql = $this->getCsq()
367
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
368
        $this->getYem()
369
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
370
        $this->getPdo()
371
            ->exec($sql);
372
        $columnDefaults = [
373
            'level' => null,
374
            'ownerID' => $ownerID,
375
            'published' => null,
376
            'skillpoints' => null,
377
            'typeID' => null
378
        ];
379
        $xPath = '//skills/row';
380
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
381
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
382
        return $this;
383
    }
384
}
385