Function highlightText
has a Cognitive Complexity of 96 (exceeds 5 allowed). Consider refactoring. Open
public function highlightText(
$text,
$terms,
$contextlines = self::DEFAULT_CONTEXT_LINES,
$contextchars = self::DEFAULT_CONTEXT_CHARS
- 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 highlightText
has 192 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function highlightText(
$text,
$terms,
$contextlines = self::DEFAULT_CONTEXT_LINES,
$contextchars = self::DEFAULT_CONTEXT_CHARS
File SearchHighlighter.php
has 381 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Basic search engine highlighting
*
* This program is free software; you can redistribute it and/or modify
Function process
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ) {
if ( $linesleft == 0 ) {
return; // nothing to do
}
foreach ( $extracts as $index => $line ) {
- 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 process
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ) {
if ( $linesleft == 0 ) {
return; // nothing to do
}
foreach ( $extracts as $index => $line ) {
Method highlightSimple
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function highlightSimple(
$text,
$terms,
$contextlines = self::DEFAULT_CONTEXT_LINES,
$contextchars = self::DEFAULT_CONTEXT_CHARS
Function highlightSimple
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function highlightSimple(
$text,
$terms,
$contextlines = self::DEFAULT_CONTEXT_LINES,
$contextchars = self::DEFAULT_CONTEXT_CHARS
- 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 position
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function position( $text, $point, $offset = 0 ) {
$tolerance = 10;
$s = max( 0, $point - $tolerance );
$l = min( strlen( $text ), $point + $tolerance ) - $s;
$m = [];
- 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 deeply nested control flow statements. Open
if (
MediaWikiServices::getInstance()->getContentLanguage()->
getNsIndex( $ns ) !== NS_FILE
) {
break;
Method process
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ) {
Method extract
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function extract( $text, $start, $end, &$posStart = null, &$posEnd = null ) {
Function extract
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function extract( $text, $start, $end, &$posStart = null, &$posEnd = null ) {
if ( $start != 0 ) {
$start = $this->position( $text, $start, 1 );
}
if ( $end >= strlen( $text ) ) {
- 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"