Completed
Push — master ( 75748b...36048b )
by Michael
06:58
created

ActiveTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 74
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
createEveApiMessage() 0 1 ?
B getActive() 0 41 6
getCsq() 0 1 ?
getMask() 0 1 ?
getPdo() 0 1 ?
getYem() 0 1 ?
1
<?php
2
/**
3
 * Contains trait ActiveTrait.
4
 *
5
 * PHP version 5.5
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   LGPL-3.0+
32
 * @author    Michael Cummings <[email protected]>
33
 */
34
namespace Yapeal\EveApi;
35
36
use PDO;
37
use PDOException;
38
use Yapeal\Log\Logger;
39
use Yapeal\Xml\EveApiReadWriteInterface;
40
41
/**
42
 * Trait ActiveTrait.
43
 */
44
trait ActiveTrait
45
{
46
    /**
47
     * @param string                   $messagePrefix
48
     * @param EveApiReadWriteInterface $data
49
     *
50
     * @return string
51
     * @throws \LogicException
52
     */
53
    abstract protected function createEveApiMessage($messagePrefix, EveApiReadWriteInterface $data);
54
    /**
55
     * @param EveApiReadWriteInterface $data
56
     *
57
     * @return array
58
     * @throws \LogicException
59
     */
60
    protected function getActive(EveApiReadWriteInterface $data)
61
    {
62
        switch (strtolower($data->getEveApiSectionName())) {
63
            case 'account':
64
                if ('APIKeyInfo' === $data->getEveApiName()) {
65
                    $sql = $this->getCsq()
66
                                ->getActiveRegisteredKeys();
67
                    break;
68
                }
69
                $sql = $this->getCsq()
70
                            ->getActiveRegisteredAccountStatus($this->getMask());
71
                break;
72
            case 'char':
73
                $sql = $this->getCsq()
74
                            ->getActiveRegisteredCharacters($this->getMask());
75
                break;
76
            case 'corp':
77
                $sql = $this->getCsq()
78
                            ->getActiveRegisteredCorporations($this->getMask());
79
                break;
80
            default:
81
                return [];
82
        }
83
        $this->getYem()
84
             ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
85
        try {
86
            return $this->getPdo()
87
                        ->query($sql)
88
                        ->fetchAll(PDO::FETCH_ASSOC);
89
        } catch (PDOException $exc) {
90
            $mess = 'Could NOT get a list of active owners for';
91
            $this->getYem()
92
                 ->triggerLogEvent(
93
                     'Yapeal.Log.log',
94
                     Logger::WARNING,
95
                     $this->createEveApiMessage($mess, $data),
96
                     ['exception' => $exc]
97
                 );
98
            return [];
99
        }
100
    }
101
    /**
102
     * @return \Yapeal\Sql\CommonSqlQueries
103
     */
104
    abstract protected function getCsq();
105
    /**
106
     * @return int
107
     */
108
    abstract protected function getMask();
109
    /**
110
     * @return \PDO
111
     */
112
    abstract protected function getPdo();
113
    /**
114
     * @return \Yapeal\Event\MediatorInterface
115
     */
116
    abstract protected function getYem();
117
}
118