Completed
Push — master ( ac62eb...633109 )
by Dawid
03:39
created

Text::trimString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
crap 2.0625
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Mapping\Strategy;
4
5
use Igni\Storage\Mapping\MappingStrategy;
6
7
final class Text implements MappingStrategy
8
{
9 14
    public static function hydrate(&$value, array $attributes = []): void
10
    {
11 14
        $value = self::trimString($value, $attributes);
12 14
    }
13
14 7
    public static function extract(&$value, array $attributes = []): void
15
    {
16 7
        $value = self::trimString($value, $attributes);
17 7
    }
18
19 17
    private static function trimString($value, array $attributes = []): string
20
    {
21 17
        if (isset($attributes['length'])) {
22
            return substr((string) $value, 0, (int) $attributes['length']);
23
        }
24
25 17
        return (string) $value;
26
    }
27
}
28