Issues (47)

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/Object/Instantiate.php (3 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
 * Part of twLib
4
 * http://www.thomaswhiston.com
5
 * [email protected]
6
 * Created by PhpStorm.
7
 * User: Thomas Whiston
8
 * Date: 27/01/2016
9
 * Time: 14:14
10
 */
11
namespace twhiston\twLib\Object;
12
13
    /**
14
     * Class Instantiate
15
     * Create a class
16
     * @package twhiston\twLib\Object
17
     */
18
/**
19
 * Class Instantiate
20
 * @package twhiston\twLib\Object
21
 */
22
class Instantiate
23
{
24
25
26
    /**
27
     * @param $class
28
     * @param $args
29
     * @param $namespace string psr-4 style 'whatever\\thing\\another\\'
30
     * @param null $interface test that class implements this interface
31
     * @return object
32
     * @throws \Exception
33
     */
34 9
    public static function make($class, $args, $namespace = null, $interface = null)
35
    {
36
37
//        $count = substr_count($class, '\\');
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
38
//        if ($count = 0 || !(0 === strpos($class, 'Drupal'))) {
39
//            //if there is no '/' we assume this is not a fully qualified namespace and make it our root Constraint namespace
40
//            //If there is no drupal at the start then we assume its our class further down the tree
41
//            $class = $namespace.$class;
42
//        }
43
44 9
        if ($namespace !== null) {
45 7
            $class = $namespace . $class;
46 7
        }
47
48
        try {
49
50 9
            if (!class_exists($class, true)) {
51 5
                throw new \Exception('Class does not exist');
52
            }
53
54 4
            if ($interface !== null) {
55
56 4
                $imp = class_implements($class, true);
57 4
                if (!is_array($imp)) {
58
                    throw new \Exception('Does not implement an interface');
59
                }
60 4
                if (!in_array($interface, $imp)) {
61 2
                    throw new \Exception('Does not implement requested interface');
62
                }
63
64 2
            }
65
            //Make sure args are an array
66 2
            if ($args !== null && $args !== false) {
67 2
                $args = (!is_array($args)) ? array($args) : $args;
68 2
                if (is_array($args)) {
69 2
                    $c = count(array_filter(array_keys($args), 'is_string'));
0 ignored issues
show
$c 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...
70 2
                    if (count(array_filter(array_keys($args), 'is_string')) > 0) {
71
                        $args = [$args];
72
                    }
73 2
                }
74 2
            }
75
76 2
            $instance = Instantiate::instantiate($class, $args);
77
78 9
        } catch (\Exception $e) {
79 7
            throw $e;
80
        }
81
82 2
        return $instance;
83
    }
84
85
    /**
86
     * @param $class
87
     * @param $args
88
     * @return object
89
     */
90 2
    private static function instantiate($class, $args)
91
    {
92
//BOOOOO, this produces a parse error on less than 5.6.0
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% 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...
93
//        if (version_compare(phpversion(), '5.6.0') !== -1) {
94
//            $instance = new $class(...$args);
95
//        } else {
96 2
        $reflect = new \ReflectionClass($class);
97 2
        $instance = ($args === null || $args === false) ? $reflect->newInstanceArgs() : $reflect->newInstanceArgs($args);
98
//        }
99
100 2
        return $instance;
101
    }
102
103
}