convertStringsToBoolean()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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