Completed
Push — master ( 598fe1...4a905b )
by Michael
03:41
created

MessageBuilderTrait   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 150
ccs 0
cts 40
cp 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A createEveApiMessage() 0 17 4
A createEventMessage() 0 9 1
A getEmittingEventMessage() 0 5 1
A getEmptyXmlDataMessage() 0 5 1
A getFailedToWriteFileMessage() 0 9 1
A getFinishedEventMessage() 0 5 1
A getNonHandledEventMessage() 0 5 1
A getReceivedEventMessage() 0 9 1
A getSufficientlyHandledEventMessage() 0 5 1
A getWasHandledEventMessage() 0 5 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Contains MessageBuilderTrait Trait.
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) 2015-2016 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 2015-2016 Michael Cummings
32
 * @license   http://www.gnu.org/copyleft/lesser.html GNU LGPL
33
 * @author    Michael Cummings <[email protected]>
34
 */
35
namespace Yapeal\Log;
36
37
use Yapeal\Xml\EveApiReadWriteInterface;
38
39
/**
40
 * Trait MessageBuilderTrait
41
 */
42
trait MessageBuilderTrait
43
{
44
    /**
45
     * @param string                   $messagePrefix
46
     * @param EveApiReadWriteInterface $data
47
     *
48
     * @return string
49
     * @throws \LogicException
50
     */
51
    protected function createEveApiMessage(string $messagePrefix, EveApiReadWriteInterface $data): string
52
    {
53
        $mess = $messagePrefix . ' Eve API %1$s/%2$s';
54
        $subs = [lcfirst($data->getEveApiSectionName()), $data->getEveApiName()];
55
        if ($data->hasEveApiArgument('keyID')) {
56
            $mess .= ' for keyID = %3$s';
57
            $subs[] = $data->getEveApiArgument('keyID');
58
            if ($data->hasEveApiArgument('characterID')) {
59
                $mess .= ' and characterID = %4$s';
60
                $subs[] = $data->getEveApiArgument('characterID');
61
            } elseif ($data->hasEveApiArgument('corporationID')) {
62
                $mess .= ' and corporationID = %4$s';
63
                $subs[] = $data->getEveApiArgument('corporationID');
64
            }
65
        }
66
        return vsprintf($mess, $subs);
67
    }
68
    /**
69
     * @param string                   $messagePrefix
70
     * @param EveApiReadWriteInterface $data
71
     * @param string                   $eventName
72
     *
73
     * @return string
74
     * @throws \LogicException
75
     */
76
    protected function createEventMessage(
77
        string $messagePrefix,
78
        EveApiReadWriteInterface $data,
79
        string $eventName
80
    ): string
81
    {
82
        $messagePrefix .= sprintf(' %s event from', $eventName);
83
        return $this->createEveApiMessage($messagePrefix, $data);
84
    }
85
    /**
86
     * @param EveApiReadWriteInterface $data
87
     * @param string                   $eventName
88
     *
89
     * @return string
90
     * @throws \LogicException
91
     */
92
    protected function getEmittingEventMessage(EveApiReadWriteInterface $data, string $eventName): string
93
    {
94
        $messagePrefix = 'Emitting';
95
        return $this->createEventMessage($messagePrefix, $data, $eventName);
96
    }
97
    /**
98
     * @param EveApiReadWriteInterface $data
99
     * @param string                   $eventName
100
     *
101
     * @return string
102
     * @throws \LogicException
103
     */
104
    protected function getEmptyXmlDataMessage(EveApiReadWriteInterface $data, string $eventName): string
105
    {
106
        $messagePrefix = 'XML empty after';
107
        return $this->createEventMessage($messagePrefix, $data, $eventName);
108
    }
109
    /**
110
     * @param EveApiReadWriteInterface $data
111
     * @param string                   $eventName
112
     * @param string                   $fileName
113
     *
114
     * @return string
115
     * @throws \LogicException
116
     */
117
    protected function getFailedToWriteFileMessage(
118
        EveApiReadWriteInterface $data,
119
        string $eventName,
120
        string $fileName
121
    ): string
122
    {
123
        $messagePrefix = sprintf('Failed writing %s file during', $fileName);
124
        return $this->createEventMessage($messagePrefix, $data, $eventName);
125
    }
126
    /**
127
     * @param EveApiReadWriteInterface $data
128
     * @param string                   $eventName
129
     *
130
     * @return string
131
     * @throws \LogicException
132
     */
133
    protected function getFinishedEventMessage(EveApiReadWriteInterface $data, string $eventName): string
134
    {
135
        $messagePrefix = 'Finished';
136
        return $this->createEventMessage($messagePrefix, $data, $eventName);
137
    }
138
    /**
139
     * @param EveApiReadWriteInterface $data
140
     * @param string                   $eventName
141
     *
142
     * @return string
143
     * @throws \LogicException
144
     */
145
    protected function getNonHandledEventMessage(EveApiReadWriteInterface $data, string $eventName): string
146
    {
147
        $messagePrefix = 'Nothing reported handling';
148
        return $this->createEventMessage($messagePrefix, $data, $eventName);
149
    }
150
    /**
151
     * @param EveApiReadWriteInterface $data
152
     * @param string                   $eventName
153
     * @param string                   $location
154
     *
155
     * @return string
156
     * @throws \LogicException
157
     */
158
    protected function getReceivedEventMessage(
159
        EveApiReadWriteInterface $data,
160
        string $eventName,
161
        string $location
162
    ): string
163
    {
164
        $messagePrefix = sprintf('Received in %s', $location);
165
        return $this->createEventMessage($messagePrefix, $data, $eventName);
166
    }
167
    /**
168
     * @param EveApiReadWriteInterface $data
169
     * @param string                   $eventName
170
     *
171
     * @return string
172
     * @throws \LogicException
173
     */
174
    protected function getSufficientlyHandledEventMessage(EveApiReadWriteInterface $data, string $eventName): string
175
    {
176
        $messagePrefix = 'Sufficiently handled';
177
        return $this->createEventMessage($messagePrefix, $data, $eventName);
178
    }
179
    /**
180
     * @param EveApiReadWriteInterface $data
181
     * @param string                   $eventName
182
     *
183
     * @return string
184
     * @throws \LogicException
185
     */
186
    protected function getWasHandledEventMessage(EveApiReadWriteInterface $data, string $eventName): string
187
    {
188
        $messagePrefix = 'Handled';
189
        return $this->createEventMessage($messagePrefix, $data, $eventName);
190
    }
191
}
192