Issues (1)

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/RecursivePagination.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
3
namespace Xparse\RecursivePagination;
4
5
6
use Xparse\ElementFinder\ElementFinderInterface;
7
use Xparse\Parser\Parser;
8
use Xparse\Parser\ParserInterface;
9
10
/**
11
 *
12
 */
13
class RecursivePagination
14
{
15
16
    /**
17
     * @var array
18
     */
19
    protected $queue = [];
20
21
    /**
22
     * @var Parser
23
     */
24
    protected $parser;
25
26
    /**
27
     * @var array
28
     */
29
    protected $elementSelector = [];
30
31
32
    /**
33
     * @param string|array $expression
34
     * @throws \Exception
35
     */
36 27
    public function __construct(ParserInterface $parser, $expression)
37
    {
38 27
        $this->parser = $parser;
0 ignored issues
show
Documentation Bug introduced by
$parser is of type object<Xparse\Parser\ParserInterface>, but the property $parser was declared to be of type object<Xparse\Parser\Parser>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
39 27
        $this->setExpression($expression);
40 18
    }
41
42
43
    /**
44
     * @param array|string $links
45
     * @return $this
46
     * @throws \InvalidArgumentException
47
     */
48 18
    public function addToQueue($links, bool $state = false): self
49
    {
50 18
        if (!is_string($links) and !is_array($links)) {
51 3
            throw new \InvalidArgumentException('Links should be an array or a string');
52
        }
53 15
        foreach ((array)$links as $url) {
54 15
            if (!is_string($url)) {
55 3
                throw new \InvalidArgumentException('url should be a string');
56
            }
57 15
            $this->queue[$url] = $state;
58
        }
59
60 12
        return $this;
61
    }
62
63
64
    /**
65
     * @throws \Exception
66
     * @throws \InvalidArgumentException
67
     */
68 12
    public function getNextPage(): ?ElementFinderInterface
69
    {
70
71 12
        $link = array_search(false, $this->queue, true);
72 12
        if ($link === false) {
73 12
            return null;
74
        }
75 12
        $this->queue[$link] = true;
76 12
        $page = $this->parser->get($link);
77 12
        if ($page === null) {
78
            return null;
79
        }
80 12
        foreach ($this->elementSelector as $expression => $state) {
81 12
            $queueLinks = $page->value($expression)->all();
82 12
            $countQueueLinks = count($queueLinks);
83 12
            if ($countQueueLinks > 0) {
84 12
                $queueLinks = array_combine($queueLinks, array_fill(0, $countQueueLinks, false));
85
                /** @noinspection SlowArrayOperationsInLoopInspection */
86 12
                $this->queue = array_merge($queueLinks, $this->queue);
87
            }
88
        }
89 12
        return $page;
90
    }
91
92
93
    /**
94
     * @param string|array $expression
95
     * @throws \InvalidArgumentException
96
     */
97 27
    private function setExpression($expression): void
98
    {
99
100 27
        if (!is_string($expression) and !is_array($expression)) {
101 3
            throw new \InvalidArgumentException('Invalid expression, should be array or string');
102
        }
103
104 24
        $expression = array_filter((array)$expression);
105
106 24
        if (count($expression) === 0) {
107 3
            throw new \InvalidArgumentException('Expression might be not empty');
108
        }
109 21
        foreach ($expression as $path) {
110 21
            if (!is_string($path)) {
111 3
                throw new \InvalidArgumentException('Invalid expression, should be a string');
112
            }
113 21
            $this->elementSelector[$path] = true;
114
        }
115 18
    }
116
117
}