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.

OutputPlugin::logVardump()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 1
nc 1
1
<?php
2
3
/**
4
 * Copyright (c) 2011-present Mediasift Ltd
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 *   * Redistributions of source code must retain the above copyright
12
 *     notice, this list of conditions and the following disclaimer.
13
 *
14
 *   * Redistributions in binary form must reproduce the above copyright
15
 *     notice, this list of conditions and the following disclaimer in
16
 *     the documentation and/or other materials provided with the
17
 *     distribution.
18
 *
19
 *   * Neither the names of the copyright holders nor the names of his
20
 *     contributors may be used to endorse or promote products derived
21
 *     from this software without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 *
36
 * @category  Libraries
37
 * @package   Storyplayer/OutputLib
38
 * @author    Stuart Herbert <[email protected]>
39
 * @copyright 2011-present Mediasift Ltd www.datasift.com
40
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
41
 * @link      http://datasift.github.io/storyplayer
42
 */
43
44
namespace DataSift\Storyplayer\OutputLib;
45
46
use DataSift\Storyplayer\PlayerLib\Story_Result;
47
use DataSift\Storyplayer\PlayerLib\PhaseGroup_Result;
48
49
/**
50
 * the base class for output plugins
51
 *
52
 * @category  Libraries
53
 * @package   Storyplayer/OutputLib
54
 * @author    Stuart Herbert <[email protected]>
55
 * @copyright 2011-present Mediasift Ltd www.datasift.com
56
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
57
 * @link      http://datasift.github.io/storyplayer
58
 */
59
abstract class OutputPlugin
60
{
61
    protected $writer = null;
62
63
    const COLOUR_MODE_OFF  = 1;
64
    const COLOUR_MODE_ON   = 2;
65
    const COLOUR_MODE_AUTO = 3;
66
67
    public function __construct()
68
    {
69
        $this->writer = new OutputWriter(self::COLOUR_MODE_AUTO);
0 ignored issues
show
Unused Code introduced by
The call to OutputWriter::__construct() has too many arguments starting with self::COLOUR_MODE_AUTO.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
70
    }
71
72
    // ==================================================================
73
    //
74
    // Support for outputting to various places
75
    //
76
    // ------------------------------------------------------------------
77
78
    /**
79
     * @return void
80
     */
81
    public function addOutputToStdout()
82
    {
83
        $this->writer->addOutputToStdout();
84
    }
85
86
    /**
87
     * @return void
88
     */
89
    public function addOutputToStderr()
90
    {
91
        $this->writer->addOutputToStderr();
92
    }
93
94
    /**
95
     * @param string $filename
96
     * @return void
97
     */
98
    public function addOutputToFile($filename)
99
    {
100
        // make sure $filename isn't a reserved name
101
        switch($filename)
102
        {
103
            case 'stdout':
104
            case 'stderr':
105
            case 'null':
106
                throw new E4xx_OutputFilenameIsAReservedName($filename);
107
        }
108
109
        $this->writer->addOutputToFile($filename);
110
    }
111
112
    /**
113
     * @param  string $output
114
     * @param  array|null $style
115
     * @return void
116
     */
117
    public function write($output, $style = null)
118
    {
119
        $this->writer->write($output, $style);
120
    }
121
122
    /**
123
     * @param  float $duration
124
     * @param  array|null $style
125
     * @return void
126
     */
127
    public function writeDuration($duration, $style = null)
128
    {
129
        // break down the duration into reportable units
130
        $hours = $mins = 0;
131
132
        // this gives us the ability to report on durations of
133
        // less than one second
134
        $secs = round($duration, 2);
135
        if ($duration > 59) {
136
            $mins  = (int)($duration / 60);
137
            // when things take a minute or more, we don't care
138
            // about sub-second accuracy any more
139
            $secs  = $duration % 60;
140
        }
141
        else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
142
        }
143
        if ($duration > 3600) {
144
            $hours = (int)($duration / 3600);
145
        }
146
147
        // turn the breakdown into a printable string
148
        $output = '';
149
        if ($hours) {
150
            if ($hours > 1) {
151
                $output = "{$hours} hours";
152
            }
153
            else {
154
                $output = "1 hour";
155
            }
156
        }
157
        if ($mins) {
158
            $minsUnit = 'mins';
159
            if ($mins == 1) {
160
                $minsUnit = 'min';
161
            }
162
            if ($hours && $secs) {
163
                $output .= ", {$mins} {$minsUnit}";
164
            }
165
            else if ($hours) {
166
                $output .= " and {$mins} {$minsUnit}";
167
            }
168
            else {
169
                $output = "{$mins} {$minsUnit}";
170
            }
171
        }
172
173
        $secsUnit = 'secs';
174
        if ($secs == 1) {
175
            $secsUnit = 'sec';
176
        }
177
        if (($hours || $mins) && $secs) {
178
            $output .= " and {$secs} {$secsUnit}";
179
        }
180
        else {
181
            $output = "{$secs} {$secsUnit}";
182
        }
183
184
        // are we using our default style?
185
        if (!$style) {
186
            $style = $this->writer->durationStyle;
187
        }
188
189
        // send the string out to the user
190
        $this->writer->write($output, $style);
191
    }
192
193
    /**
194
     * @return OutputWriter
195
     */
196
    public function getWriter()
197
    {
198
        return $this->writer;
199
    }
200
201
    // ==================================================================
202
    //
203
    // Colour support
204
    //
205
    // ------------------------------------------------------------------
206
207
    /**
208
     * @return void
209
     */
210
    public function disableColourSupport()
211
    {
212
        $this->writer->setColourMode(self::COLOUR_MODE_OFF);
213
    }
214
215
    /**
216
     * @return void
217
     */
218
    public function enableColourSupport()
219
    {
220
        $this->writer->setColourMode(self::COLOUR_MODE_AUTO);
221
    }
222
223
    /**
224
     * @return void
225
     */
226
    public function enforceColourSupport()
227
    {
228
        $this->writer->setColourMode(self::COLOUR_MODE_ON);
229
    }
230
231
    // ==================================================================
232
    //
233
    // These are the methods that Storyplayer will call as things
234
    // happen ...
235
    //
236
    // ------------------------------------------------------------------
237
238
    /**
239
     * @param string $version
240
     * @param string $url
241
     * @param string $copyright
242
     * @param string $license
243
     * @return void
244
     */
245
    abstract public function startStoryplayer($version, $url, $copyright, $license);
246
247
    /**
248
     * @return void
249
     */
250
    abstract public function endStoryplayer($duration);
251
252
    /**
253
     * @return void
254
     */
255
    abstract public function resetSilentMode();
256
257
    /**
258
     * @return void
259
     */
260
    abstract public function setSilentMode();
261
262
    /**
263
     * @return void
264
     */
265
    abstract public function startPhaseGroup($activity, $name, $details = null);
266
267
    /**
268
     * @return void
269
     */
270
    abstract public function endPhaseGroup($result);
271
272
    /**
273
     * @return void
274
     */
275
    abstract public function startPhase($phase);
276
277
    /**
278
     * @return void
279
     */
280
    abstract public function endPhase($phase, $phaseResult);
281
282
    /**
283
     * @param string $msg
284
     * @return void
285
     */
286
    abstract public function logPhaseActivity($msg);
287
288
    /**
289
     * called when a story logs the (possibly partial) output from
290
     * running a subprocess
291
     *
292
     * @param  string $msg the output to log
293
     * @return void
294
     */
295
    abstract public function logPhaseSubprocessOutput($msg);
296
297
    /**
298
     * @param string $phaseName
299
     * @param string $msg
300
     * @return void
301
     */
302
    abstract public function logPhaseError($phaseName, $msg);
303
304
    /**
305
     * @param string $phaseName
306
     * @param string $msg
307
     * @return void
308
     */
309
    abstract public function logPhaseSkipped($phaseName, $msg);
310
311
    /**
312
     * @param string $msg
313
     *
314
     * @return void
315
     */
316
    abstract public function logCliWarning($msg);
317
318
    /**
319
     * @param string $msg
320
     *
321
     * @return void
322
     */
323
    abstract public function logCliError($msg);
324
325
    /**
326
     *
327
     * @param  string $msg
328
     * @param  Exception $e
329
     * @return void
330
     */
331
    abstract public function logCliErrorWithException($msg, $e);
332
333
    /**
334
     * @param string $msg
335
     *
336
     * @return void
337
     */
338
    abstract public function logCliInfo($msg);
339
340
    /**
341
     * @param string $name
342
     *
343
     * @return void
344
     */
345
    abstract public function logVardump($name, $var);
346
}
347