HasLimit::limit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
3
namespace LaraComponents\Seo\Traits;
4
5
trait HasLimit
6
{
7
    /**
8
     * Limit the number of characters in a string.
9
     *
10
     * @param  string  $value
11
     * @param  int     $limit
12
     * @param  string  $end
13
     * @return string
14
     */
15
    protected function limit($value, $limit = 100, $end = '...')
16
    {
17
        if (mb_strwidth($value, 'UTF-8') <= $limit) {
18
            return $value;
19
        }
20
21
        return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
22
    }
23
}
24