Total Complexity | 5 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 | } |
||
60 |