Skip to content

Commit 57674d8

Browse files
committed
some refactoring for Maintainability
1 parent 344b3a4 commit 57674d8

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/Service/Generator/Compiler/MigrationCompiler.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\View\Factory as ViewFactory;
1010
use N3XT0R\MigrationGenerator\Service\Generator\Compiler\Mapper\MapperInterface;
1111
use N3XT0R\MigrationGenerator\Service\Generator\Definition\Entity\ResultEntity;
12+
use N3XT0R\MigrationGenerator\Service\Generator\DTO\MigrationTimingDto;
1213
use N3XT0R\MigrationGenerator\Service\Generator\Sort\TopSort;
1314

1415
class MigrationCompiler implements MigrationCompilerInterface
@@ -155,16 +156,18 @@ private function extractClassFromNamespace(string $namespaceLine): string
155156
public function writeToDisk(
156157
string $name,
157158
string $path,
158-
int $currentAmount = -1,
159-
int $maxAmount = -1,
160-
int $timestamp = -1
159+
MigrationTimingDto $timingDto = new MigrationTimingDto()
161160
): bool {
162161
$result = false;
163162
$this->setMigrationFiles([]);
164163
$tpl = $this->getRenderedTemplate();
165164

166165
if (!empty($tpl)) {
167-
$fileName = $this->generateFilename($name, $currentAmount, $maxAmount, $timestamp);
166+
$fileName = $this->generateFilename($name,
167+
$timingDto->getCurrentAmount(),
168+
$timingDto->getMaxAmount(),
169+
$timingDto->getTimestamp()
170+
);
168171
$renderedTemplate = str_replace('DummyClass', Str::studly($name), $tpl);
169172
$result = $this->writeTemplateToFile($path, $fileName, $renderedTemplate);
170173
}

src/Service/Generator/Compiler/MigrationCompilerInterface.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
use N3XT0R\MigrationGenerator\Service\Generator\Definition\Entity\ResultEntity;
8+
use N3XT0R\MigrationGenerator\Service\Generator\DTO\MigrationTimingDto;
89

910
interface MigrationCompilerInterface
1011
{
@@ -16,9 +17,7 @@ public function generateByResult(ResultEntity $resultEntity, string $customMigra
1617
public function writeToDisk(
1718
string $name,
1819
string $path,
19-
int $currentAmount = -1,
20-
int $maxAmount = -1,
21-
int $timestamp = -1
20+
MigrationTimingDto $timingDto
2221
): bool;
2322

2423
public function getMigrationFiles(): array;

src/Service/Generator/MigrationGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ public function generateMigrationForTable(
112112
$result = $compiler->writeToDisk(
113113
'Create'.ucfirst($table).'Table',
114114
$this->getMigrationDir(),
115-
$timingDto->getCurrentAmount(),
116-
$timingDto->getMaxAmount(),
117-
$timingDto->getMaxAmount()
115+
$timingDto,
118116
);
119117
$this->setMigrationFiles($compiler->getMigrationFiles());
120118
} catch (\Exception $e) {

0 commit comments

Comments
 (0)