Issues (24)

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/PdoCouponFactory.php (2 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
namespace Germania\Coupons;
3
4
class PdoCouponFactory
5
{
6
7
    /**
8
     * @var string
9
     */
10
    public $php_class;
11
12
    /**
13
     * @var callable
14
     */
15
    public $coupon_sheet_factory;
16
17
18
    /**
19
     * @var PDOStatement
20
     */
21
    public $stmt;
22
23
24
    /**
25
     * @var string[]
26
     */
27
    protected static $coupon_fields_default = array(
28
        'id',
29
        'code',
30
        'coupon_sheet_id AS coupon_sheet',
31
    );
32
33
    /**
34
     * @var string[]
35
     */
36
    public static $coupon_fields = array();
37
38
    /**
39
     * @param \PDO   $pdo
40
     * @param string $coupons_table
41
     * @param callable $coupon_sheet_factory
42
     * @param string $php_class
43
     */
44
    public function __construct( \PDO $pdo, $coupons_table, callable $coupon_sheet_factory, $php_class = null)
45
    {
46
        $this->coupon_sheet_factory = $coupon_sheet_factory;
47
        $this->php_class = $php_class ?: Coupon::class;
48
49
        if (!is_subclass_of($this->php_class, CouponInterface::class ))
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Germania\Coupons\CouponInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
50
            throw new \InvalidArgumentException("Class name or instance of CouponInterface expected.");
51
52
        $sql_fields = join(",", array_merge(static::$coupon_fields_default, static::$coupon_fields));
53
54
        $sql = "SELECT
55
        {$sql_fields}
56
        FROM `{$coupons_table}`
57
58
        WHERE code = :code
59
        LIMIT 1";
60
61
        $this->stmt = $pdo->prepare( $sql );
0 ignored issues
show
Documentation Bug introduced by
It seems like $pdo->prepare($sql) of type object<PDOStatement> is incompatible with the declared type object<Germania\Coupons\PDOStatement> of property $stmt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
62
        $this->stmt->setFetchMode( \PDO::FETCH_CLASS, $this->php_class );
63
64
    }
65
66
    /**
67
     * @param  string|CouponInterface $code
68
     * @return CouponInterface[]
69
     */
70
    public function __invoke( $code )
71
    {
72
        if ($code instanceOf CouponInterface)
73
            $code = $code->getCode();
74
75
        if (!$this->stmt->execute([
76
            'code' => $code
77
        ])) {
78
            throw new \RuntimeException("Could not execute PDOStatement.");
79
        }
80
81
        $coupon = $this->stmt->fetch();
82
83
        if ($coupon and $this->coupon_sheet_factory):
84
            $coupon_sheet_factory = $this->coupon_sheet_factory;
85
            $coupon->coupon_sheet = $coupon_sheet_factory( $coupon->coupon_sheet );
86
        endif;
87
88
        return $coupon;
89
    }
90
91
}
92
93