Function htmlTruncateByWords
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
{
if (!$length) {
$length = Config::main('listview_max_textlength');
}
- 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 htmlTruncate
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
{
if (\strlen($html) <= $length) {
return $html;
}
- 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 htmlTruncateByWords
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
{
if (!$length) {
$length = Config::main('listview_max_textlength');
}
Method htmlTruncate
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
{
if (\strlen($html) <= $length) {
return $html;
}
Function textTruncate
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function textTruncate($text, $length = false, $addDots = true)
{
if (!$length) {
$length = Config::main('listview_max_textlength');
}
- 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 htmlTruncate() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
{
if (\strlen($html) <= $length) {
return $html;
}
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method htmlTruncateByWords() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
{
if (!$length) {
$length = Config::main('listview_max_textlength');
}
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed. Open
public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed. Open
public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Missing class import via use statement (line '176', column '14'). Open
$dom = new \DOMDocument('1.0', 'UTF-8');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method textTruncate has a boolean flag argument $length, which is a certain sign of a Single Responsibility Principle violation. Open
public static function textTruncate($text, $length = false, $addDots = true)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method textTruncate has a boolean flag argument $addDots, which is a certain sign of a Single Responsibility Principle violation. Open
public static function textTruncate($text, $length = false, $addDots = true)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class 'App\Config' in method 'htmlTruncateByWords'. Open
$length = Config::main('listview_max_textlength');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Config' in method 'textTruncate'. Open
$length = Config::main('listview_max_textlength');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Config' in method 'textTruncate'. Open
$text = mb_substr($text, 0, $length, Config::main('default_charset'));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "/^<\s*([^\s>!]+).*?>$/s" 4 times. Open
preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
- 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.
Returning type ?string
but textTruncate()
is declared to return string
Open
return $text;
- Exclude checks
Argument 1 (str)
is ?string
but \mb_substr()
takes string
Open
$text = mb_substr($text, 0, $length, Config::main('default_charset'));
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!empty($tag[1])) {
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
// if tag is a closing tag
} elseif (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $tag[1], $tagName)) {
$pos = array_search(strtolower($tagName[1]), $openTags);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 190.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!empty($tag[1])) {
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
// if tag is a closing tag
} elseif (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $tag[1], $tagName)) {
$pos = array_search(strtolower($tagName[1]), $openTags);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 190.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (($totalLength + $tagLength + $openTagsLength) >= $length) {
if (empty($html)) {
preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
$openTags[] = $tagName[1];
$html = $tag[1] . self::textTruncate($tag[2], $length - 3, false);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 97.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (($totalLength + $tagLength + $openTagsLength) >= $length) {
if (empty($html)) {
preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
$openTags[] = $tagName[1];
$html = $tag[1] . self::textTruncate($tag[2], $length - 3, false);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 97.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($addDots) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Truncating HTML.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $html
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $html;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html = $tag[1] . self::textTruncate($tag[2], $length - 3, false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool|int $length
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= $tag[0];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalLength += $tagLength;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '</' . implode('></', $openTags) . '>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTagsLength = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$textLength = mb_strlen($text);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$text .= '...';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// if tag is a closing tag
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== $pos) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTagsLength += \mb_strlen("</{$tagName[1]}>");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($openTags) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $text
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($tags as $tag) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html = $tag[1] . self::textTruncate($tag[2], $length - 3, false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($openTags[$pos]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $addDots
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getTextLength($text)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Truncating text.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $text;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $ending
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ((!$addDots && $textLength > $length) || ($addDots && $textLength > $length + 2)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $length
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (($totalLength + $tagLength + $openTagsLength) >= $length) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tagLength = \mb_strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $tag[2]));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTags[] = $tagName[1];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTags[] = $tagName[1];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $length
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Truncating HTML by words.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $html
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$length) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tagLength = \mb_strlen($tag[0]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($html)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTags = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function textTruncate($text, $length = false, $addDots = true)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$length) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
preg_match_all('/(<.+?>)?([^<>]*)/s', $html, $tags, PREG_SET_ORDER);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= $ending;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
preg_match_all('/(<.+?>)?([^<>]*)/s', $html, $tags, PREG_SET_ORDER);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
array_unshift($openTags, strtolower($tagName[1]));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get text length.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$length = Config::main('listview_max_textlength');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalLength = \mb_strlen($ending);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pos = array_search(strtolower($tagName[1]), $openTags);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $html;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\strlen($html) <= $length) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $text
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$length = Config::main('listview_max_textlength');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTagsLength = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($html)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$textLength = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $html;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return null !== $text ? mb_strlen($text) : 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null !== $text) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$text = mb_substr($text, 0, $length, Config::main('default_charset'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\strlen(strip_tags($html)) <= $length) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $tag[1], $tagName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($tag[1])) {
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $ending
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalLength = \mb_strlen($ending);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($tags as $tag) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (($totalLength + $tagLength + $openTagsLength) >= $length) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= $tag[0];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $tag[1], $tagName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($openTags[$pos]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= $ending;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $tag
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTagsLength -= \mb_strlen("</{$tagName[1]}>");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getTagAttributes(string $tag): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// if tag is a closing tag
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTagsLength += \mb_strlen("</{$tagName[1]}>");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTags = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$openTagsLength -= \mb_strlen("</{$tagName[1]}>");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dom = new \DOMDocument('1.0', 'UTF-8');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($tag->hasAttributes()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$attributes = [];
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '</' . implode('></', $openTags) . '>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pos = array_search(strtolower($tagName[1]), $openTags);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
array_unshift($openTags, strtolower($tagName[1]));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($openTags) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($tag->attributes as $attr) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$attributes[$attr->name] = $attr->value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($tag[1])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalLength += $tagLength;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tag = $dom->getElementsByTagName('*')->item(2);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
libxml_use_internal_errors($previousValue);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== $pos) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get all attributes of a tag.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
libxml_clear_errors();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $attributes;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $html;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$previousValue = libxml_use_internal_errors(true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dom->loadHTML('<?xml encoding="utf-8"?>' . $tag);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks