| Total Complexity | 6 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 12 | abstract class AbstractWriter implements WriterInterface |
||
| 13 | { |
||
| 14 | private $content; |
||
| 15 | |||
| 16 | private $filename; |
||
| 17 | |||
| 18 | private $path; |
||
| 19 | |||
| 20 | public function __construct(string $content, string $filename, string $path) |
||
| 21 | { |
||
| 22 | $this->content = $content; |
||
| 23 | $this->filename = $filename; |
||
| 24 | $this->path = $path; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function save(): string |
||
| 28 | { |
||
| 29 | $path = $this->getPath(); |
||
| 30 | |||
| 31 | if (!\is_dir($path)) { |
||
| 32 | \mkdir($path, 0777, true); // @codeCoverageIgnore |
||
| 33 | } |
||
| 34 | |||
| 35 | $output = \sprintf('%1$s/%2$s.%3$s', $path, $this->getFilename(), $this->getExtension()); |
||
| 36 | |||
| 37 | \file_put_contents($output, $this->getContent()); |
||
| 38 | |||
| 39 | return $output; |
||
| 40 | } |
||
| 41 | |||
| 42 | abstract protected function getExtension(): string; |
||
| 43 | |||
| 44 | private function getContent(): string |
||
| 47 | } |
||
| 48 | |||
| 49 | private function getFilename(): string |
||
| 50 | { |
||
| 51 | return $this->filename; |
||
| 52 | } |
||
| 53 | |||
| 54 | private function getPath(): string |
||
| 57 | } |
||
| 58 | } |
||
| 59 |