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

HelpsFormatData::getFirstFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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