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

CodeSample::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Samples;
6
7
use function collect;
8
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
        ));
46
    }
47
}
48