Issues (3099)

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.

AbstractDoctrineORMAdminListConfigurator.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
3
namespace Kunstmaan\AdminListBundle\AdminList\Configurator;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Query;
7
use Doctrine\ORM\QueryBuilder;
8
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
9
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition;
10
use Kunstmaan\AdminListBundle\AdminList\Filter;
11
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\AbstractORMFilterType;
12
use Kunstmaan\AdminListBundle\AdminList\SortableInterface;
13
use Pagerfanta\Adapter\DoctrineORMAdapter;
14
use Pagerfanta\Pagerfanta;
15
use Traversable;
16
17
/**
18
 * An abstract admin list configurator that can be used with the orm query builder
19
 */
20
abstract class AbstractDoctrineORMAdminListConfigurator extends AbstractAdminListConfigurator
21
{
22
    /**
23
     * @var EntityManagerInterface
24
     */
25
    protected $em;
26
27
    /**
28
     * @var Query
29
     */
30
    private $query;
31
32
    /**
33
     * @var Pagerfanta
34
     */
35
    private $pagerfanta;
36
37
    /**
38
     * @var PermissionDefinition
39
     */
40
    private $permissionDef;
41
42
    /**
43
     * @var AclHelper
44
     */
45
    protected $aclHelper;
46
47
    /**
48
     * AbstractDoctrineORMAdminListConfigurator constructor.
49
     *
50
     * @param EntityManagerInterface $em
51
     * @param AclHelper|null         $aclHelper
52
     */
53 31
    public function __construct(EntityManagerInterface $em, AclHelper $aclHelper = null)
54
    {
55 31
        $this->em = $em;
56 31
        $this->aclHelper = $aclHelper;
57 31
    }
58
59
    /**
60
     * Return the url to edit the given $item
61
     *
62
     * @param object $item
63
     *
64
     * @return array
65
     */
66 1 View Code Duplication
    public function getEditUrlFor($item)
67
    {
68 1
        $params = array('id' => $item->getId());
69 1
        $params = array_merge($params, $this->getExtraParameters());
70
71
        return array(
72 1
            'path' => $this->getPathByConvention($this::SUFFIX_EDIT),
73 1
            'params' => $params,
74
        );
75
    }
76
77
    /**
78
     * Get the delete url for the given $item
79
     *
80
     * @param object $item
81
     *
82
     * @return array
83
     */
84 1 View Code Duplication
    public function getDeleteUrlFor($item)
85
    {
86 1
        $params = array('id' => $item->getId());
87 1
        $params = array_merge($params, $this->getExtraParameters());
88
89
        return array(
90 1
            'path' => $this->getPathByConvention($this::SUFFIX_DELETE),
91 1
            'params' => $params,
92
        );
93
    }
94
95
    /**
96
     * @return Pagerfanta
97
     */
98 1 View Code Duplication
    public function getPagerfanta()
99
    {
100 1
        if (\is_null($this->pagerfanta)) {
101 1
            $adapter = new DoctrineORMAdapter($this->getQuery());
102 1
            $this->pagerfanta = new Pagerfanta($adapter);
103 1
            $this->pagerfanta->setNormalizeOutOfRangePages(true);
104 1
            $this->pagerfanta->setMaxPerPage($this->getLimit());
105 1
            $this->pagerfanta->setCurrentPage($this->getPage());
106
        }
107
108 1
        return $this->pagerfanta;
109
    }
110
111
    /**
112
     * @param QueryBuilder $queryBuilder
113
     */
114 8
    public function adaptQueryBuilder(QueryBuilder $queryBuilder)
115
    {
116 8
        $queryBuilder->where('1=1');
117 8
    }
118
119
    /**
120
     * @return int
0 ignored issues
show
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
121
     */
122
    public function getCount()
123
    {
124
        return $this->getPagerfanta()->getNbResults();
125
    }
126
127
    /**
128
     * @return array|Traversable
0 ignored issues
show
Should the return type not be \Pagerfanta\iterable|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
129
     */
130
    public function getItems()
131
    {
132
        return $this->getPagerfanta()->getCurrentPageResults();
133
    }
134
135
    /**
136
     * Return an iterator for all items that matches the current filtering
137
     *
138
     * @return \Iterator
139
     */
140 1
    public function getIterator()
141
    {
142 1
        return $this->getQuery()->iterate();
143
    }
144
145
    /**
146
     * @return Query|null
147
     */
148 5
    public function getQuery()
149
    {
150 5
        if (\is_null($this->query)) {
151 5
            $queryBuilder = $this->getQueryBuilder();
152 5
            $this->adaptQueryBuilder($queryBuilder);
153
154
            // Apply filters
155 5
            $filters = $this->getFilterBuilder()->getCurrentFilters();
156
            /* @var Filter $filter */
157 5
            foreach ($filters as $filter) {
158
                /* @var AbstractORMFilterType $type */
159 1
                $type = $filter->getType();
160 1
                $type->setQueryBuilder($queryBuilder);
161 1
                $filter->apply();
162
            }
163
164
            // Apply sorting
165 5
            if (!empty($this->orderBy)) {
166 1
                $orderBy = $this->orderBy;
167 1
                if ($this->getEntityManager()->getClassMetadata($this->getRepositoryName())->hasAssociation($this->orderBy)) {
168
                    $queryBuilder->leftJoin('b.' . $orderBy, 'A' . $orderBy);
169
                    $orderBy = 'A' . $orderBy . '.id';
170 1
                } elseif (!strpos($orderBy, '.')) {
171 1
                    $orderBy = 'b.' . $orderBy;
172
                }
173 1
                $queryBuilder->orderBy($orderBy, ($this->orderDirection == 'DESC' ? 'DESC' : 'ASC'));
174
            }
175
176
            // Apply other changes
177 5
            $this->finishQueryBuilder($queryBuilder);
178
179
            // Apply ACL restrictions (if applicable)
180 5
            if (!\is_null($this->permissionDef) && !\is_null($this->aclHelper)) {
181
                $this->query = $this->aclHelper->apply($queryBuilder, $this->permissionDef);
182
            } else {
183 5
                $this->query = $queryBuilder->getQuery();
184
            }
185
        }
186
187 5
        return $this->query;
188
    }
189
190
    /**
191
     * @param QueryBuilder $queryBuilder
192
     */
193 5
    protected function finishQueryBuilder(QueryBuilder $queryBuilder)
194
    {
195 5
        if ($this instanceof SortableInterface) {
196
            $queryBuilder->addOrderBy('b.' . $this->getSortableField());
197
        }
198 5
    }
199
200
    /**
201
     * @return QueryBuilder
202
     */
203 5
    protected function getQueryBuilder()
204
    {
205 5
        $queryBuilder = $this->em
206 5
            ->getRepository($this->getRepositoryName())
207 5
            ->createQueryBuilder('b');
208
209 5
        return $queryBuilder;
210
    }
211
212
    /**
213
     * Get current permission definition.
214
     *
215
     * @return PermissionDefinition|null
216
     */
217 1
    public function getPermissionDefinition()
218
    {
219 1
        return $this->permissionDef;
220
    }
221
222
    /**
223
     * Set permission definition.
224
     *
225
     * @param PermissionDefinition $permissionDef
226
     *
227
     * @return AbstractDoctrineORMAdminListConfigurator
228
     */
229 13
    public function setPermissionDefinition(PermissionDefinition $permissionDef)
230
    {
231 13
        $this->permissionDef = $permissionDef;
232
233 13
        return $this;
234
    }
235
236
    /**
237
     * @param EntityManagerInterface $em
238
     *
239
     * @return AbstractDoctrineORMAdminListConfigurator
240
     */
241 1
    public function setEntityManager(EntityManagerInterface $em)
242
    {
243 1
        $this->em = $em;
244
245 1
        return $this;
246
    }
247
248
    /**
249
     * @return EntityManagerInterface
250
     */
251 2
    public function getEntityManager()
252
    {
253 2
        return $this->em;
254
    }
255
}
256