cleanParams accesses the super-global variable $_GET. Open
public function cleanParams()
{
$_GET = array();
$_POST = array();
$_FILES = array();
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
loadRequestFormData accesses the super-global variable $_FILES. Open
public function loadRequestFormData($paramName)
{
if (array_key_exists($paramName, $_POST)) {
$this->contextDataExists = true;
$this->contextDataValue = $_POST[$paramName];
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
loadRequestFormData accesses the super-global variable $_FILES. Open
public function loadRequestFormData($paramName)
{
if (array_key_exists($paramName, $_POST)) {
$this->contextDataExists = true;
$this->contextDataValue = $_POST[$paramName];
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
getRequestFormDataKey accesses the super-global variable $_POST. Open
public function getRequestFormDataKey()
{
$post = array_keys($_POST);
$file = array_keys($_FILES);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
cleanParams accesses the super-global variable $_COOKIE. Open
public function cleanParams()
{
$_GET = array();
$_POST = array();
$_FILES = array();
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
loadRequestFormData accesses the super-global variable $_POST. Open
public function loadRequestFormData($paramName)
{
if (array_key_exists($paramName, $_POST)) {
$this->contextDataExists = true;
$this->contextDataValue = $_POST[$paramName];
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
cleanParams accesses the super-global variable $_POST. Open
public function cleanParams()
{
$_GET = array();
$_POST = array();
$_FILES = array();
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
cleanParams accesses the super-global variable $_FILES. Open
public function cleanParams()
{
$_GET = array();
$_POST = array();
$_FILES = array();
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
getRequestFormDataKey accesses the super-global variable $_FILES. Open
public function getRequestFormDataKey()
{
$post = array_keys($_POST);
$file = array_keys($_FILES);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
loadRequestFormData accesses the super-global variable $_POST. Open
public function loadRequestFormData($paramName)
{
if (array_key_exists($paramName, $_POST)) {
$this->contextDataExists = true;
$this->contextDataValue = $_POST[$paramName];
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
cleanParams accesses the super-global variable $_SERVER. Open
public function cleanParams()
{
$_GET = array();
$_POST = array();
$_FILES = array();
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
cleanParams accesses the super-global variable $_SERVER. Open
public function cleanParams()
{
$_GET = array();
$_POST = array();
$_FILES = array();
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
File Context.php
has 642 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*
* Copyright 2016 Nicolas JUHEL <swaggervalidator@nabbar.com>.
*
Context
has 42 functions (exceeds 20 allowed). Consider refactoring. Open
class Context extends ContextBase implements \SwaggerValidator\Interfaces\ContextLog, \SwaggerValidator\Interfaces\ContextDataLoader, \SwaggerValidator\Interfaces\ContextDataParser
{
/*
* Mode Constants
*/
The class Context has an overall complexity of 152 which is very high. The configured complexity threshold is 50. Open
class Context extends ContextBase implements \SwaggerValidator\Interfaces\ContextLog, \SwaggerValidator\Interfaces\ContextDataLoader, \SwaggerValidator\Interfaces\ContextDataParser
{
/*
* Mode Constants
*/
- Exclude checks
The class Context has 29 non-getter- and setter-methods. Consider refactoring Context to keep number of methods under 25. Open
class Context extends ContextBase implements \SwaggerValidator\Interfaces\ContextLog, \SwaggerValidator\Interfaces\ContextDataLoader, \SwaggerValidator\Interfaces\ContextDataParser
{
/*
* Mode Constants
*/
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
The class Context has 25 public methods. Consider refactoring Context to keep number of public methods under 10. Open
class Context extends ContextBase implements \SwaggerValidator\Interfaces\ContextLog, \SwaggerValidator\Interfaces\ContextDataLoader, \SwaggerValidator\Interfaces\ContextDataParser
{
/*
* Mode Constants
*/
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
Function buildBodyXml
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public function buildBodyXml($contents)
{
$this->contextDataType = self::CONTENT_TYPE_XML;
$this->contextDataExists = (bool) (strlen($contents) > 0);
$this->contextDataValue = simplexml_load_string($contents);
- 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
Method setValidationError
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setValidationError($valitionType, $messageException = null, $method = null, $line = null)
{
$this->logValidationError($valitionType, $messageException, $method, $line);
if ($this->__get('IsCombined')) {
Function setValidationError
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function setValidationError($valitionType, $messageException = null, $method = null, $line = null)
{
$this->logValidationError($valitionType, $messageException, $method, $line);
if ($this->__get('IsCombined')) {
- 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 loadRequestPath
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function loadRequestPath($paramName)
{
// parse from the end to the top
$path = array_reverse(explode('/', $this->contextRequestPath));
- 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
Consider simplifying this complex logical expression. Open
if ($paramName === \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY && $this->getType() === self::TYPE_REQUEST) {
return $this->loadRequestBody();
}
elseif ($paramName === \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY && $this->getType() === self::TYPE_RESPONSE) {
return $this->loadResponseBody();
Method buildBodyXml
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function buildBodyXml($contents)
{
$this->contextDataType = self::CONTENT_TYPE_XML;
$this->contextDataExists = (bool) (strlen($contents) > 0);
$this->contextDataValue = simplexml_load_string($contents);
Method dataLoad
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function dataLoad()
{
$paramName = $this->__get('DataPath');
$paramName = array_pop($paramName);
Function dataLoad
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function dataLoad()
{
$paramName = $this->__get('DataPath');
$paramName = array_pop($paramName);
- 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 parseQueryAsMulti
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
protected function parseQueryAsMulti($queryString)
{
$params = explode('&', $queryString);
$result = array();
- 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
Method loadBodyByContent
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function loadBodyByContent($headers, $rawBody)
{
$contentType = null;
$contentLength = null;
Method loadRequestPath
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function loadRequestPath($paramName)
{
// parse from the end to the top
$path = array_reverse(explode('/', $this->contextRequestPath));
Method logReference
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function logReference($type, $ref, $oldRef = null, $method = null, $line = null)
Function logReference
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function logReference($type, $ref, $oldRef = null, $method = null, $line = null)
{
if (self::getConfig('log', 'reference') || self::getConfig('log', $type . 'Ref')) {
switch ($type) {
case 'replace':
- 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 setSandBox
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function setSandBox()
{
if ($this->getType() !== self::TYPE_REQUEST) {
return $this;
}
- 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 loadBodyByContent
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function loadBodyByContent($headers, $rawBody)
{
$contentType = null;
$contentLength = null;
- 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 $this->loadRequestPath($paramName);
Avoid too many return
statements within this method. Open
return $this->loadRequestQuery($paramName);
Avoid too many return
statements within this method. Open
return $this->checkDataIsEmpty();
Avoid too many return
statements within this method. Open
return $this->loadRequestFormData($paramName);
Function checkDataIsEmpty
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function checkDataIsEmpty()
{
if ($this->isDataExists() === false) {
$this->contextDataEmpty = 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
The class Context has 1012 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Context extends ContextBase implements \SwaggerValidator\Interfaces\ContextLog, \SwaggerValidator\Interfaces\ContextDataLoader, \SwaggerValidator\Interfaces\ContextDataParser
{
/*
* Mode Constants
*/
- Exclude checks
The method setValidationError() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function setValidationError($valitionType, $messageException = null, $method = null, $line = null)
{
$this->logValidationError($valitionType, $messageException, $method, $line);
if ($this->__get('IsCombined')) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method dataLoad() has a Cyclomatic Complexity of 21. The configured cyclomatic complexity threshold is 10. Open
public function dataLoad()
{
$paramName = $this->__get('DataPath');
$paramName = array_pop($paramName);
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Missing class import via use statement (line '1028', column '26'). Open
$e = new \SwaggerValidator\Exception($messageException);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '935', column '18'). Open
$e = new \SwaggerValidator\Exception($message);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class '\SwaggerValidator\Common\Collection' in method 'buildBodyXml'. Open
$this->contextDataValue = \SwaggerValidator\Common\Collection::jsonEncode($this->getDataValue());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\SwaggerValidator\Common\Collection' in method 'setValidationError'. Open
$messageException = 'Swagger Validation Error : Route ! Value Find : ' . \SwaggerValidator\Common\Collection::jsonEncode($this->getDataValue());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method loadResponseBody uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->loadBodyByContent($this->getResponseHeader(), file_get_contents("php://output"));
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method loadRequestBody uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->loadBodyByContent($this->getRequestHeader(), file_get_contents("php://input"));
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method buildBodyXml uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->contextDecodeError[] = array('code' => json_last_error(), 'message' => null);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method buildBodyXml uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->contextDataValue = json_decode($this->getDataValue(), false);
if (json_last_error() !== JSON_ERROR_NONE) {
$this->contextDataEmpty = true;
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\SwaggerValidator\Common\Collection' in method 'setValidationError'. Open
$messageException = 'Swagger Validation Error : Method ! Value Find : ' . \SwaggerValidator\Common\Collection::jsonEncode($this->getDataValue());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method checkDataIsEmpty uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->contextDataEmpty = (bool) $this->checkIsEmpty($this->getDataValue());
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method getRequestDataKeys uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$data = file_get_contents("php://input");
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method buildBodyXml uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->contextDecodeError[] = array('code' => json_last_error(), 'message' => null);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method buildBodyXml uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->checkDataIsEmpty();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\SwaggerValidator\Common\Collection' in method 'setValidationError'. Open
$messageException = 'Swagger Validation Error : HostName ! Value Find : ' . \SwaggerValidator\Common\Collection::jsonEncode($this->getDataValue());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method buildBodyJson uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->checkDataIsEmpty();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\SwaggerValidator\Common\Collection' in method 'logMessage'. Open
$message = \SwaggerValidator\Common\Collection::jsonEncode($message);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method parseQueryAsMulti uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$result[$key] = $qrs[$key];
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\SwaggerValidator\Common\Collection' in method 'setValidationError'. Open
$messageException = 'Swagger Validation Error : BasePath ! Value Find : ' . \SwaggerValidator\Common\Collection::jsonEncode($this->getDataValue());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method __storeData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
parent::__storeData($key, $value);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method buildBodyJson uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->contextDecodeError = array(array('code' => json_last_error(), 'message' => null));
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method buildBodyXml uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else {
$this->contextDataValue = \SwaggerValidator\Common\Collection::jsonEncode($this->getDataValue());
if (json_last_error() !== JSON_ERROR_NONE) {
$this->contextDataEmpty = true;
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused local variables such as '$code'. Open
$this->contextDecodeError[] = array('code' => $error->$code, 'message' => $error->message);
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (json_last_error() !== JSON_ERROR_NONE) {
$this->contextDataEmpty = true;
$this->contextDataValue = null;
if (function_exists('json_last_error_msg')) {
$this->contextDecodeError[] = array('code' => json_last_error(), 'message' => json_last_error_msg());
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 99.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (json_last_error() !== JSON_ERROR_NONE) {
$this->contextDataEmpty = true;
$this->contextDataValue = null;
if (function_exists('json_last_error_msg')) {
$this->contextDecodeError[] = array('code' => json_last_error(), 'message' => json_last_error_msg());
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 99.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid variables with short names like $e. Configured minimum length is 3. Open
$e = new \SwaggerValidator\Exception($messageException);
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $e. Configured minimum length is 3. Open
$e = new \SwaggerValidator\Exception($message);
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The method __storeData is not named in camelCase. Open
protected function __storeData($key, $value = null)
{
if (property_exists($this, $key)) {
$this->$key = $value;
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}