1 | <?php |
||
43 | class Application extends \Symfony\Component\Console\Application { |
||
44 | |||
45 | /** @var Container */ |
||
46 | public static $container; |
||
47 | |||
48 | /** @var Container */ |
||
49 | protected $diContainer; |
||
50 | |||
51 | /** @var ConsoleLogger */ |
||
52 | protected $fallbackLogger; |
||
53 | |||
54 | |||
55 | /** @var array */ |
||
56 | protected $allowFailure = [ |
||
57 | 'upgrade:executeCoreUpgradeScripts', |
||
58 | 'upgrade:checkpoint', |
||
59 | 'upgrade:maintenanceMode', |
||
60 | 'help', |
||
61 | 'list' |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * Pass Pimple container into application |
||
66 | * @param Container $container |
||
67 | */ |
||
68 | public function setContainer(Container $container){ |
||
72 | |||
73 | /** |
||
74 | * Get Pimple container |
||
75 | * @return Container |
||
76 | */ |
||
77 | public function getContainer(){ |
||
80 | |||
81 | /** |
||
82 | * Get logger instance |
||
83 | * @return \Psr\Log\LoggerInterface |
||
84 | */ |
||
85 | public function getLogger(){ |
||
98 | |||
99 | /** |
||
100 | * Log exception with trace |
||
101 | * @param \Exception $e |
||
102 | */ |
||
103 | public function logException($e){ |
||
108 | |||
109 | /** |
||
110 | * Runs the current application. |
||
111 | * |
||
112 | * @param InputInterface $input An Input instance |
||
113 | * @param OutputInterface $output An Output instance |
||
114 | * @return int 0 if everything went fine, or an error code |
||
115 | * @throws \Exception |
||
116 | */ |
||
117 | public function doRun(InputInterface $input, OutputInterface $output){ |
||
154 | |||
155 | /** |
||
156 | * @param Command $command |
||
157 | * @param InputInterface $input |
||
158 | * @param OutputInterface $output |
||
159 | * @return int |
||
160 | * @throws \Exception |
||
161 | */ |
||
162 | protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output){ |
||
180 | |||
181 | /** |
||
182 | * @param string $baseDir |
||
183 | */ |
||
184 | protected function initLogger($baseDir){ |
||
197 | |||
198 | /** |
||
199 | * Check for ownCloud instance |
||
200 | * @throws \RuntimeException |
||
201 | */ |
||
202 | public function assertOwnCloudFound(){ |
||
203 | $container = $this->getContainer(); |
||
204 | /** @var Locator $locator */ |
||
205 | $locator = $container['utils.locator']; |
||
206 | $fsHelper = $container['utils.filesystemhelper']; |
||
207 | /** @var OccRunner $occRunner */ |
||
208 | $occRunner = $container['utils.occrunner']; |
||
209 | |||
210 | // has to be installed |
||
211 | $file = $locator->getPathToConfigFile(); |
||
212 | $this->assertFileExists($file, 'ownCloud in ' . dirname(dirname($file)) . ' is not installed.'); |
||
213 | |||
214 | // version.php should exist |
||
215 | $file = $locator->getPathToVersionFile(); |
||
216 | $this->assertFileExists($file, 'ownCloud is not found in ' . dirname($file)); |
||
217 | |||
218 | $status = $occRunner->runJson('status'); |
||
219 | if (!isset($status['installed']) || $status['installed'] != 'true'){ |
||
220 | throw new \RuntimeException('ownCloud in ' . dirname($file) . ' is not installed.'); |
||
221 | } |
||
222 | |||
223 | // datadir should exist |
||
224 | $dataDir = $locator->getDataDir(); |
||
225 | if (!$fsHelper->fileExists($dataDir)){ |
||
226 | throw new \RuntimeException('Datadirectory ' . $dataDir . ' does not exist.'); |
||
227 | } |
||
228 | |||
229 | // datadir should be writable |
||
230 | if (!$fsHelper->isWritable($dataDir)){ |
||
231 | throw new \RuntimeException('Datadirectory ' . $dataDir . ' is not writable.'); |
||
232 | } |
||
233 | |||
234 | // assert minimum version |
||
235 | $installedVersion = implode('.', $locator->getInstalledVersion()); |
||
236 | if (version_compare($installedVersion, '9.0.0', '<')){ |
||
237 | throw new \RuntimeException("Minimum ownCloud version 9.0.0 is required for the updater - $installedVersion was found in " . $locator->getOwnCloudRootPath()); |
||
238 | } |
||
239 | |||
240 | if (!$fsHelper->fileExists($locator->getUpdaterBaseDir())){ |
||
241 | $fsHelper->mkdir($locator->getUpdaterBaseDir()); |
||
242 | } |
||
243 | |||
244 | if (!$fsHelper->fileExists($locator->getDownloadBaseDir())){ |
||
245 | $fsHelper->mkdir($locator->getDownloadBaseDir()); |
||
246 | } |
||
247 | if (!$fsHelper->fileExists($locator->getCheckpointDir())){ |
||
248 | $fsHelper->mkdir($locator->getCheckpointDir()); |
||
249 | } |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * @param string $path |
||
254 | * @param string $message |
||
255 | */ |
||
256 | protected function assertFileExists($path, $message){ |
||
261 | } |
||
262 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: