| Total Complexity | 9 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 91.67% |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class MigrationDirectoryHelper extends Helper |
||
| 19 | { |
||
| 20 | /** @var Configuration */ |
||
| 21 | private $configuration; |
||
| 22 | |||
| 23 | 18 | public function __construct(Configuration $configuration) |
|
| 24 | { |
||
| 25 | 18 | $this->configuration = $configuration; |
|
| 26 | 18 | } |
|
| 27 | |||
| 28 | /** @throws InvalidArgumentException */ |
||
| 29 | 17 | public function getMigrationDirectory() : string |
|
| 30 | { |
||
| 31 | 17 | $dir = $this->configuration->getMigrationsDirectory(); |
|
| 32 | 17 | $dir = $dir ?? getcwd(); |
|
| 33 | 17 | $dir = rtrim($dir, '/'); |
|
| 34 | |||
| 35 | 17 | if (! file_exists($dir)) { |
|
| 36 | 1 | throw new InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir)); |
|
| 37 | } |
||
| 38 | |||
| 39 | 16 | if ($this->configuration->areMigrationsOrganizedByYear()) { |
|
| 40 | 3 | $dir .= $this->appendDir(date('Y')); |
|
| 41 | } |
||
| 42 | |||
| 43 | 16 | if ($this->configuration->areMigrationsOrganizedByYearAndMonth()) { |
|
| 44 | 2 | $dir .= $this->appendDir(date('m')); |
|
| 45 | } |
||
| 46 | |||
| 47 | 16 | $this->createDirIfNotExists($dir); |
|
| 48 | |||
| 49 | 16 | return $dir; |
|
| 50 | } |
||
| 51 | |||
| 52 | 3 | private function appendDir(string $dir) : string |
|
| 55 | } |
||
| 56 | |||
| 57 | 16 | private function createDirIfNotExists(string $dir) : void |
|
| 58 | { |
||
| 59 | 16 | if (file_exists($dir)) { |
|
| 60 | 13 | return; |
|
| 61 | } |
||
| 62 | |||
| 63 | 3 | mkdir($dir, 0755, true); |
|
| 64 | 3 | } |
|
| 65 | |||
| 66 | public function getName() : string |
||
| 69 | } |
||
| 70 | } |
||
| 71 |