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

ContactList   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 186
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 7
c 4
b 0
f 3
lcom 1
cbo 5
dl 0
loc 186
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A preserveToAllianceContactLabels() 0 20 1
A preserveToAllianceContactList() 0 23 1
A preserveToContactLabels() 0 20 1
B preserveToContactList() 0 24 1
A preserveToCorporateContactLabels() 0 20 1
A preserveToCorporateContactList() 0 23 1
1
<?php
2
/**
3
 * Contains class ContactList.
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 ContactList
42
 */
43
class ContactList extends CharSection
44
{
45
    use PreserverTrait;
46
    /** @noinspection MagicMethodsValidityInspection */
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        $this->mask = 16;
53
        $this->preserveTos = [
54
            'preserveToAllianceContactLabels',
55
            'preserveToAllianceContactList',
56
            'preserveToContactLabels',
57
            'preserveToContactList',
58
            'preserveToCorporateContactLabels',
59
            'preserveToCorporateContactList'
60
        ];
61
    }
62
    /**
63
     * @param EveApiReadWriteInterface $data
64
     *
65
     * @return self Fluent interface.
66
     * @throws \LogicException
67
     */
68
    protected function preserveToAllianceContactLabels(EveApiReadWriteInterface $data)
69
    {
70
        $tableName = 'charAllianceContactLabels';
71
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
72
        $sql = $this->getCsq()
73
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
74
        $this->getYem()
75
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
76
        $this->getPdo()
77
            ->exec($sql);
78
        $columnDefaults = [
79
            'labelID' => null,
80
            'name' => '',
81
            'ownerID' => $ownerID
82
        ];
83
        $xPath = '//allianceContactLabels/row';
84
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
85
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
86
        return $this;
87
    }
88
    /**
89
     * @param EveApiReadWriteInterface $data
90
     *
91
     * @return self Fluent interface.
92
     * @throws \LogicException
93
     */
94
    protected function preserveToAllianceContactList(EveApiReadWriteInterface $data)
95
    {
96
        $tableName = 'charAllianceContactList';
97
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
98
        $sql = $this->getCsq()
99
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
100
        $this->getYem()
101
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
102
        $this->getPdo()
103
            ->exec($sql);
104
        $columnDefaults = [
105
            'contactID' => null,
106
            'contactName' => '',
107
            'contactTypeID' => null,
108
            'labelMask' => null,
109
            'ownerID' => $ownerID,
110
            'standing' => null
111
        ];
112
        $xPath = '//allianceContactList/row';
113
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
114
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
115
        return $this;
116
    }
117
    /**
118
     * @param EveApiReadWriteInterface $data
119
     *
120
     * @return self Fluent interface.
121
     * @throws \LogicException
122
     */
123
    protected function preserveToContactLabels(EveApiReadWriteInterface $data)
124
    {
125
        $tableName = 'charContactLabels';
126
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
127
        $sql = $this->getCsq()
128
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
129
        $this->getYem()
130
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
131
        $this->getPdo()
132
            ->exec($sql);
133
        $columnDefaults = [
134
            'labelID' => null,
135
            'name' => '',
136
            'ownerID' => $ownerID
137
        ];
138
        $xPath = '//contactLabels/row';
139
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
140
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
141
        return $this;
142
    }
143
    /**
144
     * @param EveApiReadWriteInterface $data
145
     *
146
     * @return self Fluent interface.
147
     * @throws \LogicException
148
     */
149
    protected function preserveToContactList(EveApiReadWriteInterface $data)
150
    {
151
        $tableName = 'charContactList';
152
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
153
        $sql = $this->getCsq()
154
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
155
        $this->getYem()
156
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
157
        $this->getPdo()
158
            ->exec($sql);
159
        $columnDefaults = [
160
            'contactID' => null,
161
            'contactName' => '',
162
            'contactTypeID' => null,
163
            'inWatchlist' => null,
164
            'labelMask' => null,
165
            'ownerID' => $ownerID,
166
            'standing' => null
167
        ];
168
        $xPath = '//contactList/row';
169
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
170
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
171
        return $this;
172
    }
173
    /**
174
     * @param EveApiReadWriteInterface $data
175
     *
176
     * @return self Fluent interface.
177
     * @throws \LogicException
178
     */
179
    protected function preserveToCorporateContactLabels(EveApiReadWriteInterface $data)
180
    {
181
        $tableName = 'charCorporateContactLabels';
182
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
183
        $sql = $this->getCsq()
184
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
185
        $this->getYem()
186
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
187
        $this->getPdo()
188
            ->exec($sql);
189
        $columnDefaults = [
190
            'labelID' => null,
191
            'name' => '',
192
            'ownerID' => $ownerID
193
        ];
194
        $xPath = '//corporateContactLabels/row';
195
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
196
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
197
        return $this;
198
    }
199
    /**
200
     * @param EveApiReadWriteInterface $data
201
     *
202
     * @return self Fluent interface.
203
     * @throws \LogicException
204
     */
205
    protected function preserveToCorporateContactList(EveApiReadWriteInterface $data)
206
    {
207
        $tableName = 'charCorporateContactList';
208
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
209
        $sql = $this->getCsq()
210
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
211
        $this->getYem()
212
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
213
        $this->getPdo()
214
            ->exec($sql);
215
        $columnDefaults = [
216
            'contactID' => null,
217
            'contactName' => '',
218
            'contactTypeID' => null,
219
            'labelMask' => null,
220
            'ownerID' => $ownerID,
221
            'standing' => null
222
        ];
223
        $xPath = '//corporateContactList/row';
224
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
225
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
226
        return $this;
227
    }
228
}
229