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

Text::extract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 1
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