Passed
Push — master ( ea6712...81e439 )
by Daniel
18:46 queued 12s
created
lib/private/Console/Application.php 2 patches
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -47,187 +47,187 @@
 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->getSystemValueBool('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->getSystemValueBool('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(InputInterface $input, ConsoleOutputInterface $output): void {
182
-		if ($input->getArgument('command') !== '_completion'
183
-			&& $input->getArgument('command') !== 'maintenance:mode'
184
-			&& $input->getArgument('command') !== 'status') {
185
-			$errOutput = $output->getErrorOutput();
186
-			$errOutput->writeln('<comment>Nextcloud is in maintenance mode, no apps are loaded.</comment>');
187
-			$errOutput->writeln('<comment>Commands provided by apps are unavailable.</comment>');
188
-		}
189
-	}
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(InputInterface $input, ConsoleOutputInterface $output): void {
182
+        if ($input->getArgument('command') !== '_completion'
183
+            && $input->getArgument('command') !== 'maintenance:mode'
184
+            && $input->getArgument('command') !== 'status') {
185
+            $errOutput = $output->getErrorOutput();
186
+            $errOutput->writeln('<comment>Nextcloud is in maintenance mode, no apps are loaded.</comment>');
187
+            $errOutput->writeln('<comment>Commands provided by apps are unavailable.</comment>');
188
+        }
189
+    }
190 190
 
191
-	/**
192
-	 * Sets whether to automatically exit after a command execution or not.
193
-	 *
194
-	 * @param bool $boolean Whether to automatically exit after a command execution or not
195
-	 */
196
-	public function setAutoExit($boolean) {
197
-		$this->application->setAutoExit($boolean);
198
-	}
191
+    /**
192
+     * Sets whether to automatically exit after a command execution or not.
193
+     *
194
+     * @param bool $boolean Whether to automatically exit after a command execution or not
195
+     */
196
+    public function setAutoExit($boolean) {
197
+        $this->application->setAutoExit($boolean);
198
+    }
199 199
 
200
-	/**
201
-	 * @param InputInterface $input
202
-	 * @param OutputInterface $output
203
-	 * @return int
204
-	 * @throws \Exception
205
-	 */
206
-	public function run(InputInterface $input = null, OutputInterface $output = null) {
207
-		$this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
208
-			ConsoleEvent::EVENT_RUN,
209
-			$this->request->server['argv']
210
-		));
211
-		return $this->application->run($input, $output);
212
-	}
200
+    /**
201
+     * @param InputInterface $input
202
+     * @param OutputInterface $output
203
+     * @return int
204
+     * @throws \Exception
205
+     */
206
+    public function run(InputInterface $input = null, OutputInterface $output = null) {
207
+        $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
208
+            ConsoleEvent::EVENT_RUN,
209
+            $this->request->server['argv']
210
+        ));
211
+        return $this->application->run($input, $output);
212
+    }
213 213
 
214
-	private function loadCommandsFromInfoXml($commands) {
215
-		foreach ($commands as $command) {
216
-			try {
217
-				$c = \OC::$server->query($command);
218
-			} catch (QueryException $e) {
219
-				if (class_exists($command)) {
220
-					try {
221
-						$c = new $command();
222
-					} catch (\ArgumentCountError $e2) {
223
-						throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e);
224
-					}
225
-				} else {
226
-					throw new \Exception("Console command '$command' is unknown and could not be loaded");
227
-				}
228
-			}
214
+    private function loadCommandsFromInfoXml($commands) {
215
+        foreach ($commands as $command) {
216
+            try {
217
+                $c = \OC::$server->query($command);
218
+            } catch (QueryException $e) {
219
+                if (class_exists($command)) {
220
+                    try {
221
+                        $c = new $command();
222
+                    } catch (\ArgumentCountError $e2) {
223
+                        throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e);
224
+                    }
225
+                } else {
226
+                    throw new \Exception("Console command '$command' is unknown and could not be loaded");
227
+                }
228
+            }
229 229
 
230
-			$this->application->add($c);
231
-		}
232
-	}
230
+            $this->application->add($c);
231
+        }
232
+    }
233 233
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 
106 106
 		if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
107 107
 			$output->getErrorOutput()->writeln(
108
-				'<comment>The current PHP memory limit ' .
108
+				'<comment>The current PHP memory limit '.
109 109
 				'is below the recommended value of 512MB.</comment>'
110 110
 			);
111 111
 		}
112 112
 
113 113
 		try {
114
-			require_once __DIR__ . '/../../../core/register_command.php';
114
+			require_once __DIR__.'/../../../core/register_command.php';
115 115
 			if ($this->config->getSystemValueBool('installed', false)) {
116 116
 				if (\OCP\Util::needUpgrade()) {
117 117
 					throw new NeedsUpdateException();
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 						}
133 133
 						// load from register_command.php
134 134
 						\OC_App::registerAutoloading($app, $appPath);
135
-						$file = $appPath . '/appinfo/register_command.php';
135
+						$file = $appPath.'/appinfo/register_command.php';
136 136
 						if (file_exists($file)) {
137 137
 							try {
138 138
 								require $file;
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 			$errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
161 161
 			if (!empty($errors)) {
162 162
 				foreach ($errors as $error) {
163
-					$output->writeln((string)$error['error']);
164
-					$output->writeln((string)$error['hint']);
163
+					$output->writeln((string) $error['error']);
164
+					$output->writeln((string) $error['hint']);
165 165
 					$output->writeln('');
166 166
 				}
167 167
 				throw new \Exception("Environment not properly prepared.");
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 					try {
221 221
 						$c = new $command();
222 222
 					} catch (\ArgumentCountError $e2) {
223
-						throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e);
223
+						throw new \Exception("Failed to construct console command '$command': ".$e->getMessage(), 0, $e);
224 224
 					}
225 225
 				} else {
226 226
 					throw new \Exception("Console command '$command' is unknown and could not be loaded");
Please login to merge, or discard this patch.