Gallery   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A fillSource() 0 7 2
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