Issues (255)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Module.php (28 issues)

Upgrade to new PHP Analysis Engine

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
Accessing php 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
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 $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...
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
The variable $id 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...
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.

Loading history...
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.

Loading history...
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.

Loading history...
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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
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.

Loading history...
Space found before comma in function call
Loading history...
113
                foreach ( $resources as $resource ) {
0 ignored issues
show
Space found after opening bracket of FOREACH loop
Loading history...
Space found before closing bracket of FOREACH loop
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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;
Loading history...
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;
Loading history...
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.

Loading history...
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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
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.

Loading history...
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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Blank line found at start of control structure
Loading history...
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
The parameter $file 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...
The parameter $code 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...
The parameter $namespace 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...
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
The parameter $module 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...
Method name "Module::compress_php" is not in camel caps format
Loading history...
160
    {
161
        $this->logger->log(' - Compressing PHP file[##]', $file);
162
        return $this->compressCode($file, $code, $namespace);
163
    }
164
}
165