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 ( 467c2a...fdb351 )
by Stuart
05:47
created

UbLangConsole::logCliWarning()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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/Console
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\Console;
45
46
use DataSift\Storyplayer\OutputLib\CodeFormatter;
47
use DataSift\Storyplayer\Phases\Phase;
48
use DataSift\Storyplayer\PlayerLib\Phase_Result;
49
use DataSift\Storyplayer\PlayerLib\PhaseGroup_Result;
50
use DataSift\Storyplayer\PlayerLib\Story_Result;
51
use DataSift\Storyplayer\PlayerLib\Story;
52
53
/**
54
 * the console plugin we use to show the user how each story is going
55
 *
56
 * @category  Libraries
57
 * @package   Storyplayer/Console
58
 * @author    Stuart Herbert <[email protected]>
59
 * @copyright 2011-present Mediasift Ltd www.datasift.com
60
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
61
 * @link      http://datasift.github.io/storyplayer
62
 */
63
class UbLangConsole extends Console
64
{
65
    protected $currentPhase;
66
    protected $currentPhaseStep;
67
    protected $phaseNumber = 0;
68
    protected $phaseMessages = array();
69
70
    /**
71
     * a list of the results we have received from stories
72
     * @var array
73
     */
74
    protected $storyResults = [];
75
76
    /**
77
     * called when storyplayer starts
78
     *
79
     * @param string $version
80
     * @param string $url
81
     * @param string $copyright
82
     * @param string $license
83
     * @return void
84
     */
85
    public function startStoryplayer($version, $url, $copyright, $license)
86
    {
87
        $this->write("Storyplayer {$version}", $this->writer->highlightStyle);
88
        $this->write(" - ");
89
        $this->write($url, $this->writer->urlStyle);
90
        $this->write(PHP_EOL);
91
        $this->write($copyright . PHP_EOL);
92
        $this->write($license . PHP_EOL . PHP_EOL);
93
    }
94
95
    public function endStoryplayer($duration)
96
    {
97
        $this->writeFinalReport($duration, true);
98
    }
99
100
    /**
101
     * called when we start a new set of phases
102
     *
103
     * @param  string $activity
104
     *         what are we doing? (e.g. 'creating', 'running')
105
     * @param  string $name
106
     *         the name of the phase group
107
     * @param  array|null $details
108
     *         optional explanation of what this PhaseGroup is trying
109
     *         to achieve
110
     * @return void
111
     */
112
    public function startPhaseGroup($activity, $name, $details = null)
113
    {
114
        $this->write($activity . ' ', $this->writer->activityStyle);
115
        $this->write($name, $this->writer->nameStyle);
116
        $this->write(' ...' . PHP_EOL, $this->writer->punctuationStyle);
117
118
        if (is_array($details)) {
119
            $this->write('  Scenario: ' . PHP_EOL);
120
            foreach ($details as $line) {
121
                $this->write('    ' . $line . PHP_EOL);
122
            }
123
        }
124
    }
125
126 View Code Duplication
    public function endPhaseGroup($result)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        // tell the user what happened
129
        $this->write('  Result: ');
130
        if ($result->getPhaseGroupSkipped()) {
131
            $this->writePhaseGroupSkipped($result->getResultString());
132
        }
133
        else if ($result->getPhaseGroupSucceeded()) {
134
            $this->writePhaseGroupSucceeded($result->getResultString());
135
        }
136
        else {
137
            $this->writePhaseGroupFailed($result->getResultString());
138
        }
139
140
        // write out the duration too
141
        $this->write(' (', $this->writer->punctuationStyle);
142
        $this->writeDuration($result->getDuration());
143
        $this->write(')' . PHP_EOL, $this->writer->punctuationStyle);
144
145
        // remember the result for the final report
146
        //
147
        // we have to clone as the result object apparently changes
148
        // afterwards. no idea why (yet)
149
        $this->results[] = clone $result;
150
151
        // if we are not connected to a terminal, we need to write out
152
        // a detailed error report
153
        if (!function_exists("posix_isatty") || !posix_isatty(STDOUT)) {
154
            $this->writeDetailedErrorReport($result);
155
        }
156
    }
157
158
    /**
159
     * called when a story starts a new phase
160
     *
161
     * @return void
162
     */
163
    public function startPhase($phase)
164
    {
165
        // shorthand
166
        $phaseType  = $phase->getPhaseType();
167
        $phaseSeqNo = $phase->getPhaseSequenceNo();
168
169
        $this->currentPhaseType = $phaseType;
0 ignored issues
show
Bug introduced by
The property currentPhaseType does not seem to exist. Did you mean currentPhase?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
170
171
        // we're only interested in telling the user about the
172
        // phases of a story
173
        if ($phaseType !== Phase::STORY_PHASE) {
174
            return;
175
        }
176
177
        // remember the phase for later use
178
        $this->currentPhase = $phaseSeqNo;
179
        $this->currentPhaseName = $phase->getPhaseName();
0 ignored issues
show
Bug introduced by
The property currentPhaseName does not seem to exist. Did you mean currentPhase?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
180
        $this->currentPhaseStep = 0;
181
    }
182
183
    /**
184
     * called when a story ends a phase
185
     *
186
     * @return void
187
     */
188
    public function endPhase($phase, $phaseResult)
189
    {
190
        // shorthand
191
        $phaseType = $phase->getPhaseType();
192
193
        // we're only interested in telling the user about the
194
        // phases of a story
195
        if ($phaseType !== Phase::STORY_PHASE) {
196
            return;
197
        }
198
199
        // if there was no output for the phase, skip the report
200
        if ($this->currentPhaseStep === 0) {
201
            return;
202
        }
203
204
        if ($phaseResult->getPhaseFailed()) {
205
            $this->writePhaseGroupFailed($phaseResult->getPhaseResultString());
206
        }
207
        else if ($phaseResult->getPhaseIsIncomplete() || $phaseResult->getPhaseIsBlacklisted()) {
208
            $this->writePhaseGroupSkipped( $phaseResult->getPhaseResultString());
209
        }
210
        $this->write(PHP_EOL);
211
    }
212
213
    /**
214
     * called when a story logs an action
215
     *
216
     * @param string $msg
217
     * @return void
218
     */
219
    public function logPhaseActivity($msg, $codeLine = null)
220
    {
221
        // has output been suppressed?
222
        if ($this->isSilent()) {
223
            return;
224
        }
225
226
        // we only want Story phases
227
        if ($this->currentPhaseType !== Phase::STORY_PHASE) {
0 ignored issues
show
Bug introduced by
The property currentPhaseType does not seem to exist. Did you mean currentPhase?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
228
            return;
229
        }
230
231
        // skip any empty messages (just in case)
232
        if (strlen($msg) === 0) {
233
            return;
234
        }
235
236
        // we only want the top-level messages
237
        if ($msg{0} == ' ') {
238
            return;
239
        }
240
241
        // special case - not the first message for a phase
242
        if ($this->currentPhaseStep !== 0) {
243
            $this->write(PHP_EOL);
244
        }
245
246
        $this->write('  ' . $this->currentPhase . chr(ord('a') + $this->currentPhaseStep) . ' ', $this->writer->miniPhaseNameStyle);
247
        $this->write($msg . ' ');
248
249
        $this->currentPhaseStep++;
250
    }
251
252
    /**
253
     * called when a story logs the (possibly partial) output from
254
     * running a subprocess
255
     *
256
     * @param  string $msg the output to log
257
     * @return void
258
     */
259
    public function logPhaseSubprocessOutput($msg)
260
    {
261
        // no-op?
262
    }
263
264
    /**
265
     * called when a story logs an error
266
     *
267
     * @param string $phaseName
268
     * @param string $msg
269
     * @return void
270
     */
271
    public function logPhaseError($phaseName, $msg)
272
    {
273
        // no-op?
274
    }
275
276
    /**
277
     * called when a story is skipped
278
     *
279
     * @param string $phaseName
280
     * @param string $msg
281
     * @return void
282
     */
283
    public function logPhaseSkipped($phaseName, $msg)
284
    {
285
        // no-op?
286
    }
287
288
    public function logPhaseCodeLine($codeLine)
0 ignored issues
show
Unused Code introduced by
The parameter $codeLine is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
289
    {
290
        // this is a no-op for us
291
    }
292
293
    /**
294
     * called when the outer CLI shell encounters a fatal error
295
     *
296
     * @param  string $msg
297
     *         the error message to show the user
298
     *
299
     * @return void
300
     */
301
    public function logCliError($msg)
302
    {
303
        $this->write("*** error: $msg" . PHP_EOL);
304
    }
305
306
    /**
307
     *
308
     * @param  string $msg
309
     * @param  Exception $e
310
     * @return void
311
     */
312
    public function logCliErrorWithException($msg, $e)
313
    {
314
        $this->write("*** error: $msg" . PHP_EOL . PHP_EOL
315
             . "This was caused by an unexpected exception " . get_class($e) . PHP_EOL . PHP_EOL
316
             . $e->getTraceAsString() . PHP_EOL);
317
    }
318
319
    /**
320
     * called when the outer CLI shell needs to publish a warning
321
     *
322
     * @param  string $msg
323
     *         the warning message to show the user
324
     *
325
     * @return void
326
     */
327
    public function logCliWarning($msg)
328
    {
329
        $this->write("*** warning: $msg" . PHP_EOL);
330
    }
331
332
    /**
333
     * called when the outer CLI shell needs to tell the user something
334
     *
335
     * @param  string $msg
336
     *         the message to show the user
337
     *
338
     * @return void
339
     */
340
    public function logCliInfo($msg)
341
    {
342
        $this->write($msg . PHP_EOL);
343
    }
344
345
    /**
346
     * an alternative to using PHP's built-in var_dump()
347
     *
348
     * @param  string $name
349
     *         a human-readable name to describe $var
350
     *
351
     * @param  mixed $var
352
     *         the variable to dump
353
     *
354
     * @return void
355
     */
356
    public function logVardump($name, $var)
357
    {
358
        // this is a no-op for us
359
    }
360
}
361