| Total Complexity | 8 |
| Total Lines | 87 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | abstract class FileDumper implements DumperInterface |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * The path of the file to generate. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $path; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The file extension. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $extension; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The file content. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $content = ''; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Instantiate the class. |
||
| 37 | * |
||
| 38 | * @param string $path |
||
| 39 | */ |
||
| 40 | 24 | public function __construct(string $path = null) |
|
| 41 | { |
||
| 42 | 24 | $this->path = $path ?: $this->getDefaultPath(); |
|
| 43 | 24 | } |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Retrieve the default file path |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | 15 | protected function getDefaultPath(): string |
|
| 51 | { |
||
| 52 | 15 | if ($path = Config::get('sql_dumper.' . static::class . '.path')) { |
|
| 53 | 6 | return $path; |
|
| 54 | } |
||
| 55 | |||
| 56 | 9 | return App::storagePath() . '/sql_dump_' . time() . '.' . $this->getExtension(); |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Retrieve the file extension |
||
| 61 | * |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | 9 | protected function getExtension(): string |
|
| 65 | { |
||
| 66 | 9 | return (string) $this->extension; |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Retrieve the file path |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | 3 | public function getPath(): string |
|
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Retrieve the file content |
||
| 81 | * |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | 3 | public function getContent(): string |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Dump queries information |
||
| 91 | * |
||
| 92 | * @return mixed |
||
| 93 | */ |
||
| 94 | 12 | public function dump() |
|
| 101 |