Issues (45)

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/Controller/EntityListingMethods.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
/**
4
 * This file is part of slick/mvc package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mvc\Controller;
11
12
use Psr\Http\Message\ServerRequestInterface;
13
use Slick\Filter\StaticFilter;
14
use Slick\Http\PhpEnvironment\Request;
15
use Slick\Mvc\Service\Entity\EntityListingService;
16
use Slick\Mvc\Service\Entity\QueryFilter\SearchFilter;
17
use Slick\Mvc\Utils\Pagination;
18
use Slick\Orm\Repository\EntityRepository;
19
20
/**
21
 * Entity Listing Methods
22
 *
23
 * @package Slick\Mvc\Controller
24
 * @author  Filipe Silva <[email protected]>
25
 */
26
trait EntityListingMethods
27
{
28
    
29
    /**
30
     * @var int
31
     */
32
    protected $rowsPerPage = 12;
33
34
    /**
35
     * @var Pagination
36
     */
37
    protected $pagination;
38
39
    /**
40
     * @var EntityListingService
41
     */
42
    protected $listingService;
43
44
    /**
45
     * @var string[]
46
     */
47
    protected $searchFields;
48
49
    /**
50
     * Handle the request to display a list of entities
51
     */
52 2
    public function index()
53
    {
54 2
        $this->getListingService()
55 2
            ->setOrder($this->getOrder())
56 2
            ->setPagination($this->getPagination())
57 2
            ->getFilters()->add($this->getSearchFilter());
58 2
        $this->set(
0 ignored issues
show
It seems like set() 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...
59
            [
60 2
                $this->getEntityNamePlural() => $this->getListingService()
61 2
                    ->getList(),
62 2
                'pagination' => $this->getListingService()->getPagination()
63 1
            ]
64 1
        );
65 2
    }
66
67
    /**
68
     * Get pagination for roes per page property
69
     *
70
     * @return Pagination
71
     */
72 4
    protected function getPagination()
73
    {
74 4
        if (null == $this->pagination) {
75 4
            $this->pagination = new Pagination(
76
                [
77 4
                    'rowsPerPage' => $this->rowsPerPage,
78 4
                    'request' => $this->getRequest()
79 2
                ]
80 2
            );
81 2
        }
82 4
        return $this->pagination;
83
    }
84
85
    /**
86
     * Get the entity listing service
87
     *
88
     * @return EntityListingService
89
     */
90 4
    protected function getListingService()
91
    {
92 4
        if (null == $this->listingService) {
93 2
            $this->listingService = new EntityListingService(
94 2
                $this->getEntityClassName()
0 ignored issues
show
It seems like getEntityClassName() 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...
95 1
            );
96 1
        }
97 4
        return $this->listingService;
98
    }
99
100
    /**
101
     * Get search filter 
102
     * 
103
     * @return SearchFilter
104
     */
105 4
    protected function getSearchFilter()
106
    {
107 4
        $pattern = $this->getRequest()->getQuery('pattern', null);
0 ignored issues
show
The method getQuery() does not exist on Psr\Http\Message\ServerRequestInterface. Did you maybe mean getQueryParams()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
108 4
        $pattern = StaticFilter::filter('text', $pattern);
109 4
        $this->set('pattern', $pattern);
0 ignored issues
show
It seems like set() 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...
110
        
111 4
        return new SearchFilter(['pattern' => $pattern]);
112
    }
113
114
    /**
115
     * Get the fields list to use on search filter
116
     * 
117
     * @return array|\string[]
118
     */
119 2
    protected function getSearchFields()
120
    {
121 2
        if (null == $this->searchFields) {
122 2
            $field = $this->getEntityDescriptor()->getDisplayFiled();
123 2
            $this->searchFields = [
124 2
                $this->getEntityDescriptor()
125 2
                    ->getTableName().'.'.$field->getField()
126 1
            ];
127 1
        }
128 2
        return $this->searchFields;
129
    }
130
131
    /**
132
     * Returns the query order by clause
133
     * 
134
     * @return string
135
     */
136 2
    protected function getOrder()
137
    {
138
        /** @var EntityRepository $repo */
139 2
        $repo = $this->getRepository();
0 ignored issues
show
It seems like getRepository() 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...
140 2
        $table = $repo->getEntityDescriptor()->getTableName();
141 2
        $pmk = $repo->getEntityDescriptor()->getPrimaryKey()->getField();
142 2
        return "{$table}.{$pmk} DESC";
143
    }
144
145
    /**
146
     * Gets updated HTTP request
147
     *
148
     * @return ServerRequestInterface|Request
149
     */
150
    abstract public function getRequest();
151
152
    /**
153
     * Get the current entity descriptor
154
     *
155
     * @return \Slick\Orm\Descriptor\EntityDescriptorInterface
156
     */
157
    abstract protected function getEntityDescriptor();
158
159
    /**
160
     * Get the plural name of the entity
161
     *
162
     * @return string
163
     */
164
    abstract protected function getEntityNamePlural();
165
}