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.

Issues (3647)

symphony/lib/toolkit/class.eventmanager.php (17 issues)

1
<?php
2
/**
3
 * @package toolkit
4
 */
5
/**
6
 * The EventManager class is responsible for managing all Event objects
7
 * in Symphony. Event's are stored on the file system either in the
8
 * /workspace/events folder or provided by an extension in an /events folder.
9
 * Events run from the Frontend usually to add new entries to the system, but
10
 * they are not limited to that facet.
11
 */
12
13
class EventManager implements FileResource
14
{
15
    /**
16
     * Given the filename of an Event return it's handle. This will remove
17
     * the Symphony convention of `event.*.php`
18
     *
19
     * @param string $filename
20
     *  The filename of the Event
21
     * @return string
22
     */
23
    public static function __getHandleFromFilename($filename)
24
    {
25
        return preg_replace(array('/^event./i', '/.php$/i'), '', $filename);
26
    }
27
28
    /**
29
     * Given a name, returns the full class name of an Event. Events
30
     * use an 'event' prefix.
31
     *
32
     * @param string $handle
33
     *  The Event handle
34
     * @return string
35
     */
36
    public static function __getClassName($handle)
37
    {
38
        return 'event' . $handle;
39
    }
40
41
    /**
42
     * Finds an Event by name by searching the events folder in the workspace
43
     * and in all installed extension folders and returns the path to it's folder.
44
     *
45
     * @param string $handle
46
     *  The handle of the Event free from any Symphony conventions
47
     *  such as `event.*.php`
48
     * @return string|boolean
49
     *  If the Event is found, the function returns the path it's folder, otherwise false.
50
     */
51
    public static function __getClassPath($handle)
52
    {
53
        if (is_file(EVENTS . "/event.$handle.php")) {
0 ignored issues
show
The constant EVENTS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $handle instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
54
            return EVENTS;
55
        } else {
56
            $extensions = Symphony::ExtensionManager()->listInstalledHandles();
57
58
            if (is_array($extensions) && !empty($extensions)) {
59
                foreach ($extensions as $e) {
60
                    if (is_file(EXTENSIONS . "/$e/events/event.$handle.php")) {
0 ignored issues
show
The constant EXTENSIONS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $e instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $handle instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
61
                        return EXTENSIONS . "/$e/events";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $e instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
62
                    }
63
                }
64
            }
65
        }
66
67
        return false;
68
    }
69
70
    /**
71
     * Given a name, return the path to the Event class
72
     *
73
     * @see toolkit.EventManager#__getClassPath()
74
     * @param string $handle
75
     *  The handle of the Event free from any Symphony conventions
76
     *  such as event.*.php
77
     * @return string
78
     */
79
    public static function __getDriverPath($handle)
80
    {
81
        return self::__getClassPath($handle) . "/event.$handle.php";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $handle instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
82
    }
83
84
    /**
85
     * Finds all available Events by searching the events folder in the workspace
86
     * and in all installed extension folders. Returns an associative array of Events.
87
     *
88
     * @see toolkit.Manager#about()
89
     * @return array
90
     *  Associative array of Events with the key being the handle of the Event
91
     *  and the value being the Event's `about()` information.
92
     */
93
    public static function listAll()
94
    {
95
        $result = array();
96
        $structure = General::listStructure(EVENTS, '/event.[\\w-]+.php/', false, 'ASC', EVENTS);
0 ignored issues
show
The constant EVENTS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Are you sure the assignment to $structure is correct as General::listStructure(E..., false, 'ASC', EVENTS) targeting General::listStructure() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
97
98
        if (is_array($structure['filelist']) && !empty($structure['filelist'])) {
99
            foreach ($structure['filelist'] as $f) {
100
                $f = self::__getHandleFromFilename($f);
101
102
                if ($about = self::about($f)) {
103
                    $classname = self::__getClassName($f);
104
                    $env = array();
105
                    $class = new $classname($env);
106
107
                    $about['can_parse'] = method_exists($class, 'allowEditorToParse')
108
                        ? $class->allowEditorToParse()
0 ignored issues
show
Inline shorthand IF statement must be declared on a single line
Loading history...
109
                        : false;
110
111
                    $about['source'] = method_exists($class, 'getSource')
112
                        ? $class->getSource()
0 ignored issues
show
Inline shorthand IF statement must be declared on a single line
Loading history...
113
                        : null;
114
115
                    $result[$f] = $about;
116
                }
117
            }
118
        }
119
120
        $extensions = Symphony::ExtensionManager()->listInstalledHandles();
121
122
        if (is_array($extensions) && !empty($extensions)) {
123
            foreach ($extensions as $e) {
124
                if (!is_dir(EXTENSIONS . "/$e/events")) {
0 ignored issues
show
The constant EXTENSIONS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $e instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
125
                    continue;
126
                }
127
128
                $tmp = General::listStructure(EXTENSIONS . "/$e/events", '/event.[\\w-]+.php/', false, 'ASC', EXTENSIONS . "/$e/events");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $e instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Are you sure the assignment to $tmp is correct as General::listStructure(E...ONS . '/'.$e.'/events') targeting General::listStructure() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
129
130
                if (is_array($tmp['filelist']) && !empty($tmp['filelist'])) {
131
                    foreach ($tmp['filelist'] as $f) {
132
                        $f = self::__getHandleFromFilename($f);
133
134
                        if ($about = self::about($f)) {
135
                            $about['can_parse'] = false;
136
                            $result[$f] = $about;
137
                        }
138
                    }
139
                }
140
            }
141
        }
142
143
        ksort($result);
144
        return $result;
145
    }
146
147
    public static function about($name)
148
    {
149
        $classname = self::__getClassName($name);
150
        $path = self::__getDriverPath($name);
151
152
        if (!@file_exists($path)) {
153
            return false;
154
        }
155
156
        require_once $path;
157
158
        $handle = self::__getHandleFromFilename(basename($path));
159
        $env = array();
160
        $class = new $classname($env);
161
162
        try {
163
            $method = new ReflectionMethod($classname, 'about');
164
            $about = $method->invoke($class);
165
        } catch (ReflectionException $e) {
166
            $about = array();
167
        }
168
169
        return array_merge($about, array('handle' => $handle));
170
    }
171
172
    /**
173
     * Creates an instance of a given class and returns it.
174
     *
175
     * @param string $handle
176
     *  The handle of the Event to create
177
     * @param array $env
178
     *  The environment variables from the Frontend class which includes
179
     *  any params set by Symphony or Datasources or by other Events
180
     * @throws Exception
181
     * @return Event
182
     */
183
    public static function create($handle, array $env = null)
0 ignored issues
show
Incorrect spacing between argument "$env" and equals sign; expected 0 but found 1
Loading history...
Incorrect spacing between default value and equals sign for argument "$env"; expected 0 but found 1
Loading history...
184
    {
185
        $classname = self::__getClassName($handle);
186
        $path = self::__getDriverPath($handle);
187
188
        if (!is_file($path)) {
189
            throw new Exception(
190
                __('Could not find Event %s.', array('<code>' . $handle . '</code>'))
191
                . ' ' . __('If it was provided by an Extension, ensure that it is installed, and enabled.')
192
            );
193
        }
194
195
        if (!class_exists($classname)) {
196
            require_once $path;
197
        }
198
199
        return new $classname($env);
200
    }
201
}
202