src/Style/Formatter/HtmlOutputFormatter.php
Function formatHtml
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
private function formatHtml($matches)
{
$out = '<span style="';
foreach (explode(';', $matches[1]) as $code) {
if (isset(self::$availableForegroundColors[$code])) {
- 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 unused private methods such as 'formatHtml'. Open
Open
private function formatHtml($matches)
{
$out = '<span style="';
foreach (explode(';', $matches[1]) as $code) {
if (isset(self::$availableForegroundColors[$code])) {
- Read upRead up
- Exclude checks
UnusedPrivateMethod
Since: 0.2
Unused Private Method detects when a private method is declared but is unused.
Example
class Something
{
private function foo() {} // unused
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatemethod
When fetching an array index from a value of type array{40:'black',41:'red',42:'green',43:'yellow',44:'blue',45:'magenta',46:'cyan',47:'white'},
found an array index of type string,
but expected the index to be of type int
Open
Open
$out .= 'background-color:'.self::$availableBackgroundColors[$code].';';
- Exclude checks
When fetching an array index from a value of type array{30:'black',31:'red',32:'green',33:'yellow',34:'blue',35:'magenta',36:'cyan',37:'white'},
found an array index of type string,
but expected the index to be of type int
Open
Open
$out .= 'color:'.self::$availableForegroundColors[$code].';';
- Exclude checks