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/Sniffs/Commenting/RequiredDocBlockSniff.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\Sniffs\Commenting;
6
7
use BestIt\CodeSniffer\CodeError;
8
use BestIt\CodeSniffer\CodeWarning;
9
use BestIt\CodeSniffer\Helper\PropertyHelper;
10
use BestIt\Sniffs\AbstractSniff;
11
use BestIt\Sniffs\DocPosProviderTrait;
12
use function array_keys;
13
use function lcfirst;
14
use function ucfirst;
15
use const T_CLASS;
16
use const T_CONST;
17
use const T_FUNCTION;
18
use const T_INTERFACE;
19
use const T_PRIVATE;
20
use const T_PROTECTED;
21
use const T_PUBLIC;
22
use const T_TRAIT;
23
use const T_VARIABLE;
24
25
/**
26
 * @author blange <[email protected]>
27
 * @package BestIt\Sniffs\Commenting
28
 */
29
class RequiredDocBlockSniff extends AbstractSniff
30
{
31
    use DocPosProviderTrait;
32
33
    /**
34
     * There MUST be a doc block before a Class, Constant, Interface, Function, Trait, Variable.
35
     *
36
     * It will get suffixed like MissingDocBlockClass.
37
     */
38
    public const CODE_MISSING_DOC_BLOCK_PREFIX = 'MissingDocBlock';
39
40
    /**
41
     * The doc block before a Class, Constant, Interface, Function, Trait, Variable must be multi-line.
42
     *
43
     * It will be suffixed with the name of the structure like NoMultiLineDocBlockClass.
44
     */
45
    public const CODE_NO_MULTI_LINE_DOC_BLOCK_PREFIX = 'NoMultiLineDocBlock';
46
47
    /**
48
     * The message for missing doc blocks.
49
     */
50
    private const MESSAGE_MISSING_DOC_BLOCK = 'Please provide a doc block for your %s.';
51
52
    /**
53
     * The message for missing doc blocks in variable declarations.
54
     */
55
    private const MESSAGE_MISSING_DOC_BLOCK_VAR = 'Please provide a doc block for your %s or define a property type.';
56
57
    /**
58
     * The error message for the inline block.
59
     */
60
    private const MESSAGE_NO_MULTI_LINE_DOC_BLOCK_PREFIX = 'Please provide a multi line doc block for your %s.';
61
62
    /**
63
     * Maps the registered tokens to a readable key.
64
     *
65
     * @var array
66
     */
67
    private array $registeredTokens = [
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...
68
        T_CLASS => 'Class',
69
        T_CONST => 'Constant',
70
        T_INTERFACE => 'Interface',
71
        T_FUNCTION => 'Function',
72
        T_PRIVATE => 'MethodOrProperty',
73
        T_PROTECTED => 'MethodOrProperty',
74
        T_PUBLIC => 'MethodOrProperty',
75
        T_TRAIT => 'Trait',
76
        T_VARIABLE => 'Variable',
77
    ];
78
79
    /**
80
     * Ignore normal variables for this sniff.
81
     *
82
     * @return bool
83
     */
84
    protected function areRequirementsMet(): bool
85
    {
86
        return ($this->token['code'] !== T_VARIABLE) || (new PropertyHelper($this->file))->isProperty($this->stackPos);
87
    }
88
89
    /**
90
     * Checks for a missing doc block and throws an error if the doc is missing.
91
     *
92
     * @throws CodeWarning
93
     *
94
     * @return void
95
     */
96
    private function checkAndRegisterMissingDocBlock(): void
97
    {
98
        if (!$this->getDocCommentPos()) {
99
            $tokenIdent = $this->getTokenName();
100
101
            throw (new CodeError(
102
                static::CODE_MISSING_DOC_BLOCK_PREFIX . ucfirst($tokenIdent),
103
                self::MESSAGE_MISSING_DOC_BLOCK,
104
                $this->stackPos
105
            ))->setPayload([lcfirst($tokenIdent)]);
106
        }
107
    }
108
109
    /**
110
     * Checks and registers a multi line error.
111
     *
112
     * @throws CodeWarning
113
     *
114
     * @return void
115
     */
116
    private function checkAndRegisterNoMultiLine(): void
117
    {
118
        $docCommentPos = $this->getDocCommentPos();
119
        $openingToken = $this->tokens[$docCommentPos];
120
        $closingToken = $this->tokens[$openingToken['comment_closer']];
121
122
        if ($openingToken['line'] === $closingToken['line']) {
123
            $tokenIdent = $this->getTokenName();
124
125
            $exception = (new CodeError(
126
                static::CODE_NO_MULTI_LINE_DOC_BLOCK_PREFIX . ucfirst($tokenIdent),
127
                self::MESSAGE_NO_MULTI_LINE_DOC_BLOCK_PREFIX,
128
                $docCommentPos
129
            ))->setPayload([lcfirst($tokenIdent)]);
130
131
            throw $exception;
132
        }
133
    }
134
135
    /**
136
     * Returns the name for the token.
137
     *
138
     * @return string
139
     */
140
    private function getTokenName(): string
141
    {
142
        return $this->registeredTokens[$this->token['code']];
143
    }
144
145
    /**
146
     * Processes the token.
147
     *
148
     * @return void
149
     */
150
    protected function processToken(): void
151
    {
152
        try {
153
            $this->checkAndRegisterMissingDocBlock();
154
            $this->checkAndRegisterNoMultiLine();
155
        } catch (CodeWarning $error) {
156
            $this->getExceptionHandler()->handleException($error);
157
        }
158
    }
159
160
    /**
161
     * Register for all tokens which require a php doc block for us.
162
     *
163
     * @return array
164
     */
165
    public function register(): array
166
    {
167
        return array_keys($this->registeredTokens);
168
    }
169
}
170