ManifestManager::filePermissions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 9.4285
1
<?php
2
3
/**
4
 * Koch Framework
5
 * Jens-André Koch © 2005 - onwards.
6
 *
7
 * This file is part of "Koch Framework".
8
 *
9
 * License: GNU/GPL v2 or any later version, see LICENSE file.
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace Koch\Module;
26
27
/**
28
 * \Koch\Module\ManifestManager.
29
 */
30
class ManifestManager
0 ignored issues
show
Coding Style introduced by
ManifestManager does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
31
{
32
    /**
33
     * @var array contains the module informations
34
     */
35
    private static $modulesInfo = false;
36
37
    /**
38
     * @var array contains the system-wide module registry
39
     */
40
    private static $modulesRegistry = false;
41
42
    /**
43
     * Setter for module infos.
44
     *
45
     * @param array $module_infos_array
46
     */
47
    public static function setModuleInformations($module_infos_array)
0 ignored issues
show
Coding Style introduced by
$module_infos_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
48
    {
49
        self::$modulesInfo = $module_infos_array;
0 ignored issues
show
Coding Style introduced by
$module_infos_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
50
    }
51
52
    /**
53
     * Setter for modules registry.
54
     *
55
     * @param array $module_registry_array
56
     */
57
    public static function setModuleRegistry($module_registry_array)
0 ignored issues
show
Coding Style introduced by
$module_registry_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
58
    {
59
        self::$modulesRegistry = $module_registry_array;
0 ignored issues
show
Coding Style introduced by
$module_registry_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
60
    }
61
62
    /**
63
     * Reads the CMS Module Registry.
64
     *
65
     * This is the right method if you want to know if
66
     * a module is installed and active or deactivated.
67
     *
68
     * @return array Module Registry Array
69
     */
70
    public static function readModuleRegistry()
71
    {
72
        return \Koch\Config\Config()->read(APPLICATION_PATH . 'configuration/modules.config.php');
73
    }
74
75
    /**
76
     * Writes the Module Registry.
77
     *
78
     * @param array $array The Module Registry Array to write.
79
     *
80
     * @return bool
81
     */
82
    public static function writeModuleRegistry($array)
0 ignored issues
show
Coding Style introduced by
function writeModuleRegistry() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Unused Code introduced by
The parameter $array 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...
83
    {
84
        return \Koch\Config\Config()->write(APPLICATION_PATH . 'configuration/modules.config.php');
85
    }
86
87
    /**
88
     * Returns the module configuration as array.
89
     *
90
     * @param string $modulename
91
     *
92
     * @return array Module Configuration Array
93
     */
94
    public static function readModuleConfig($modulename)
95
    {
96
        return \Koch\Config\Config()->readModuleConfig($modulename);
97
    }
98
99
    /**
100
     * Checks if a modulename belongs to the core modules.
101
     *
102
     * @param string $modulename The modulename
103
     *
104
     * @return bool True if modulename is a core module, false otherwise.
105
     */
106
    public static function isCoreModule($modulename)
107
    {
108
        // hardcoded map with core modules
109
        static $core_modules = ['account', 'categories', 'controlcenter', 'doctrine', 'menu', 'modulemanager',
110
                                      'users', 'settings', 'systeminfo', 'thememanager', 'templatemanager', ];
111
112
        // @todo extract from module info file if core module or not
113
        return in_array($modulename, $core_modules, true);
0 ignored issues
show
Coding Style introduced by
$core_modules does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
114
    }
115
116
    /**
117
     * Get a list of all the module directories.
118
     *
119
     * @return array
120
     */
121
    public static function getModuleDirectories()
122
    {
123
        return glob(APPLICATION_MODULES_PATH . '[a-zA-Z]*', GLOB_ONLYDIR);
124
    }
125
126
    /**
127
     * Get a list of all the module names.
128
     *
129
     * 4 in 1 method, handling the following cases:
130
     * 1. array with module names
131
     * 2. named array with modulenames
132
     * 3. array with module names and paths
133
     * 4. named array with modulenames and paths
134
     *
135
     * @param bool $only_modulenames Toggle between only_names (true) and names+paths.
136
     * @param bool $named_array      Toggle between named (true) and unnamed array.
137
     *
138
     * @return array( $modulename => $module_path )
0 ignored issues
show
Documentation introduced by
The doc-type array( could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
139
     */
140
    public static function getModuleNames($named_array = false, $only_modulenames = false)
0 ignored issues
show
Coding Style introduced by
$named_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
141
    {
142
        $modules = [];
143
144
        $module_dirs = self::getModuleDirectories();
0 ignored issues
show
Coding Style introduced by
$module_dirs does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
145
146
        foreach ($module_dirs as $module_path) {
0 ignored issues
show
Coding Style introduced by
$module_dirs does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
147
            // strip path off
148
            $modulename = str_replace(APPLICATION_MODULES_PATH, '', $module_path);
0 ignored issues
show
Coding Style introduced by
$module_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
149
150
            if ($only_modulenames === true) {
0 ignored issues
show
Coding Style introduced by
$only_modulenames does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
151
                if ($named_array === false) {
0 ignored issues
show
Coding Style introduced by
$named_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
152
                    $modules[] = $modulename;
153
                } else {
154
                    $modules[] = ['name' => $modulename];
155
                }
156
            } else {
157
                if ($named_array === false) {
0 ignored issues
show
Coding Style introduced by
$named_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
158
                    $modules[] = [$modulename => $module_path];
0 ignored issues
show
Coding Style introduced by
$module_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
159
                } else {
160
                    $modules[] = ['name' => $modulename, 'path' => $module_path];
0 ignored issues
show
Coding Style introduced by
$module_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
161
                }
162
            }
163
        }
164
165
        return $modules;
166
    }
167
168
    /**
169
     * Returns all activated modules.
170
     *
171
     * @return array $activated_modules_array
172
     */
173
    public static function getAllActivatedModules()
174
    {
175
        $activated_modules_array = [];
0 ignored issues
show
Coding Style introduced by
$activated_modules_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
176
177
        $modules = self::getModuleNames(true);
178
179
        foreach ($modules as $module) {
180
            if (true === self::isModuleActive($module)) {
181
                $activated_modules_array[$module] = self::$modulesRegistry[$module];
0 ignored issues
show
Coding Style introduced by
$activated_modules_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
182
            }
183
        }
184
185
        return $activated_modules_array;
0 ignored issues
show
Coding Style introduced by
$activated_modules_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
186
    }
187
188
    /**
189
     * Checks if a module is active or deactived.
190
     *
191
     * @param bool $module True if module activated, false otherwise.
192
     */
193
    public static function isModuleActive($module)
194
    {
195
        // load module registry, if not available yet
196
        if (empty(self::$modulesRegistry[$module])) {
197
            self::$modulesRegistry = self::readModuleRegistry();
198
        }
199
200
        // check, if the module is
201
        if (isset(self::$modulesRegistry[$module]['active']) and self::$modulesRegistry[$module]['active'] === true) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
Coding Style introduced by
The if-else statement can be simplified to return isset(self::$modu...le]['active'] === true;.
Loading history...
202
            return true;
203
        } else {
204
            return false;
205
        }
206
    }
207
208
    /**
209
     * Fetches all pieces of information of a certain module.
210
     *
211
     * @param string $module
0 ignored issues
show
Documentation introduced by
Should the type for parameter $module not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
212
     *
213
     * @return array Module Informations
214
     */
215
    public static function getModuleInformations($module = null)
216
    {
217
        $modulename = strtolower($module);
218
219
        // check if the infos of this specific module were catched before
220
        if (self::$modulesInfo[$modulename] !== null) {
221
            return self::$modulesInfo[$modulename];
222
        }
223
224
        // fetch infos for the requested $module
225
        return self::loadModuleInformations($module);
226
    }
227
228
    public static function buildModuleRegistry()
229
    {
230
        foreach ($module_directories as $module_path) {
0 ignored issues
show
Coding Style introduced by
$module_directories does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The variable $module_directories does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
231
            // strip off path info and get the modulename
232
            $modulename = str_replace(APPLICATION_MODULES_PATH, '', $module_path);
0 ignored issues
show
Unused Code introduced by
$modulename is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Coding Style introduced by
$module_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
233
        }
234
235
        self::writeModuleRegistry();
0 ignored issues
show
Bug introduced by
The call to writeModuleRegistry() misses a required argument $array.

This check looks for function calls that miss required arguments.

Loading history...
236
    }
237
238
    /**
239
     * Gather Module Informations from Manifest Files.
240
     *
241
     * @staticvar array $modulesinfo
242
     *
243
     * @param mixed array|string $module array with modulenames or one modulename
244
     * @param string             $module
0 ignored issues
show
Documentation introduced by
Should the type for parameter $module not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
245
     *
246
     * @return moduleinformations (self::$modulesinfo)
0 ignored issues
show
Documentation introduced by
Should the return type not be array? Also, consider making the array more specific, something like array<String>, or String[].

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.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
247
     */
248
    public static function loadModuleInformations($module = null)
249
    {
250
        // Init vars
251
        $module_directories = [];
0 ignored issues
show
Coding Style introduced by
$module_directories does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
252
        $number_of_modules  = 0;
0 ignored issues
show
Coding Style introduced by
$number_of_modules does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
253
254
        /**
255
         * either fetch the module requested via parameter $module
256
         * fetch all modules.
257
         */
258
        if ($module === null) {
259
            $module_directories = self::getModuleDirectories();
0 ignored issues
show
Coding Style introduced by
$module_directories does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
260
        } else {
261
            // cast string to array
262
            $module_directories[] = APPLICATION_MODULES_PATH . $module;
0 ignored issues
show
Coding Style introduced by
$module_directories does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
263
        }
264
265
        foreach ($module_directories as $modulepath) {
0 ignored issues
show
Coding Style introduced by
$module_directories does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
266
            /*
267
             * create array with pieces of information about a module
268
             */
269
270
            // 1) get the modulename, by stripping off the path info
271
            $modulename = str_replace(APPLICATION_MODULES_PATH, '', $modulepath);
272
273
            self::$modulesinfo[$modulename]['name'] = $modulename;
274
            self::$modulesinfo[$modulename]['id']   = $number_of_modules;
0 ignored issues
show
Coding Style introduced by
$number_of_modules does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
275
            self::$modulesinfo[$modulename]['path'] = $modulepath;
276
            self::$modulesinfo[$modulename]['core'] = self::isCoreModule($modulename);
277
278
            // active - based on /configuration/modules.config.php
279
            self::$modulesinfo[$modulename]['active'] = self::isModuleActive($modulename);
280
281
            // hasMenu / ModuleNavigation
282
            self::$modulesinfo[$modulename]['menu'] = is_file($modulepath . '/' . $modulename . '.menu.php');
283
284
            // hasInfo
285
            $module_infofile = $modulepath . '/' . $modulename . '.info.php';
0 ignored issues
show
Coding Style introduced by
$module_infofile does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
286
            $config          = new \Koch\Config\Config();
287
288
            if (is_file($module_infofile)) {
0 ignored issues
show
Coding Style introduced by
$module_infofile does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
289
                #\Koch\Debug\Debug::firebug($module_infofile);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
290
291
                self::$modulesinfo[$modulename]['info'] = $config->read($module_infofile);
0 ignored issues
show
Coding Style introduced by
$module_infofile does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
292
            } else { // create file in DEV MODE
293
                // if the info file for a module does not exists yet, create it
294
                $config->write($module_infofile);
0 ignored issues
show
Coding Style introduced by
$module_infofile does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
295
            }
296
297
            // hasRoutes
298
299
            // hasConfig
300
            $config = self::readModuleConfig($modulename);
301
            if ($config[$modulename] !== null) {
302
                self::$modulesinfo[$modulename]['config'] = $config[$modulename];
303
304
                // properties
305
                if (isset($config['properties'])) {
306
                    self::$modulesinfo[$modulename]['settings'] = $config['properties'];
307
                }
308
            }
309
            /* else {
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
310
              $modules[$modulename]['config'] = $config;
311
              } */
312
313
            // hasLanguages
314
            self::$modulesinfo[$modulename]['languages'] = self::getLanguageInfosForModule($modulepath);
315
316
            // take some stats: increase the module counter
317
            self::$modulesinfo['yy_summary']['counter'] = ++$number_of_modules;
0 ignored issues
show
Coding Style introduced by
$number_of_modules does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
318
        }
319
320
        ksort(self::$modulesinfo);
321
322
        #\Koch\Debug\Debug::printR(self::$modulesinfo);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
323
324
        return self::$modulesinfo;
325
    }
326
327
    public static function getLanguageInfosForModule($modulepath)
328
    {
329
        $lang = [];
330
331
        // we are looking at the languages folder for the given module path
332
        $moduleLangDir = $modulepath . DIRECTORY_SEPARATOR . 'languages';
333
334
        // return early, if languages directory does not exist
335
        if (false === is_dir($moduleLangDir)) {
336
            return 'No language dir.';
337
        }
338
339
        // lets recurse this directory
340
        $iterator = new \RecursiveIteratorIterator(
341
            new \RecursiveDirectoryIterator($moduleLangDir, \FilesystemIterator::UNIX_PATHS),
342
            \RecursiveIteratorIterator::LEAVES_ONLY
343
        );
344
345
        // some leaves found (dirs and files)
346
        foreach ($iterator as $file) {
347
            // proceed with iteration instantly, if file is not a gettext file
348
            if (0 === preg_match('/.(mo|po)$/', $file->getFileName())) {
349
                continue;
350
            }
351
352
            // fetch locale from path (en_UK, de_DE)
353
            if (1 === preg_match('/[a-z]{2}_[A-Z]{2}/', $file->getPathName(), $match)) {
354
                $locale = $match[0];
355
            }
356
357
            // fetch file extension (mo|po)
358
            if (version_compare(PHP_VERSION, '5.3.6') >= 0) {
359
                $ext = $file->getExtension();
360
            } else { // php lower then 5.3.6
361
                $ext = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
362
            }
363
364
            $isReadable = $file->isReadable() ? 'r' : '';
365
            $isWritable = $file->isWritable() ? 'w' : '';
366
367
            /*
368
             * Add some more pieces of information about the file
369
             */
370
            $lang[$locale][$ext]['pathName']       = realpath($file->getPathName());
0 ignored issues
show
Bug introduced by
The variable $locale does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
371
            $lang[$locale][$ext]['fileName']       = $file->getFileName();
372
            $lang[$locale][$ext]['filePermString'] = self::filePermissions($lang[$locale][$ext]['pathName']);
373
            $lang[$locale][$ext]['fileReadable']   = $file->isReadable();
374
            $lang[$locale][$ext]['fileWriteable']  = $file->isWritable();
375
            $lang[$locale][$ext]['timestamp']      = date(DATE_FORMAT, $file->getCTime());
376
            $lang[$locale][$ext]['cssClass']       = '-' . $isReadable . $isWritable;
377
        }
378
379
        /*
380
         * Add some more pieces of information about the locale
381
         */
382
383
         // if the language definitions are not already loaded, load them
384
        if (empty(self::$l10n_sys_locales)) {
385
            // fetch arrays containing locale data
386
            require __DIR__ . '/../Localization/Locales.php';
387
            self::$l10n_sys_locales = $l10n_sys_locales;
0 ignored issues
show
Coding Style introduced by
$l10n_sys_locales does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The variable $l10n_sys_locales does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
388
        }
389
390
        foreach ($lang as $locale => $filedata) {
391
            // get more data about that locale from the locales array
392
            if (isset(self::$l10n_sys_locales[$locale]) === true) {
393
                $lang[$locale]['country_www'] = self::$l10n_sys_locales[$locale]['country-www'];
394
                $lang[$locale]['lang_native'] = self::$l10n_sys_locales[$locale]['lang-native'];
395
                $lang[$locale]['lang_www']    = self::$l10n_sys_locales[$locale]['lang-www'];
396
                $lang[$locale]['lang']        = self::$l10n_sys_locales[$locale]['lang'];
397
            } else { // locale not in locales array
398
                $lang[$locale]['country_www'] = 'unknown';
399
                $lang[$locale]['lang_native'] = '<em>locale: </em>' . $locale;
400
                $lang[$locale]['lang_www']    = '';
401
                $lang[$locale]['lang']        = $locale;
402
            }
403
        }
404
405
        #\Koch\Debug\Debug::printR($langinfo);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
406
407
        return $lang;
408
    }
409
410
    /**
411
     * Returns file permissions as string.
412
     *
413
     * @staticvar array $permissions
414
     *
415
     * @param type $filename
416
     *
417
     * @return string File Permissions as string, e.h. "rwx", "rw-"
418
     */
419
    private static function filePermissions($filename)
420
    {
421
        static $permissions = ['---', '--x', '-w-', '-wx', 'r--', 'r-x', 'rw-', 'rwx'];
422
        $perm_oct           = substr(decoct(fileperms($filename)), 3);
0 ignored issues
show
Coding Style introduced by
$perm_oct does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
423
424
        $string = '[';
425
        $string .= $permissions[(int) $perm_oct[0]] . '|';
0 ignored issues
show
Coding Style introduced by
$perm_oct does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
426
        $string .= $permissions[(int) $perm_oct[1]] . '|';
0 ignored issues
show
Coding Style introduced by
$perm_oct does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
427
        $string .= $permissions[(int) $perm_oct[2]] . ']';
0 ignored issues
show
Coding Style introduced by
$perm_oct does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
428
429
        return $string;
430
    }
431
}
432