CanConvertValuesToBooleans   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 8
cp 0
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertBooleansToString() 0 12 3
A convertStringsToBoolean() 0 12 3
1
<?php
2
3
/**
4
 * This file is part of Dimtrovich/Validation.
5
 *
6
 * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Dimtrovich\Validation\Traits;
13
14
/**
15
 * @credit <a href="https://github.com/somnambulist-tech/validation">somnambulist-tech/validation - Somnambulist\Components\Validation\Rules\Behaviours\CanConvertValuesToBooleans</a>
16
 */
17
trait CanConvertValuesToBooleans
18
{
19
    private function convertStringsToBoolean(array $values): array
20
    {
21
        return array_map(function ($value) {
22
            if ($value === 'true') {
23
                return true;
24
            }
25
            if ($value === 'false') {
26
                return false;
27
            }
28
29
            return $value;
30
        }, $values);
31
    }
32
33
    private function convertBooleansToString(array $values): array
34
    {
35
        return array_map(function ($value) {
36
            if ($value === true) {
37
                return 'true';
38
            }
39
            if ($value === false) {
40
                return 'false';
41
            }
42
43
            return (string) $value;
44
        }, $values);
45
    }
46
}
47