Passed
Push — master ( ec9982...23e9a9 )
by Zing
06:03
created

Sample::print()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Samples;
6
7
use function collect;
8
9
class Sample
10
{
11
    /**
12
     * @var string
13
     */
14
    public $title;
15
16
    /**
17
     * @var string
18
     */
19
    public $subtitle;
20
21
    /**
22
     * @var \Illuminate\Support\Collection|\Zing\QueryBuilder\Samples\CodeSample[]
23
     */
24
    public $codeSamples;
25
26
    /**
27
     * @var string
28
     */
29
    private $description = '';
30
31
    /**
32
     * @param \Zing\QueryBuilder\Samples\CodeSample[] $codeSamples
33
     */
34
    public function __construct(string $title, string $subtitle, array $codeSamples)
35
    {
36
        $this->title = $title;
37
        $this->subtitle = $subtitle;
38
        $this->codeSamples = collect($codeSamples);
39
    }
40
41
    public function description(string $description): self
42
    {
43
        $this->description = $description;
44
45
        return $this;
46
    }
47
48
    public function print(): string
49
    {
50
        $lines = [];
51
        if ($this->description !== '' && $this->description !== '0') {
52
            $lines[] = sprintf('**%s**' . PHP_EOL, $this->description);
53
        }
54
55
        $lines[] = $this->codeSamples->map->print()->implode(PHP_EOL);
56
57
        return implode(PHP_EOL, $lines);
58
    }
59
}
60