Passed
Push — main ( eb1d9a...1db9f0 )
by Michael
04:31 queued 10s
created

HelpsFormatData   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 7
c 2
b 1
f 0
dl 0
loc 18
ccs 6
cts 7
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A extractStringFromCollection() 0 11 3
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