GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 8f9f4a...5d20fa )
by Miguel Angel
03:25
created

BasePlugin   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 78.46%

Importance

Changes 8
Bugs 3 Features 1
Metric Value
wmc 16
c 8
b 3
f 1
lcom 1
cbo 4
dl 0
loc 160
ccs 51
cts 65
cp 0.7846
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 1
A writeLn() 0 5 1
A write() 0 19 3
A deprecationNotice() 0 4 1
A progressStart() 0 4 1
A progressAdvance() 0 4 1
A progressFinish() 0 4 1
A getEditionOption() 0 19 3
B getConfigOption() 0 25 4
1
<?php
2
/*
3
 * This file is part of the trefoil application.
4
 *
5
 * (c) Miguel Angel Gabriel <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Trefoil\Plugins;
11
12
use Easybook\Events\BaseEvent;
13
use Symfony\Component\Console\Output\Output;
14
use Trefoil\DependencyInjection\Application;
15
use Trefoil\Util\Toolkit;
16
17
/**
18
 * Base class for all plugins
19
 *
20
 */
21
abstract class BasePlugin
22
{
23
    /**
24
     * @var array|Application
25
     */
26
    protected $app;
27
28
    /**
29
     * @var Output
30
     */
31
    protected $output;
32
    protected $edition;
33
    protected $format;
34
    protected $theme;
35
    protected $item;
36
    protected $event;
37
38
    /**
39
     * Do some initialization tasks.
40
     * Must be called explicitly for each plugin at the beginning
41
     * of each event handler method.
42
     *
43
     * @param BaseEvent $event
44
     */
45 26
    public function init(BaseEvent $event)
46
    {
47 26
        $this->event = $event;
48 26
        $this->app = $event->app;
49 26
        $this->output = $this->app['console.output'];
50 26
        $this->edition = $this->app['publishing.edition'];
51 26
        $this->format = Toolkit::getCurrentFormat($this->app);
52 26
        $this->theme = ucfirst($this->app->edition('theme'));
53 26
        $this->item = $event->getItem();
54 26
    }
55
56
    /**
57
     * Write an output message line
58
     *
59
     * @param string $message
60
     * @param string $type of message ('error', 'warning', 'info')
61
     */
62 7
    public function writeLn($message, $type = 'info')
63
    {
64 7
        $this->write($message, $type);
65 7
        $this->output->writeLn('');
66 7
    }
67
68
    /**
69
     * Write an output message (w/o a line break)
70
     *
71
     * @param string $message
72
     * @param string $type of message ('error', 'warning', 'info')
73
     */
74 7
    public function write($message, $type = 'info')
75
    {
76 7
        $class = join('', array_slice(explode('\\', get_called_class()), -1));
77 7
        $prefix = sprintf('%s: ', $class);
78
79 7
        $msgType = '';
80
81 7
        switch (strtolower($type)) {
82 7
            case 'warning':
83 4
                $msgType = '<bg=yellow;fg=black> WARNING </> ';
84 4
                break;
85
86 4
            case 'error':
87 1
                $msgType = '<bg=red;fg=white> ERROR </> ';
88 1
                break;
89 7
        }
90
91 7
        $this->output->write(' > ' . $prefix . $msgType . $message);
92 7
    }
93
94
    /**
95
     * Writes a deprecation notice.
96
     * 
97
     * @param string $message
98
     */
99 4
    public function deprecationNotice($message = 'This plugin is deprecated. Please use an alternative.')
100
    {
101 4
        $this->writeLn($message, 'warning');
102 4
    }
103
104 1
    protected function progressStart($limit)
105
    {
106 1
        $this->app['console.progress']->start($this->output, $limit);
107 1
    }
108
109 1
    protected function progressAdvance()
110
    {
111 1
        $this->app['console.progress']->advance();
112 1
    }
113
114 1
    protected function progressFinish()
115
    {
116 1
        $this->app['console.progress']->finish();
117 1
    }
118
119
    /**
120
     * Retrieve the value of an edition option (from config.yml file)
121
     *
122
     * @param string $optionName (as in 'one.two.three')
123
     * @param mixed  $default
124
     *
125
     * @return mixed
126
     */
127 13
    protected function getEditionOption($optionName, $default = null)
128
    {
129 13
        $editions = $this->app->book('editions');
130 13
        $editionOptions = $editions[$this->edition];
131
132 13
        $keys = explode('.', $optionName);
133
134 13
        $option = $editionOptions;
135
136 13
        foreach ($keys as $key) {
137 13
            if (array_key_exists($key, $option)) {
138 13
                $option = $option[$key];
139 13
            } else {
140 4
                return $default;
141
            }
142 13
        }
143
144 11
        return $option;
145
    }
146
147
    /**
148
     * Retrieve the value of a book option (from config.yml file)
149
     *
150
     * @param string $optionName (as in 'one.two.three')
151
     * @param mixed  $default
152
     *
153
     * @return mixed
154
     */
155
    protected function getConfigOption($optionName, $default = null)
156
    {
157
        $configOptions = $this->app['publishing.book.config'];
158
159
        $keys = explode('.', $optionName);
160
161
        $option = $configOptions;
162
163
        foreach ($keys as $index => $key) {
164
            if (array_key_exists($key, $option)) {
165
                $option = $option[$key];
166
            } else {
167
168
                $joinKeys = implode('.', array_slice($keys, $index));
169
170
                if (array_key_exists($joinKeys, $option)) {
171
                    return $option[$joinKeys];
172
                } else {
173
                    return $default;
174
                }
175
            }
176
        }
177
178
        return $option;
179
    }
180
}
181