Function callback
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function callback()
{
$src = $this->inputElement->getAttribute('data-href');
preg_match('/https:\/\/www.facebook\.com\/\w*\/(\w*)\/\d*/', $src, $embedType);
switch ($embedType) {
- 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 callback
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function callback()
{
$src = $this->inputElement->getAttribute('data-href');
preg_match('/https:\/\/www.facebook\.com\/\w*\/(\w*)\/\d*/', $src, $embedType);
switch ($embedType) {
Avoid too many return
statements within this method. Open
return null;
The method callback uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
}else{
$this->outputElement->removeAttribute('height');
}
- 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
Define a constant instead of duplicating this literal "height" 6 times. Open
case 'height':
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "data-href" 4 times. Open
$this->attributes = array('data-href', 'data-embed-as');
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
The closing brace for the class must go on the next line after the body Open
}
- Exclude checks
Blank line found at end of control structure Open
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
}
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
}
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
The variable $OEmbed is not named in camelCase. Open
public function callback()
{
$src = $this->inputElement->getAttribute('data-href');
preg_match('/https:\/\/www.facebook\.com\/\w*\/(\w*)\/\d*/', $src, $embedType);
switch ($embedType) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $OEmbed is not named in camelCase. Open
public function callback()
{
$src = $this->inputElement->getAttribute('data-href');
preg_match('/https:\/\/www.facebook\.com\/\w*\/(\w*)\/\d*/', $src, $embedType);
switch ($embedType) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $OEmbed is not named in camelCase. Open
public function callback()
{
$src = $this->inputElement->getAttribute('data-href');
preg_match('/https:\/\/www.facebook\.com\/\w*\/(\w*)\/\d*/', $src, $embedType);
switch ($embedType) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $OEmbed is not named in camelCase. Open
public function callback()
{
$src = $this->inputElement->getAttribute('data-href');
preg_match('/https:\/\/www.facebook\.com\/\w*\/(\w*)\/\d*/', $src, $embedType);
switch ($embedType) {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}