Completed
Pull Request — master (#6048)
by Joas
30:00 queued 13:52
created
core/Command/Db/Migrations/GenerateCommand.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 
37 37
 class GenerateCommand extends Command {
38 38
 
39
-	protected static $_templateSimple =
40
-		'<?php
39
+    protected static $_templateSimple =
40
+        '<?php
41 41
 namespace {{namespace}};
42 42
 
43 43
 use Doctrine\DBAL\Schema\Schema;
@@ -80,94 +80,94 @@  discard block
 block discarded – undo
80 80
 }
81 81
 ';
82 82
 
83
-	/** @var IDBConnection */
84
-	protected $connection;
85
-
86
-	/**
87
-	 * @param IDBConnection $connection
88
-	 */
89
-	public function __construct(IDBConnection $connection) {
90
-		$this->connection = $connection;
91
-
92
-		parent::__construct();
93
-	}
94
-
95
-	protected function configure() {
96
-		$this
97
-			->setName('migrations:generate')
98
-			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
99
-			->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches')
100
-		;
101
-
102
-		parent::configure();
103
-	}
104
-
105
-	public function execute(InputInterface $input, OutputInterface $output) {
106
-		$appName = $input->getArgument('app');
107
-		$version = $input->getArgument('version');
108
-
109
-		if (!preg_match('/^\d{1,16}$/',$version)) {
110
-			$output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
111
-			return 1;
112
-		}
113
-
114
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
115
-
116
-		$date = date('YmdHis');
117
-		$path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date);
118
-
119
-		$output->writeln("New migration class has been generated to <info>$path</info>");
120
-		return 0;
121
-	}
122
-
123
-	/**
124
-	 * @param MigrationService $ms
125
-	 * @param string $className
126
-	 * @param string $schemaBody
127
-	 * @return string
128
-	 */
129
-	protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') {
130
-		if ($schemaBody === '') {
131
-			$schemaBody = "\t\t" . 'return null;';
132
-		}
133
-
134
-
135
-		$placeHolders = [
136
-			'{{namespace}}',
137
-			'{{classname}}',
138
-			'{{schemabody}}',
139
-		];
140
-		$replacements = [
141
-			$ms->getMigrationsNamespace(),
142
-			$className,
143
-			$schemaBody,
144
-		];
145
-		$code = str_replace($placeHolders, $replacements, self::$_templateSimple);
146
-		$dir = $ms->getMigrationsDirectory();
147
-
148
-		$this->ensureMigrationDirExists($dir);
149
-		$path = $dir . '/' . $className . '.php';
150
-
151
-		if (file_put_contents($path, $code) === false) {
152
-			throw new RuntimeException('Failed to generate new migration step.');
153
-		}
154
-
155
-		return $path;
156
-	}
157
-
158
-	protected function ensureMigrationDirExists($directory) {
159
-		if (file_exists($directory) && is_dir($directory)) {
160
-			return;
161
-		}
162
-
163
-		if (file_exists($directory)) {
164
-			throw new \RuntimeException("Could not create folder \"$directory\"");
165
-		}
166
-
167
-		$this->ensureMigrationDirExists(dirname($directory));
168
-
169
-		if (!@mkdir($directory) && !is_dir($directory)) {
170
-			throw new \RuntimeException("Could not create folder \"$directory\"");
171
-		}
172
-	}
83
+    /** @var IDBConnection */
84
+    protected $connection;
85
+
86
+    /**
87
+     * @param IDBConnection $connection
88
+     */
89
+    public function __construct(IDBConnection $connection) {
90
+        $this->connection = $connection;
91
+
92
+        parent::__construct();
93
+    }
94
+
95
+    protected function configure() {
96
+        $this
97
+            ->setName('migrations:generate')
98
+            ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
99
+            ->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches')
100
+        ;
101
+
102
+        parent::configure();
103
+    }
104
+
105
+    public function execute(InputInterface $input, OutputInterface $output) {
106
+        $appName = $input->getArgument('app');
107
+        $version = $input->getArgument('version');
108
+
109
+        if (!preg_match('/^\d{1,16}$/',$version)) {
110
+            $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
111
+            return 1;
112
+        }
113
+
114
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
115
+
116
+        $date = date('YmdHis');
117
+        $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date);
118
+
119
+        $output->writeln("New migration class has been generated to <info>$path</info>");
120
+        return 0;
121
+    }
122
+
123
+    /**
124
+     * @param MigrationService $ms
125
+     * @param string $className
126
+     * @param string $schemaBody
127
+     * @return string
128
+     */
129
+    protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') {
130
+        if ($schemaBody === '') {
131
+            $schemaBody = "\t\t" . 'return null;';
132
+        }
133
+
134
+
135
+        $placeHolders = [
136
+            '{{namespace}}',
137
+            '{{classname}}',
138
+            '{{schemabody}}',
139
+        ];
140
+        $replacements = [
141
+            $ms->getMigrationsNamespace(),
142
+            $className,
143
+            $schemaBody,
144
+        ];
145
+        $code = str_replace($placeHolders, $replacements, self::$_templateSimple);
146
+        $dir = $ms->getMigrationsDirectory();
147
+
148
+        $this->ensureMigrationDirExists($dir);
149
+        $path = $dir . '/' . $className . '.php';
150
+
151
+        if (file_put_contents($path, $code) === false) {
152
+            throw new RuntimeException('Failed to generate new migration step.');
153
+        }
154
+
155
+        return $path;
156
+    }
157
+
158
+    protected function ensureMigrationDirExists($directory) {
159
+        if (file_exists($directory) && is_dir($directory)) {
160
+            return;
161
+        }
162
+
163
+        if (file_exists($directory)) {
164
+            throw new \RuntimeException("Could not create folder \"$directory\"");
165
+        }
166
+
167
+        $this->ensureMigrationDirExists(dirname($directory));
168
+
169
+        if (!@mkdir($directory) && !is_dir($directory)) {
170
+            throw new \RuntimeException("Could not create folder \"$directory\"");
171
+        }
172
+    }
173 173
 }
Please login to merge, or discard this patch.