Function fromCode
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public static function fromCode($code)
{
$embedClass = 'Ajde_Embed';
foreach (self::$_detect as $provider => $test) {
if (is_array($test)) {
- 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 method getProvider uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return false;
}
- 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 fromCode uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (substr_count($code, $test) > 0) {
$providerClass = 'Ajde_Embed_'.ucfirst($provider);
if (class_exists($providerClass)) {
$embedClass = $providerClass;
- 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 class Ajde_Embed is not named in CamelCase. Open
class Ajde_Embed extends Ajde_Object_Standard
{
protected $_code;
protected $_parser;
- 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 property $_allowedTags is not named in camelCase. Open
class Ajde_Embed extends Ajde_Object_Standard
{
protected $_code;
protected $_parser;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_code is not named in camelCase. Open
class Ajde_Embed extends Ajde_Object_Standard
{
protected $_code;
protected $_parser;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_parser is not named in camelCase. Open
class Ajde_Embed extends Ajde_Object_Standard
{
protected $_code;
protected $_parser;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_height is not named in camelCase. Open
class Ajde_Embed extends Ajde_Object_Standard
{
protected $_code;
protected $_parser;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_detect is not named in camelCase. Open
class Ajde_Embed extends Ajde_Object_Standard
{
protected $_code;
protected $_parser;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_width is not named in camelCase. Open
class Ajde_Embed extends Ajde_Object_Standard
{
protected $_code;
protected $_parser;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The method _setHeight is not named in camelCase. Open
protected function _setHeight()
{
$ptn = "/height=(\'|\")([0-9]+)(\'|\")/";
$rpltxt = "height='".$this->_height."'";
$this->_code = preg_replace($ptn, $rpltxt, $this->_code);
- 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() {
}
}
Source
The method _setWidth is not named in camelCase. Open
protected function _setWidth()
{
$ptn = "/width=(\'|\")([0-9]+)(\'|\")/";
$rpltxt = "width='".$this->_width."'";
$this->_code = preg_replace($ptn, $rpltxt, $this->_code);
- 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() {
}
}