This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Created by PhpStorm. |
||
4 | * User: egorov |
||
5 | * Date: 11.01.2015 |
||
6 | * Time: 9:18 |
||
7 | */ |
||
8 | |||
9 | namespace samsonos\compressor; |
||
10 | |||
11 | use samsonphp\compressor\Code; |
||
12 | use samsonphp\compressor\Compressor; |
||
13 | |||
14 | /** |
||
15 | * Class for automatic SamsonPHP module optimization|compression |
||
16 | * |
||
17 | * @package samsonos\compressor |
||
18 | * @author Vitaly Iegorov <[email protected]> |
||
19 | */ |
||
20 | class Module |
||
21 | { |
||
22 | /** @var \samson\core\Core Core pointer */ |
||
23 | protected $core; |
||
24 | |||
25 | /** @var \samson\core\CompressableExternalModule Module pointer */ |
||
26 | protected $module; |
||
27 | |||
28 | /** @var Object Logger object */ |
||
29 | protected $logger; |
||
30 | |||
31 | /** @var array Collection of module PHP code */ |
||
32 | protected $code = array(); |
||
33 | |||
34 | /** @var array Ignored resource extensions */ |
||
35 | public $ignoredExtensions = array( |
||
36 | 'php', 'js', 'css', 'md', 'map', 'dbs', 'vphp', 'less' , 'gz', 'lock', 'json', 'sql', 'xml', 'yml' |
||
37 | ); |
||
38 | |||
39 | /** |
||
40 | * @param \samson\core\Core $core Core pointer |
||
41 | * @param \samson\core\CompressableExternalModule $module Module pointer |
||
42 | * @param object $logger Logger object |
||
43 | */ |
||
44 | public function __construct($core, $module, $logger = null) |
||
45 | { |
||
46 | $this->core = & $core; |
||
47 | $this->module = & $module; |
||
48 | $this->logger = & $logger; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Perform module compression |
||
53 | * @return bool True if module was successfully compressed |
||
54 | */ |
||
55 | public function compress() |
||
56 | { |
||
57 | // Cache module ID |
||
58 | $id = $this->module->id(); |
||
59 | |||
60 | $this->logger->log(' - Compressing module[##]', $id); |
||
61 | |||
62 | // Call special method enabling module personal resource pre-management on compressing |
||
63 | if ($this->module->beforeCompress($this, $this->code) !== false) { |
||
64 | //$this->compressResources(); |
||
65 | //$this->compressView(); |
||
66 | //$this->compressTemplate(); |
||
67 | |||
68 | if (is_a($this->module->resourceMap, 'samson\core\ResourceMap')) { |
||
69 | $sources = array_merge( |
||
70 | $this->module->resourceMap->php, |
||
0 ignored issues
–
show
|
|||
71 | $this->module->resourceMap->controllers, |
||
0 ignored issues
–
show
Accessing
controllers on the interface samsonframework\core\ResourcesInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
72 | $this->module->resourceMap->models, |
||
0 ignored issues
–
show
Accessing
models on the interface samsonframework\core\ResourcesInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
73 | $this->module->resourceMap->globals |
||
0 ignored issues
–
show
Accessing
globals on the interface samsonframework\core\ResourcesInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
74 | ); |
||
75 | |||
76 | // Add module class files to array of sources |
||
77 | foreach ($this->module->resourceMap->modules as $module) { |
||
0 ignored issues
–
show
Accessing
modules on the interface samsonframework\core\ResourcesInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
78 | $sources = array_merge(array($module[1]), $sources); |
||
79 | } |
||
80 | |||
81 | // Create code collector |
||
82 | $code = new Code($sources, $this->logger); |
||
0 ignored issues
–
show
$code 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 ![]() |
|||
83 | } |
||
84 | |||
85 | // Change module path, now all modules would be located at wwwroot folder |
||
86 | //$this->module->path($id.'/'); |
||
87 | |||
88 | // Call special method enabling module personal resource post-management on compressing |
||
89 | //$this->module->afterCompress($this, $this->code); |
||
90 | |||
91 | return true; |
||
92 | } |
||
93 | |||
94 | $this->logger->log(' - Module[##] compression stopped', $id); |
||
95 | |||
96 | return false; |
||
97 | } |
||
98 | |||
99 | public function compressResources() |
||
100 | { |
||
101 | // Build output module path |
||
102 | $destination = $id == 'local' ? '' : $id.'/'; |
||
0 ignored issues
–
show
|
|||
103 | |||
104 | // Build resource source path |
||
105 | $source = $id == 'local' ? $this->module->path().__SAMSON_PUBLIC_PATH : $this->module->path(); |
||
106 | |||
107 | $this->log(' -> Copying resources from [##] to [##]', $module_path, $module_output_path); |
||
0 ignored issues
–
show
The variable
$module_path 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. ![]() The variable
$module_output_path 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. ![]() The method
log() does not seem to exist on object<samsonos\compressor\Module> .
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. ![]() |
|||
108 | |||
109 | // Iterate module resources |
||
110 | foreach ($this->module->resourceMap->resources as $extension => $resources) { |
||
0 ignored issues
–
show
Accessing
resources on the interface samsonframework\core\ResourcesInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
111 | // Iterate only allowed resource types |
||
112 | if (!in_array( $extension , $this->ignored_extensions)) { |
||
0 ignored issues
–
show
The property
ignored_extensions does not seem to exist. Did you mean ignoredExtensions ?
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. ![]() |
|||
113 | foreach ( $resources as $resource ) { |
||
0 ignored issues
–
show
|
|||
114 | // Get only filename |
||
115 | $filename = basename( $resource ); |
||
116 | |||
117 | // Copy only allowed resources |
||
118 | if (!in_array( $filename, $this->ignored_resources)) { |
||
0 ignored issues
–
show
The property
ignored_resources does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
119 | // Build relative module resource path |
||
120 | $relative_path = str_replace($module_path, '', $resource); |
||
121 | |||
122 | // Build correct destination folder |
||
123 | $dst = $this->output.$module_output_path.$relative_path; |
||
0 ignored issues
–
show
The property
output does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
124 | |||
125 | // Copy/update file if necessary |
||
126 | $this->copy_resource( $resource, $dst ); |
||
0 ignored issues
–
show
The method
copy_resource() does not seem to exist on object<samsonos\compressor\Module> .
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. ![]() |
|||
127 | } |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | |||
132 | // Copy all module resources |
||
133 | $this->copy_path_resources($this->module->resourceMap->resources, $source, $destination); |
||
0 ignored issues
–
show
Accessing
resources on the interface samsonframework\core\ResourcesInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() The method
copy_path_resources() does not seem to exist on object<samsonos\compressor\Module> .
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. ![]() |
|||
134 | } |
||
135 | |||
136 | public function compressView() |
||
137 | { |
||
138 | // Iterate all views |
||
139 | foreach ($this->module->resourceMap->views as $view) { |
||
0 ignored issues
–
show
Accessing
views on the interface samsonframework\core\ResourcesInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
140 | |||
141 | } |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Recursively gather PHP code from file and gather |
||
146 | * it into array, grouped by namespace |
||
147 | */ |
||
148 | public function compressCode($file, array $code = array(), $namespace = Compressor::NS_GLOBAL) |
||
0 ignored issues
–
show
|
|||
149 | { |
||
150 | |||
151 | } |
||
152 | |||
153 | public function compressTemplate() |
||
154 | { |
||
155 | |||
156 | } |
||
157 | |||
158 | /** @deprecated Use compressCode() instead */ |
||
159 | public function compress_php($file, $module, array $code = array(), $namespace = Compressor::NS_GLOBAL) |
||
0 ignored issues
–
show
|
|||
160 | { |
||
161 | $this->logger->log(' - Compressing PHP file[##]', $file); |
||
162 | return $this->compressCode($file, $code, $namespace); |
||
163 | } |
||
164 | } |
||
165 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: