TextTransform   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
dl 0
loc 28
rs 10
c 1
b 0
f 1
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 12 6
1
<?php
2
3
namespace ByTIC\DocumentGenerator\PdfLetters\Models\Fields\Attributes;
4
5
use Nip\Utility\Str;
6
7
class TextTransform
8
{
9
    public const NAME = "text_transform";
10
11
    public const NONE = "none";
12
    public const CAPITALIZE = "capitalize";
13
    public const UPPERCASE = "uppercase";
14
    public const LOWERCASE = "lowercase";
15
16
    public const OPTIONS = [self::NONE, self::CAPITALIZE, self::UPPERCASE, self::LOWERCASE];
17
18
    /**
19
     * @param string $value
20
     * @param null $transform
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $transform is correct as it would always require null to be passed?
Loading history...
21
     * @return mixed|string
22
     */
23
    public static function transform($value, $transform = null)
24
    {
25
        if (empty($transform) || $transform == null || $transform == static::NONE) {
26
            return $value;
27
        }
28
        if ($transform === static::UPPERCASE) {
29
            return Str::upper($value);
30
        }
31
        if ($transform === static::LOWERCASE) {
32
            return Str::lower($value);
33
        }
34
        return $value;
35
    }
36
}