APIKeyInfo   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 83
ccs 0
cts 51
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A preserveToAPIKeyInfo() 0 15 1
A preserveToCharacters() 0 18 1
A preserveToKeyBridge() 0 10 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Contains APIKeyInfo class.
5
 *
6
 * PHP version 7.0+
7
 *
8
 * LICENSE:
9
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
10
 * which can be used to access the Eve Online API data and place it into a
11
 * database.
12
 * Copyright (C) 2016-2017 Michael Cummings
13
 *
14
 * This program is free software: you can redistribute it and/or modify it
15
 * under the terms of the GNU Lesser General Public License as published by the
16
 * Free Software Foundation, either version 3 of the License, or (at your
17
 * option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful, but WITHOUT
20
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
22
 * for more details.
23
 *
24
 * You should have received a copy of the GNU Lesser General Public License
25
 * along with this program. If not, see
26
 * <http://spdx.org/licenses/LGPL-3.0.html>.
27
 *
28
 * You should be able to find a copy of this license in the COPYING-LESSER.md
29
 * file. A copy of the GNU GPL should also be available in the COPYING.md file.
30
 *
31
 * @copyright 2016-2017 Michael Cummings
32
 * @license   LGPL-3.0+
33
 * @author    Michael Cummings <[email protected]>
34
 */
35
namespace Yapeal\EveApi\Account;
36
37
use Yapeal\Event\EveApiPreserverInterface;
38
use Yapeal\Sql\PreserverTrait;
39
use Yapeal\Xml\EveApiReadWriteInterface;
40
41
/**
42
 * Class APIKeyInfo
43
 */
44
class APIKeyInfo extends AccountSection implements EveApiPreserverInterface
45
{
46
    use PreserverTrait;
47
48
    /**
49
     * Constructor
50
     */
51
    public function __construct()
52
    {
53
        $this->preserveTos = [
54
            'preserveToAPIKeyInfo',
55
            'preserveToCharacters',
56
            'preserveToKeyBridge'
57
        ];
58
    }
59
    /**
60
     * @param EveApiReadWriteInterface $data
61
     *
62
     * @return self Fluent interface.
63
     * @throws \DomainException
64
     * @throws \InvalidArgumentException
65
     * @throws \LogicException
66
     */
67
    protected function preserveToAPIKeyInfo(EveApiReadWriteInterface $data)
68
    {
69
        $tableName = 'accountAPIKeyInfo';
70
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
71
        $columnDefaults = [
72
            'accessMask' => null,
73
            'expires' => '2038-01-19 03:14:07',
74
            'keyID' => $ownerID,
75
            'type' => null
76
        ];
77
        $xPath = '//key';
78
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
79
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
80
        return $this;
81
    }
82
    /**
83
     * @param EveApiReadWriteInterface $data
84
     *
85
     * @return self Fluent interface.
86
     * @throws \DomainException
87
     * @throws \InvalidArgumentException
88
     * @throws \LogicException
89
     */
90
    protected function preserveToCharacters(EveApiReadWriteInterface $data)
91
    {
92
        $tableName = 'accountCharacters';
93
        $columnDefaults = [
94
            'allianceID' => null,
95
            'allianceName' => null,
96
            'characterID' => null,
97
            'characterName' => null,
98
            'corporationID' => null,
99
            'corporationName' => null,
100
            'factionID' => null,
101
            'factionName' => null
102
        ];
103
        $xPath = '//characters/row';
104
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
105
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
106
        return $this;
107
    }
108
    /**
109
     * @param EveApiReadWriteInterface $data
110
     *
111
     * @return self Fluent interface.
112
     * @throws \DomainException
113
     * @throws \InvalidArgumentException
114
     * @throws \LogicException
115
     */
116
    protected function preserveToKeyBridge(EveApiReadWriteInterface $data)
117
    {
118
        $tableName = 'accountKeyBridge';
119
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
120
        $columnDefaults = ['keyID' => $ownerID, 'characterID' => null];
121
        $xPath = '//characters/row';
122
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
123
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
124
        return $this;
125
    }
126
}
127