Issues (1519)

system/modules/Libs/Libs.php (11 issues)

1
<?php
2
namespace Inji;
3
/**
4
 * Libs module
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class Libs extends Module {
12
13
    public function loadLib($libName, $options = []) {
14
        $className = 'Inji\Libs\\' . ucfirst($libName);
15
        if (class_exists($className)) {
16
            if (!empty($className::$composerPacks)) {
0 ignored issues
show
The property composerPacks does not exist on string.
Loading history...
17
                foreach ($className::$composerPacks as $packageName => $version) {
18
                    ComposerCmd::requirePackage($packageName, $version);
19
                }
20
            }
21
            if (!empty($className::$bowerPacks)) {
0 ignored issues
show
The property bowerPacks does not exist on string.
Loading history...
22
                foreach ($className::$bowerPacks as $packageName => $version) {
23
                    BowerCmd::requirePackage($packageName, $version);
24
                }
25
            }
26
            if (!empty($className::$requiredLibs)) {
0 ignored issues
show
The property requiredLibs does not exist on string.
Loading history...
27
                foreach ($className::$requiredLibs as $rLib) {
28
                    $this->loadLib($rLib);
29
                }
30
            }
31
            if (!empty($className::$files['css']) && (!isset($options['loadCss']) || $options['loadCss'])) {
0 ignored issues
show
The property files does not exist on string.
Loading history...
32
                foreach ($className::$files['css'] as $file) {
33
                    if (strpos($file, '/') === 0 || strpos($file, 'http') === 0) {
34
                        App::$cur->view->customAsset('css', $file, $libName);
0 ignored issues
show
Bug Best Practice introduced by
The property view does not exist on Inji\App. Since you implemented __get, consider adding a @property annotation.
Loading history...
The method customAsset() does not exist on Inji\Module. It seems like you code against a sub-type of Inji\Module such as Inji\Db. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
                        App::$cur->view->/** @scrutinizer ignore-call */ 
35
                                         customAsset('css', $file, $libName);
Loading history...
The method customAsset() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
                        App::$cur->view->/** @scrutinizer ignore-call */ 
35
                                         customAsset('css', $file, $libName);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
                    } else {
36
                        App::$cur->view->customAsset('css', '/static/libs/vendor/' . ucfirst($libName) . '/' . $file, $libName);
37
                    }
38
                }
39
            }
40
            if (!empty($className::$files['js'])) {
41
                foreach ($className::$files['js'] as $file) {
42
                    if (strpos($file, '/') === 0 || strpos($file, 'http') === 0) {
43
                        App::$cur->view->customAsset('js', $file, $libName);
44
                    } else {
45
                        App::$cur->view->customAsset('js', '/static/libs/vendor/' . ucfirst($libName) . '/' . $file, $libName);
46
                    }
47
                }
48
            }
49
            if (!empty($className::$files['bower'])) {
50
                $this->bowerFiles($libName, $className::$files['bower'], $options);
51
            }
52
        }
53
    }
54
55
    public function bowerFiles($libName, $files, $options) {
56
        if (!empty($files['css']) && (!isset($options['loadCss']) || $options['loadCss'])) {
57
            foreach ($files['css'] as $file) {
58
                App::$cur->view->customAsset('css', '/cache/static/bowerLibs/' . $file, $libName);
0 ignored issues
show
Bug Best Practice introduced by
The property view does not exist on Inji\App. Since you implemented __get, consider adding a @property annotation.
Loading history...
59
            }
60
        }
61
        if (!empty($files['js'])) {
62
            foreach ($files['js'] as $file) {
63
                App::$cur->view->customAsset('js', '/cache/static/bowerLibs/' . $file, $libName);
64
            }
65
        }
66
    }
67
68
    public function staticCalled($file, $dir) {
69
        $libPath = preg_replace('!^libs/!', '', $file);
70
        $libName = substr($libPath, 0, strpos($libPath, '/'));
71
        $className = 'Inji\Libs\\' . ucfirst($libName);
72
        if (class_exists($className)) {
73
            if (!empty($className::$programDirs)) {
0 ignored issues
show
The property programDirs does not exist on string.
Loading history...
74
                $fileDir = substr($libPath, strlen($libName) + 1, strpos($libPath, '/', strlen($libName) + 1) - strlen($libName) - 1);
75
                foreach ($className::$programDirs as $programDir) {
76
                    if ($programDir == $fileDir) {
77
                        include $dir . $file;
78
                        exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
79
                    }
80
                }
81
            }
82
        }
83
        return $dir . $file;
84
    }
85
86
    public function getPath($args) {
87
        if (!empty($args[0])) {
88
            $libName = 'Inji\Libs\\' . ucfirst($args[0]);
89
            if (class_exists($libName) && !empty($libName::$staticDirs)) {
0 ignored issues
show
The property staticDirs does not exist on string.
Loading history...
90
                $file = implode('/', array_slice($args, 1));
91
                foreach ($libName::$staticDirs as $dir) {
92
                    if (strpos($file, $dir) === 0) {
93
                        return \App::$primary->path . '/vendor/' . $file;
94
                    }
95
                }
96
            }
97
        }
98
        return false;
99
    }
100
}