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
Pull Request — master (#186)
by
unknown
11:15 queued 05:03
created

functions.php ➔ tryTo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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
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
use DataSift\Storyplayer\PlayerLib\Story;
45
use DataSift\Storyplayer\PlayerLib\StoryTeller;
46
use DataSift\Storyplayer\DefinitionLib\TestEnvironment_Definition;
47
use Prose\E5xx_ActionFailed;
48
use Prose\E5xx_ProseException;
49
50
/**
51
 * return the first element in an array
52
 *
53
 * this function avoids reset()ing the array, so it will not mess with
54
 * any iteration that you may currently be part-way through
55
 *
56
 * @param  array $arrayToSearch
57
 *         the array to get the first element of
58
 * @return mixed
59
 *         the first element of $array, or NULL if the array is empty
60
 */
61
function first($arrayToSearch)
62
{
63
    if (!is_array($arrayToSearch)) {
64
        return null;
65
    }
66
67
    if (count($arrayToSearch) == 0) {
68
        return null;
69
    }
70
71
    $keys = array_keys($arrayToSearch);
72
    $key = reset($keys);
73
74
    return $arrayToSearch[$key];
75
}
76
77
/**
78
 * Create a new story object
79
 *
80
 * @param  string $category the category that the story belongs to
81
 * @return Story            the new story object to use
82
 */
83
function newStoryFor($category)
84
{
85
    $story = new Story();
86
    $story->setCategory($category);
87
88
    // our output reports may need to know which file the story itself
89
    // is defined in
90
    $story->determineStoryFilename();
91
92
    return $story;
93
}
94
95
/**
96
 * Create a new test environment object
97
 *
98
 * @return TestEnvironment
0 ignored issues
show
Documentation introduced by
Should the return type not be TestEnvironment_Definition?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
99
 *         the test environment object to use in the script
100
 */
101
function newTestEnvironment()
102
{
103
    // work out the name of this test environment
104
    $trace = debug_backtrace();
105
    $filename = $trace[0]['file'];
106
    $name = basename(dirname($filename));
107
108
    $testEnv = new TestEnvironment_Definition($name);
109
    return $testEnv;
110
}
111
112
/**
113
 * Attempt an action, and if it fails, swallow the failure
114
 *
115
 * @param  callback $callback the action(s) to attempt
116
 * @return void
117
 */
118
function tryTo($callback) {
119
    try {
120
        $callback();
121
    }
122
    catch (E5xx_ProseException $e) {
123
        // do nothing
124
    }
125
}
126