Gallery::fillSource()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
3
namespace One\Model;
4
5
use One\Collection;
6
7
/**
8
 * Attachment Gallery class
9
 */
10
class Gallery extends Model
11
{
12
    /**
13
     * constructor
14
     *
15
     * @param \Psr\Http\Message\UriInterface|string $photo
16
     * @param \Psr\Http\Message\UriInterface|string $source
17
     * @param string $lead
18
     */
19
    public function __construct(
20
        string $body,
21
        int $order,
22
        $photo,
23
        $source,
24
        $lead = ''
25
    ) {
26
        $this->collection = new Collection([
27
            'lead' => empty($lead) ? $this->createLeadFromBody($body) : $this->filterStringInstance($lead),
28
            'body' => $this->filterStringInstance($body),
29
            'source' => $this->fillSource($source, $photo),
30
            'order' => $order,
31
            'photo' => $this->filterUriInstance($photo),
32
        ]);
33
    }
34
35
    /**
36
     * source taken from photo url if not available
37
     *
38
     * @param \Psr\Http\Message\UriInterface|string $source
39
     * @param \Psr\Http\Message\UriInterface|string $photo
40
     */
41
    private function fillSource($source, $photo): string
42
    {
43
        if (! empty($source)) {
44
            return $this->filterUriInstance($source);
45
        }
46
47
        return (string) $photo;
48
    }
49
}
50