CsrfGuard
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
class CsrfGuard
{
public const HEADER_TOKEN = 'HTTP_X_CSRF_TOKEN';
public const REQUEST_TOKEN_VALUE = 'CSRFToken';
public const TOKEN_LENGTH = 48;
Consider simplifying this complex logical expression. Open
if ($this->isGetSecured() && $method == "GET") {
return true;
} elseif ($this->isPostSecured() && $method == "POST") {
return true;
} elseif ($this->isPutSecured() && $method == "PUT") {
Function injectForms
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function injectForms(string $html): string
{
preg_match_all("/<form(.*?)>(.*?)<\\/form>/is", $html, $matches, PREG_SET_ORDER);
if (is_array($matches)) {
foreach ($matches as $match) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function run
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function run(): void
{
if (!$this->isExempt()) {
$providedToken = $this->getProvidedCsrfToken();
if (is_null($providedToken)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return false;
Function isExempt
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function isExempt(): bool
{
if (!$this->isHttpMethodFiltered($this->request->getMethod()->value)) {
return true;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function isHttpMethodFiltered
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function isHttpMethodFiltered(string $method): bool
{
if ($this->isGetSecured() && $method == "GET") {
return true;
} elseif ($this->isPostSecured() && $method == "POST") {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function initializeGuardedMethods
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function initializeGuardedMethods(): void
{
if (isset($this->configurations['guard_methods'])) {
foreach ($this->configurations['guard_methods'] as $method) {
if (!in_array($method, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"