lib/Ajde/Model/Validator/Text.php
Function _validate
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
protected function _validate()
{
if (!empty($this->_value)) {
if ($length = $this->getLength()) {
if (strlen($this->_value) > $length) {
- 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 assigning values to variables in if clauses and the like (line '8', column '17'). Open
Open
protected function _validate()
{
if (!empty($this->_value)) {
if ($length = $this->getLength()) {
if (strlen($this->_value) > $length) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The class Ajde_Model_Validator_Text is not named in CamelCase. Open
Open
class Ajde_Model_Validator_Text extends Ajde_Model_ValidatorAbstract
{
protected function _validate()
{
if (!empty($this->_value)) {
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The method _validate is not named in camelCase. Open
Open
protected function _validate()
{
if (!empty($this->_value)) {
if ($length = $this->getLength()) {
if (strlen($this->_value) > $length) {
- 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() {
}
}