Encoding   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A keywordField() 0 18 3
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Helper;
4
5
final class Encoding
6
{
7
    /**
8
     * The maximum number of characters that are accepted in a keyword field.
9
     */
10
    const KEYWORD_MAX_LENGTH = 1024;
11
12
    /**
13
     * Limit the size of keyword fields.
14
     *
15
     * @param int|string|null $value
16
     *
17
     * @return string
18
     */
19 40
    public static function keywordField($value)
20
    {
21 40
        if (false === is_string($value)) {
22 4
            return $value;
23
        }
24
25 40
        if (strlen($value) <= self::KEYWORD_MAX_LENGTH) {
26 39
            return $value;
27
        }
28
29 1
        $value = mb_substr(
30 1
            $value,
31 1
            0,
32 1
            self::KEYWORD_MAX_LENGTH - 1,
33
            'UTF-8'
34 1
        );
35
36 1
        return $value . '…';
37
    }
38
}
39