Issues (104)

Security Analysis    not enabled

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/Models/Collections/ModelCollection.php (1 issue)

Labels
Severity

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
namespace As3\Modlr\Models\Collections;
4
5
use As3\Modlr\Metadata\EntityMetadata;
6
use As3\Modlr\Models\AbstractModel;
7
use As3\Modlr\Models\Model;
8
use As3\Modlr\Store\Store;
9
10
/**
11
 * Model collection that contains record representations from a persistence (database) layer.
12
 *
13
 * @author Jacob Bare <[email protected]>
14
 */
15
abstract class ModelCollection extends AbstractCollection
16
{
17
    /**
18
     * @var EntityMetadata
19
     */
20
    protected $metadata;
21
22
    /**
23
     * Constructor.
24
     *
25
     * @param   EntityMetadata  $metadata
26
     * @param   Store           $store
27
     * @param   AbstractModel[] $models
28
     * @param   int             $totalCount
29
     */
30
    public function __construct(EntityMetadata $metadata, Store $store, array $models = [], $totalCount)
31
    {
32
        $this->metadata = $metadata;
33
        parent::__construct($store, $models, $totalCount);
34
    }
35
36
    /**
37
     * Returns all models in this collection without triggering auto-loading.
38
     *
39
     * @return  AbstractModel[]
40
     */
41
    public function allWithoutLoad()
42
    {
43
        return $this->models;
44
    }
45
46
    /**
47
     * Gets the identifiers for this collection.
48
     *
49
     * @param   bool    $onlyUnloaded   Whether to only include unloaded models in the results.
50
     * @return  array
51
     */
52
    abstract public function getIdentifiers($onlyUnloaded = true);
53
54
    /**
55
     * Gets the metadata for the model collection.
56
     *
57
     * @return  EntityMetadata
58
     */
59
    public function getMetadata()
60
    {
61
        return $this->metadata;
62
    }
63
64
    /**
65
     * Gets the query field for this collection.
66
     *
67
     * @return  string
68
     */
69
    abstract public function getQueryField();
70
71
    /**
72
     * {@inheritdoc}
73
     *
74
     * Overloaded to ensure models are loaded from the store.
75
     *
76
     */
77
    public function getSingleResult()
78
    {
79
        $this->loadFromStore();
80
        return parent::getSingleResult();
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getType()
87
    {
88
        return $this->getMetadata()->type;
89
    }
90
91
    /**
92
     * {@inheritDoc}
93
     */
94
    public function rewind()
95
    {
96
        $this->loadFromStore();
97
        parent::rewind();
98
    }
99
100
    /**
101
     * Loads this collection from the store.
102
     */
103
    protected function loadFromStore()
104
    {
105
        if (false === $this->isLoaded()) {
106
            // Loads collection from the database on iteration.
107
            $models = $this->store->loadCollection($this);
108
            $this->setModels($models);
109
            $this->loaded = true;
110
        }
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    protected function validateAdd(AbstractModel $model)
117
    {
118
        $this->validateModelClass($model);
119
        $this->store->validateRelationshipSet($this->getMetadata(), $model->getType());
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class As3\Modlr\Models\AbstractModel as the method getType() does only exist in the following sub-classes of As3\Modlr\Models\AbstractModel: As3\Modlr\Models\Model. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
120
    }
121
122
    /**
123
     * Validates that the model class instance is supported.
124
     *
125
     * @param   AbstractModel   $model
126
     * @throws  \InvalidArgumentException
127
     */
128
    protected function validateModelClass(AbstractModel $model)
129
    {
130
        if (!$model instanceof Model) {
131
            throw new \InvalidArgumentException('The model must be an instanceof of Model');
132
        }
133
    }
134
}
135