Issues (51)

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.

BestIt/CodeSniffer/Helper/DocTagHelper.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
declare(strict_types=1);
4
5
namespace BestIt\CodeSniffer\Helper;
6
7
use PHP_CodeSniffer\Files\File;
8
use function array_key_exists;
9
use function in_array;
10
use const T_DOC_COMMENT_CLOSE_TAG;
11
use const T_DOC_COMMENT_STRING;
12
use const T_DOC_COMMENT_TAG;
13
14
/**
15
 * Class DocTagHelper
16
 *
17
 * @author Nick Lubisch <[email protected]>
18
 * @package BestIt\CodeSniffer\Helper
19
 */
20
class DocTagHelper
21
{
22
    /**
23
     * The stating token of the comment.
24
     *
25
     * @var array
26
     */
27
    private array $token;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
28
29
    /**
30
     * The PHP CS file
31
     *
32
     * @var File
33
     */
34
    private File $file;
35
36
    /**
37
     * The token stack from php cs file.
38
     *
39
     * @var array
40
     */
41
    private array $tokens;
42
43
    /**
44
     * DocTagHelper constructor.
45
     *
46
     * @param File $file The php cs file
47
     * @param int $stackPos Position to the token which is to be listened
48
     * @param array $tokens Another token array if we want to overwrite them.
49
     */
50
    public function __construct(File $file, int $stackPos, array $tokens = [])
51
    {
52
        $this->file = $file;
53
        $this->tokens = $tokens ?: $file->getTokens();
54
        $this->token = $this->tokens[$stackPos];
55
    }
56
57
    /**
58
     * Returns the comment start token.
59
     *
60
     * @return array the token.
61
     */
62
    private function getCommentStartToken(): array
63
    {
64
        return $this->token;
65
    }
66
67
    /**
68 121
     * Loads the tag content for the given tag position.
69
     *
70 121
     * @param int $tagPosition The position of the tag.
71 121
     * @param int $iteratedPosition
72 121
     *
73 121
     * @return array The content tokens of the tag.
74 121
     */
75
    private function loadTagContentTokens(int $tagPosition, int &$iteratedPosition): array
76
    {
77
        $contents = [];
78
        $myColumn = $this->tokens[$tagPosition]['column'];
79
        $closingPos = $this->file->findNext([T_DOC_COMMENT_CLOSE_TAG], $position = $tagPosition + 1);
80
81
        while ($position < $closingPos) {
82
            $contentToken = $this->tokens[$position++];
83
84 113
            if (($contentToken['code'] === T_DOC_COMMENT_TAG) && ($contentToken['column'] <= $myColumn)) {
85
                break;
86 113
            }
87 113
88
            if (in_array($contentToken['code'], [T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG])) {
89 113
                $contents[$position] = $contentToken;
90 113
            }
91
92 113
            $iteratedPosition = $position;
93 113
        }
94 113
95
        return $contents;
96 113
    }
97 113
98
    /**
99 16
     * Returns array of all comment tag tokens.
100
     *
101
     * @return array List of all comment tag tokens indexed by token position
102 100
     */
103 100
    public function getTagTokens(): array
104
    {
105
        $iteratedPos = 0;
106
        $tagPositions = $this->getCommentStartToken()['comment_tags'];
107
        $tagTokens = [];
108
109
        /** @var int $tagPos */
110 100
        foreach ($tagPositions as $tagPos) {
111
            if ($tagPos >= $iteratedPos) {
112 100
                $tagTokens[$tagPos] = $this->tokens[$tagPos] + [
113
                    'contents' => $this->loadTagContentTokens($tagPos, $iteratedPos)
114 100
                ];
115 100
            }
116
        }
117 100
118 100
        return $tagTokens;
119 62
    }
120
121
    /**
122 100
     * Returns the individual count of every tag.
123 100
     *
124
     * @param array $tagTokens Array of tag tokens.
125
     *
126 100
     * @return array List of comment tags with there count of the current comment
127 100
     */
128
    public function getTagCounts(array $tagTokens): array
129
    {
130
        $tagCounts = [];
131
132
        foreach ($tagTokens as $tagToken) {
133
            $tagName = $tagToken['content'];
134
135
            if (!array_key_exists($tagName, $tagCounts)) {
136
                $tagCounts[$tagName] = 0;
137
            }
138 62
139
            ++$tagCounts[$tagName];
140 62
        }
141 62
142
        return $tagCounts;
143 62
    }
144
}
145