Passed
Push — master ( 9af7ee...312f19 )
by Christoph
15:17 queued 13s
created
lib/private/Console/Application.php 1 patch
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -47,191 +47,191 @@
 block discarded – undo
47 47
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
48 48
 
49 49
 class Application {
50
-	/** @var IConfig */
51
-	private $config;
52
-	private SymfonyApplication $application;
53
-	/** @var EventDispatcherInterface */
54
-	private $dispatcher;
55
-	/** @var IRequest */
56
-	private $request;
57
-	/** @var LoggerInterface */
58
-	private $logger;
59
-	/** @var MemoryInfo */
60
-	private $memoryInfo;
50
+    /** @var IConfig */
51
+    private $config;
52
+    private SymfonyApplication $application;
53
+    /** @var EventDispatcherInterface */
54
+    private $dispatcher;
55
+    /** @var IRequest */
56
+    private $request;
57
+    /** @var LoggerInterface */
58
+    private $logger;
59
+    /** @var MemoryInfo */
60
+    private $memoryInfo;
61 61
 
62
-	public function __construct(IConfig $config,
63
-								EventDispatcherInterface $dispatcher,
64
-								IRequest $request,
65
-								LoggerInterface $logger,
66
-								MemoryInfo $memoryInfo) {
67
-		$defaults = \OC::$server->getThemingDefaults();
68
-		$this->config = $config;
69
-		$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
70
-		$this->dispatcher = $dispatcher;
71
-		$this->request = $request;
72
-		$this->logger = $logger;
73
-		$this->memoryInfo = $memoryInfo;
74
-	}
62
+    public function __construct(IConfig $config,
63
+                                EventDispatcherInterface $dispatcher,
64
+                                IRequest $request,
65
+                                LoggerInterface $logger,
66
+                                MemoryInfo $memoryInfo) {
67
+        $defaults = \OC::$server->getThemingDefaults();
68
+        $this->config = $config;
69
+        $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
70
+        $this->dispatcher = $dispatcher;
71
+        $this->request = $request;
72
+        $this->logger = $logger;
73
+        $this->memoryInfo = $memoryInfo;
74
+    }
75 75
 
76
-	/**
77
-	 * @param InputInterface $input
78
-	 * @param ConsoleOutputInterface $output
79
-	 * @throws \Exception
80
-	 */
81
-	public function loadCommands(
82
-		InputInterface $input,
83
-		ConsoleOutputInterface $output
84
-	) {
85
-		// $application is required to be defined in the register_command scripts
86
-		$application = $this->application;
87
-		$inputDefinition = $application->getDefinition();
88
-		$inputDefinition->addOption(
89
-			new InputOption(
90
-				'no-warnings',
91
-				null,
92
-				InputOption::VALUE_NONE,
93
-				'Skip global warnings, show command output only',
94
-				null
95
-			)
96
-		);
97
-		try {
98
-			$input->bind($inputDefinition);
99
-		} catch (\RuntimeException $e) {
100
-			//expected if there are extra options
101
-		}
102
-		if ($input->getOption('no-warnings')) {
103
-			$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
104
-		}
76
+    /**
77
+     * @param InputInterface $input
78
+     * @param ConsoleOutputInterface $output
79
+     * @throws \Exception
80
+     */
81
+    public function loadCommands(
82
+        InputInterface $input,
83
+        ConsoleOutputInterface $output
84
+    ) {
85
+        // $application is required to be defined in the register_command scripts
86
+        $application = $this->application;
87
+        $inputDefinition = $application->getDefinition();
88
+        $inputDefinition->addOption(
89
+            new InputOption(
90
+                'no-warnings',
91
+                null,
92
+                InputOption::VALUE_NONE,
93
+                'Skip global warnings, show command output only',
94
+                null
95
+            )
96
+        );
97
+        try {
98
+            $input->bind($inputDefinition);
99
+        } catch (\RuntimeException $e) {
100
+            //expected if there are extra options
101
+        }
102
+        if ($input->getOption('no-warnings')) {
103
+            $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
104
+        }
105 105
 
106
-		if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
107
-			$output->getErrorOutput()->writeln(
108
-				'<comment>The current PHP memory limit ' .
109
-				'is below the recommended value of 512MB.</comment>'
110
-			);
111
-		}
106
+        if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
107
+            $output->getErrorOutput()->writeln(
108
+                '<comment>The current PHP memory limit ' .
109
+                'is below the recommended value of 512MB.</comment>'
110
+            );
111
+        }
112 112
 
113
-		try {
114
-			require_once __DIR__ . '/../../../core/register_command.php';
115
-			if ($this->config->getSystemValue('installed', false)) {
116
-				if (\OCP\Util::needUpgrade()) {
117
-					throw new NeedsUpdateException();
118
-				} elseif ($this->config->getSystemValueBool('maintenance')) {
119
-					$this->writeMaintenanceModeInfo($input, $output);
120
-				} else {
121
-					OC_App::loadApps();
122
-					$appManager = \OCP\Server::get(IAppManager::class);
123
-					foreach ($appManager->getInstalledApps() as $app) {
124
-						$appPath = \OC_App::getAppPath($app);
125
-						if ($appPath === false) {
126
-							continue;
127
-						}
128
-						// load commands using info.xml
129
-						$info = $appManager->getAppInfo($app);
130
-						if (isset($info['commands'])) {
131
-							$this->loadCommandsFromInfoXml($info['commands']);
132
-						}
133
-						// load from register_command.php
134
-						\OC_App::registerAutoloading($app, $appPath);
135
-						$file = $appPath . '/appinfo/register_command.php';
136
-						if (file_exists($file)) {
137
-							try {
138
-								require $file;
139
-							} catch (\Exception $e) {
140
-								$this->logger->error($e->getMessage(), [
141
-									'exception' => $e,
142
-								]);
143
-							}
144
-						}
145
-					}
146
-				}
147
-			} elseif ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') {
148
-				$errorOutput = $output->getErrorOutput();
149
-				$errorOutput->writeln("Nextcloud is not installed - only a limited number of commands are available");
150
-			}
151
-		} catch (NeedsUpdateException $e) {
152
-			if ($input->getArgument('command') !== '_completion') {
153
-				$errorOutput = $output->getErrorOutput();
154
-				$errorOutput->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available");
155
-				$errorOutput->writeln("You may use your browser or the occ upgrade command to do the upgrade");
156
-			}
157
-		}
113
+        try {
114
+            require_once __DIR__ . '/../../../core/register_command.php';
115
+            if ($this->config->getSystemValue('installed', false)) {
116
+                if (\OCP\Util::needUpgrade()) {
117
+                    throw new NeedsUpdateException();
118
+                } elseif ($this->config->getSystemValueBool('maintenance')) {
119
+                    $this->writeMaintenanceModeInfo($input, $output);
120
+                } else {
121
+                    OC_App::loadApps();
122
+                    $appManager = \OCP\Server::get(IAppManager::class);
123
+                    foreach ($appManager->getInstalledApps() as $app) {
124
+                        $appPath = \OC_App::getAppPath($app);
125
+                        if ($appPath === false) {
126
+                            continue;
127
+                        }
128
+                        // load commands using info.xml
129
+                        $info = $appManager->getAppInfo($app);
130
+                        if (isset($info['commands'])) {
131
+                            $this->loadCommandsFromInfoXml($info['commands']);
132
+                        }
133
+                        // load from register_command.php
134
+                        \OC_App::registerAutoloading($app, $appPath);
135
+                        $file = $appPath . '/appinfo/register_command.php';
136
+                        if (file_exists($file)) {
137
+                            try {
138
+                                require $file;
139
+                            } catch (\Exception $e) {
140
+                                $this->logger->error($e->getMessage(), [
141
+                                    'exception' => $e,
142
+                                ]);
143
+                            }
144
+                        }
145
+                    }
146
+                }
147
+            } elseif ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') {
148
+                $errorOutput = $output->getErrorOutput();
149
+                $errorOutput->writeln("Nextcloud is not installed - only a limited number of commands are available");
150
+            }
151
+        } catch (NeedsUpdateException $e) {
152
+            if ($input->getArgument('command') !== '_completion') {
153
+                $errorOutput = $output->getErrorOutput();
154
+                $errorOutput->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available");
155
+                $errorOutput->writeln("You may use your browser or the occ upgrade command to do the upgrade");
156
+            }
157
+        }
158 158
 
159
-		if ($input->getFirstArgument() !== 'check') {
160
-			$errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
161
-			if (!empty($errors)) {
162
-				foreach ($errors as $error) {
163
-					$output->writeln((string)$error['error']);
164
-					$output->writeln((string)$error['hint']);
165
-					$output->writeln('');
166
-				}
167
-				throw new \Exception("Environment not properly prepared.");
168
-			}
169
-		}
170
-	}
159
+        if ($input->getFirstArgument() !== 'check') {
160
+            $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
161
+            if (!empty($errors)) {
162
+                foreach ($errors as $error) {
163
+                    $output->writeln((string)$error['error']);
164
+                    $output->writeln((string)$error['hint']);
165
+                    $output->writeln('');
166
+                }
167
+                throw new \Exception("Environment not properly prepared.");
168
+            }
169
+        }
170
+    }
171 171
 
172
-	/**
173
-	 * Write a maintenance mode info.
174
-	 * The commands "_completion" and "maintenance:mode" are excluded.
175
-	 *
176
-	 * @param InputInterface $input The input implementation for reading inputs.
177
-	 * @param ConsoleOutputInterface $output The output implementation
178
-	 * for writing outputs.
179
-	 * @return void
180
-	 */
181
-	private function writeMaintenanceModeInfo(
182
-		InputInterface $input, ConsoleOutputInterface $output
183
-	) {
184
-		if ($input->getArgument('command') !== '_completion'
185
-			&& $input->getArgument('command') !== 'maintenance:mode'
186
-			&& $input->getArgument('command') !== 'status') {
187
-			$errOutput = $output->getErrorOutput();
188
-			$errOutput->writeln(
189
-				'<comment>Nextcloud is in maintenance mode, hence the database isn\'t accessible.' . PHP_EOL .
190
-				'Cannot perform any command except \'maintenance:mode --off\'</comment>' . PHP_EOL
191
-			);
192
-		}
193
-	}
172
+    /**
173
+     * Write a maintenance mode info.
174
+     * The commands "_completion" and "maintenance:mode" are excluded.
175
+     *
176
+     * @param InputInterface $input The input implementation for reading inputs.
177
+     * @param ConsoleOutputInterface $output The output implementation
178
+     * for writing outputs.
179
+     * @return void
180
+     */
181
+    private function writeMaintenanceModeInfo(
182
+        InputInterface $input, ConsoleOutputInterface $output
183
+    ) {
184
+        if ($input->getArgument('command') !== '_completion'
185
+            && $input->getArgument('command') !== 'maintenance:mode'
186
+            && $input->getArgument('command') !== 'status') {
187
+            $errOutput = $output->getErrorOutput();
188
+            $errOutput->writeln(
189
+                '<comment>Nextcloud is in maintenance mode, hence the database isn\'t accessible.' . PHP_EOL .
190
+                'Cannot perform any command except \'maintenance:mode --off\'</comment>' . PHP_EOL
191
+            );
192
+        }
193
+    }
194 194
 
195
-	/**
196
-	 * Sets whether to automatically exit after a command execution or not.
197
-	 *
198
-	 * @param bool $boolean Whether to automatically exit after a command execution or not
199
-	 */
200
-	public function setAutoExit($boolean) {
201
-		$this->application->setAutoExit($boolean);
202
-	}
195
+    /**
196
+     * Sets whether to automatically exit after a command execution or not.
197
+     *
198
+     * @param bool $boolean Whether to automatically exit after a command execution or not
199
+     */
200
+    public function setAutoExit($boolean) {
201
+        $this->application->setAutoExit($boolean);
202
+    }
203 203
 
204
-	/**
205
-	 * @param InputInterface $input
206
-	 * @param OutputInterface $output
207
-	 * @return int
208
-	 * @throws \Exception
209
-	 */
210
-	public function run(InputInterface $input = null, OutputInterface $output = null) {
211
-		$this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
212
-			ConsoleEvent::EVENT_RUN,
213
-			$this->request->server['argv']
214
-		));
215
-		return $this->application->run($input, $output);
216
-	}
204
+    /**
205
+     * @param InputInterface $input
206
+     * @param OutputInterface $output
207
+     * @return int
208
+     * @throws \Exception
209
+     */
210
+    public function run(InputInterface $input = null, OutputInterface $output = null) {
211
+        $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
212
+            ConsoleEvent::EVENT_RUN,
213
+            $this->request->server['argv']
214
+        ));
215
+        return $this->application->run($input, $output);
216
+    }
217 217
 
218
-	private function loadCommandsFromInfoXml($commands) {
219
-		foreach ($commands as $command) {
220
-			try {
221
-				$c = \OC::$server->query($command);
222
-			} catch (QueryException $e) {
223
-				if (class_exists($command)) {
224
-					try {
225
-						$c = new $command();
226
-					} catch (\ArgumentCountError $e2) {
227
-						throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e);
228
-					}
229
-				} else {
230
-					throw new \Exception("Console command '$command' is unknown and could not be loaded");
231
-				}
232
-			}
218
+    private function loadCommandsFromInfoXml($commands) {
219
+        foreach ($commands as $command) {
220
+            try {
221
+                $c = \OC::$server->query($command);
222
+            } catch (QueryException $e) {
223
+                if (class_exists($command)) {
224
+                    try {
225
+                        $c = new $command();
226
+                    } catch (\ArgumentCountError $e2) {
227
+                        throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e);
228
+                    }
229
+                } else {
230
+                    throw new \Exception("Console command '$command' is unknown and could not be loaded");
231
+                }
232
+            }
233 233
 
234
-			$this->application->add($c);
235
-		}
236
-	}
234
+            $this->application->add($c);
235
+        }
236
+    }
237 237
 }
Please login to merge, or discard this patch.