Issues (6)

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/ObjectTrait.php (5 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
 * Collection library for Yii2.
4
 *
5
 * @link      https://github.com/hiqdev/yii2-collection
6
 * @package   yii2-collection
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\collection;
12
13
use hiqdev\php\collection\BaseTrait;
14
use yii\base\ArrayableTrait;
15
16
/**
17
 * ObjectTrait.
18
 * Intended to be used for yii\base\BaseObject descendants.
19
 * Uses canSet/GetPropperty and magic functions to provide compatible getter/setter mechanisms.
20
 */
21
trait ObjectTrait
22
{
23
    use ArrayableTrait;
24
    use BaseTrait {
25
        BaseTrait::fields insteadof ArrayableTrait;
26
    }
27
28
    /**
29
     * Returns property of item by name.
30
     * @param mixed $name
31
     * @return mixed
32
     */
33 20
    public function get($name)
34
    {
35 20
        return $this->__get($name);
36
    }
37
38
    /**
39
     * Sets an item. Silently resets if already exists.
40
     * @param int|string   $name
41
     * @param mixed        $value the element value
42
     * @param string|array $where where to put, see [[setItem()]]
43
     * @see setItem()
44
     */
45 80
    public function set($name, $value, $where = '')
46
    {
47 80
        if (($name && $this->canSetProperty($name)) || strpos($name, 'on ') === 0 || strpos($name, 'as ') === 0) {
0 ignored issues
show
It seems like canSetProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
48 80
            parent::__set($name, $value);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (__set() instead of set()). Are you sure this is correct? If so, you might want to change this to $this->__set().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
49 80
        } else {
50 42
            $this->setItem($name, $value, $where);
51
        }
52 80
    }
53
54
    /**
55
     * Adds an item. Does not touch if already exists.
56
     * @param int|string   $name  item name
57
     * @param array        $value item value
58
     * @param string|array $where where to put, see [[setItem()]]
59
     * @return $this for chaining
60
     * @see setItem()
61
     */
62 20
    public function add($name, $value = null, $where = '')
63
    {
64 20
        if (!$this->has($name)) {
65 15
            $this->set($name, $value, $where);
66 15
        }
67
68 20
        return $this;
69
    }
70
71
    /**
72
     * Check collection has the item.
73
     * @param string $name item name
74
     * @return bool whether item exist
75
     */
76 49
    public function has($name)
77
    {
78 49
        return ($name && $this->hasProperty($name)) || $this->hasItem($name);
0 ignored issues
show
It seems like hasProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
79
    }
80
81
    /**
82
     * Delete an item.
83
     * @param $name
84
     */
85 12
    public function delete($name)
86
    {
87 12
        $this->__unset($name);
88 12
    }
89
90
    /**
91
     * This method is overridden to support accessing items like properties.
92
     * @param string $name item or property name
93
     * @return mixed item of found or the named property value
94
     */
95 28
    public function __get($name)
96
    {
97 28
        if ($name && $this->canGetProperty($name)) {
0 ignored issues
show
It seems like canGetProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
98 1
            return parent::__get($name);
99
        } else {
100 28
            return $this->getItem($name);
101
        }
102
    }
103
104
    /**
105
     * This method is overridden to support accessing items like properties.
106
     * @param string $name  item or property name
107
     * @param string $value value to be set
108
     * @return mixed item of found or the named property value
109
     */
110 80
    public function __set($name, $value)
111
    {
112 80
        $this->set($name, $value);
113 80
    }
114
115
    /**
116
     * Checks if a property value is null.
117
     * This method overrides the parent implementation by checking if the named item is loaded.
118
     * @param string $name the property name or the event name
119
     * @return bool whether the property value is null
120
     */
121 5
    public function __isset($name)
122
    {
123 5
        return ($name && parent::__isset($name)) || $this->issetItem($name);
124
    }
125
126
    /**
127
     * Checks if a property value is null.
128
     * This method overrides the parent implementation by checking if the named item is loaded.
129
     * @param string $name the property name or the event name
130
     * @return bool whether the property value is null
131
     */
132 12
    public function __unset($name)
133
    {
134 12
        if ($name && $this->canSetProperty($name)) {
0 ignored issues
show
It seems like canSetProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
135
            parent::__unset($name);
136
        } else {
137 12
            $this->unsetItem($name);
138
        }
139 12
    }
140
}
141