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

TextParser::textTruncate()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.8333
c 0
b 0
f 0
cc 7
nc 6
nop 3
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