Total Complexity | 2 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class CodeSample |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | public $code; |
||
15 | |||
16 | /** |
||
17 | * @var \Illuminate\Support\Collection|\Zing\QueryBuilder\Samples\IOSample[] |
||
18 | */ |
||
19 | public $ioSamples; |
||
20 | |||
21 | /** |
||
22 | * @param \Zing\QueryBuilder\Samples\IOSample[] $ioSamples |
||
23 | */ |
||
24 | public function __construct(string $code, array $ioSamples) |
||
25 | { |
||
26 | $this->code = $code; |
||
27 | $this->ioSamples = collect($ioSamples); |
||
28 | } |
||
29 | |||
30 | public function print(): string |
||
31 | { |
||
32 | return sprintf("```php\n%s```" . PHP_EOL, str_replace( |
||
33 | PHP_EOL . PHP_EOL, |
||
34 | PHP_EOL . PHP_EOL . $this->ioSamples->map(function ($ioSample): string { |
||
35 | return implode('', [ |
||
36 | sprintf('// uri: %s' . PHP_EOL, $ioSample->uri), |
||
37 | sprintf('// sql: %s' . PHP_EOL, $ioSample->sql), |
||
38 | ]); |
||
39 | })->implode(''), |
||
40 | str_replace('<?php |
||
41 | |||
42 | declare(strict_types=1); |
||
43 | |||
44 | ', '', (string) file_get_contents($this->code)) |
||
45 | )); |
||
48 |