Passed
Pull Request — master (#149)
by Zing
06:07
created

Sample::description()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
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 string $title
33
     * @param string $subtitle
34
     * @param \Zing\QueryBuilder\Samples\CodeSample[] $codeSamples
35
     */
36
    public function __construct(string $title, string $subtitle, array $codeSamples)
37
    {
38
        $this->title = $title;
39
        $this->subtitle = $subtitle;
40
        $this->codeSamples = collect($codeSamples);
41
    }
42
43
    public function description(string $description): self
44
    {
45
        $this->description = $description;
46
47
        return $this;
48
    }
49
50
    public function print(): string
51
    {
52
        $lines = [];
53
        if ($this->description !== '' && $this->description !== '0') {
54
            $lines[] = sprintf('**%s**' . PHP_EOL, $this->description);
55
        }
56
57
        $lines[] = $this->codeSamples->map->print()->implode(PHP_EOL);
58
59
        return implode(PHP_EOL, $lines);
60
    }
61
}
62