Issues (10)

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/JsonApiPaginationDecorator.php (1 issue)

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\Pagination;
3
4
use Psr\Http\Message\UriInterface;
5
6
class JsonApiPaginationDecorator extends PaginationDecoratorAbstract implements  \JsonSerializable
7
{
8
9
	/**
10
	 * @var UriInterface
11
	 */
12
	public $uri;
13
14
	/**
15
	 * @var array
16
	 */
17
	public $query_params = array();
18
19
	/**
20
	 * @var array
21
	 */
22
	public $json_result = array();
23
24
	/**
25
	 * @var array
26
	 */
27
	public $filter_result = false;
28
29
30
	/**
31
	 * @param PaginationInterface $pagination    The pagination to decorate
32
	 * @param UriInterface        $uri           PSR-7 URI instance
33
	 * @param array               $query_params  Optional: default query parameters for URIs
34
	 * @param bool                $filter_result Optional: Filter out null member values in jsonSerialize's result. 
35
	 *                                           Default: FALSE
36
	 */
37 48
	public function __construct( PaginationInterface $pagination, UriInterface $uri, array $query_params = array(), bool $filter_result = false )
38
	{
39 48
		$this->uri = $uri;
40 48
		$this->query_params = $query_params;
41 48
		$this->filter_result = $filter_result;
0 ignored issues
show
Documentation Bug introduced by
It seems like $filter_result of type boolean is incompatible with the declared type array of property $filter_result.

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...
42
43
   
44 48
		$this->json_result['first'] = null;
45 48
		$this->json_result['prev']  = null;
46 48
		$this->json_result['next']  = null;
47 48
		$this->json_result['last']  = null;		
48
49 48
		parent::__construct($pagination);
50 48
	}
51
52
53
	/**
54
	 * JsonSerializable alias for getLinks()
55
	 * @return array
56
	 */
57 24
	public function jsonSerialize()
58
	{
59 24
		return $this->getLinks();
60
	}
61
62
63
	/**
64
	 * Returns an array with `first`, `last`, `next`, and `previous` elements
65
	 * according to the JsonAPI pagination specs.
66
	 * 
67
	 * @return array
68
	 * @see    https://jsonapi.org/format/#fetching-pagination
69
	 */
70 48
	public function getLinks() : array
71
	{
72 48
		if (!$this->pagination->isActive()):
73 24
			return $this->json_result;
74
		endif;
75
76 24
		$page_size = $this->isDefaultPageSize() ? null : $this->pagination->getPageSize( );
77
78 24
        $this->buildField('first', $this->pagination->getFirst(),    $page_size);
79 24
        $this->buildField('prev',  $this->pagination->getPrevious(), $page_size);
80 24
        $this->buildField('next',  $this->pagination->getNext(),     $page_size);
81 24
        $this->buildField('last',  $this->pagination->getLast(),     $page_size);
82
83 24
        return $this->filter_result 
84 12
        ? array_filter($this->json_result)
85 24
        : $this->json_result;		
86
	}
87
88
	/**
89
	 * Returns an array with non-standard meta information about the pagination
90
	 *
91
	 * - numberOfPages
92
	 * - currentPage
93
	 * - pageSize
94
	 * 
95
	 * @return array
96
	 */
97 48
	public function getMeta() : array
98
	{
99 48
		if (!$this->pagination->isActive()):
100 24
			return array();
101
		endif;
102
103
		return array(
104 24
        	'numberOfPages' => $this->pagination->getPagesCount(),
105 24
        	'currentPage'   => $this->pagination->getCurrent(),
106 24
        	'pageSize'      => $this->pagination->getPageSize()
107
		);
108
	}
109
110
111
112
113
	/**
114
	 * @param  string   $field     Link element field name
115
	 * @param  int      $page      Page number
116
	 * @param  int|null $page_size Page size
117
	 * @return void
118
	 */
119 18
	protected function buildField($field, $page, $page_size) {
120
121
		$notnullfilter = function($i) { return !is_null($i); };
122
123 24
		if (is_null($page)):
124 24
			$this->json_result[$field] = null;
125
		else:
126
			$pagination_query_params = array(
127 24
				'page' => array_filter(['size' => $page_size, 'number' => $page], $notnullfilter) 
128
			);
129 24
			$this->json_result[$field] = $this->buildUriString( $pagination_query_params );
130
		endif;
131 24
	}
132
133
134
    /**
135
     * @param  array $custom_params
136
     * @return string
137
     */
138 24
    protected function buildUriString( array $custom_params) : string
139
    {
140 24
    	$params = array_merge($this->query_params, $custom_params);
141 24
    	$query = http_build_query( $params );
142 24
        return (string) $this->uri->withQuery( $query );
143
    }
144
145
}