Passed
Push — developer ( 8ac017...cc24b2 )
by Mariusz
73:39 queued 38:36
created

TextParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B textTruncate() 0 14 7
1
<?php
2
3
namespace App;
4
5
/**
6
 * Text parser class.
7
 *
8
 * @package App
9
 *
10
 * @copyright YetiForce Sp. z o.o
11
 * @license   YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
12
 * @author    Arkadiusz Sołek <[email protected]>
13
 */
14
class TextParser
0 ignored issues
show
Coding Style introduced by
TextParser does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
15
{
16
	/**
17
	 * Truncating text.
18
	 *
19
	 * @param string   $text
20
	 * @param bool|int $length
21
	 * @param bool     $addDots
22
	 *
23
	 * @return string
24
	 */
25
	public static function textTruncate($text, $length = false, $addDots = true)
26
	{
27
		if (!$length) {
28
			$length = 40;
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $length. This often makes code more readable.
Loading history...
29
		}
30
		$textLength = mb_strlen($text);
31
		if ((!$addDots && $textLength > $length) || ($addDots && $textLength > $length + 2)) {
32
			$text = mb_substr($text, 0, $length, 'UTF-8');
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $text. This often makes code more readable.
Loading history...
33
			if ($addDots) {
34
				$text .= '...';
35
			}
36
		}
37
		return $text;
38
	}
39
}
40