Passed
Push — main ( ebbc7c...eb1d9a )
by Michael
04:10
created

HelpsFormatData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 9
dl 0
loc 29
ccs 6
cts 10
cp 0.6
rs 10
c 2
b 1
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractStringFromCollection() 0 11 3
A getFirstFrom() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\Formatters\Traits;
6
7
use Illuminate\Support\Collection;
8
9
trait HelpsFormatData
10
{
11
    /**
12
     * @param Collection $collection
13
     *
14
     * @return string
15
     */
16 7
    private function extractStringFromCollection(Collection $collection): string
17
    {
18 7
        $extracted = $collection->first();
19
20 7
        if (is_array($extracted)) {
21
            $extracted = current($extracted);
22
        }
23
24 7
        return is_string($extracted)
25 6
            ? $extracted
26 7
            : (string) $extracted;
27
    }
28
29
    /**
30
     * @param Collection $items
31
     *
32
     * @return Collection
33
     */
34
    private function getFirstFrom(Collection $items): Collection
35
    {
36
        return collect(
37
            $items->first()
38
        );
39
    }
40
}
41