Completed
Pull Request — master (#7490)
by Tobia
12:23
created
apps/files_external/lib/Command/Notify.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 			return 1;
121 121
 		}
122 122
 		if (!$storage instanceof INotifyStorage) {
123
-			$output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>');
123
+			$output->writeln('<error>Mount of type "'.$mount->getBackend()->getText().'" does not support active update notifications</error>');
124 124
 			return 1;
125 125
 		}
126 126
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$path = trim($input->getOption('path'), '/');
130 130
 		$notifyHandler = $storage->notify($path);
131 131
 		$this->selfTest($storage, $notifyHandler, $verbose, $output);
132
-		$notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) {
132
+		$notifyHandler->listen(function(IChange $change) use ($mount, $verbose, $output) {
133 133
 			if ($verbose) {
134 134
 				$this->logUpdate($change, $output);
135 135
 			}
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
 				return;
172 172
 		}
173 173
 
174
-		$text .= ' ' . $change->getPath();
174
+		$text .= ' '.$change->getPath();
175 175
 		if ($change instanceof IRenameChange) {
176
-			$text .= ' to ' . $change->getTargetPath();
176
+			$text .= ' to '.$change->getTargetPath();
177 177
 		}
178 178
 
179 179
 		$output->writeln($text);
Please login to merge, or discard this patch.
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -40,178 +40,178 @@
 block discarded – undo
40 40
 use Symfony\Component\Console\Output\OutputInterface;
41 41
 
42 42
 class Notify extends Base {
43
-	/** @var GlobalStoragesService */
44
-	private $globalService;
45
-	/** @var IDBConnection */
46
-	private $connection;
47
-	/** @var \OCP\DB\QueryBuilder\IQueryBuilder */
48
-	private $updateQuery;
49
-
50
-	function __construct(GlobalStoragesService $globalService, IDBConnection $connection) {
51
-		parent::__construct();
52
-		$this->globalService = $globalService;
53
-		$this->connection = $connection;
54
-		// the query builder doesn't really like subqueries with parameters
55
-		$this->updateQuery = $this->connection->prepare(
56
-			'UPDATE *PREFIX*filecache SET size = -1
43
+    /** @var GlobalStoragesService */
44
+    private $globalService;
45
+    /** @var IDBConnection */
46
+    private $connection;
47
+    /** @var \OCP\DB\QueryBuilder\IQueryBuilder */
48
+    private $updateQuery;
49
+
50
+    function __construct(GlobalStoragesService $globalService, IDBConnection $connection) {
51
+        parent::__construct();
52
+        $this->globalService = $globalService;
53
+        $this->connection = $connection;
54
+        // the query builder doesn't really like subqueries with parameters
55
+        $this->updateQuery = $this->connection->prepare(
56
+            'UPDATE *PREFIX*filecache SET size = -1
57 57
 			WHERE `path` = ?
58 58
 			AND `storage` IN (SELECT storage_id FROM *PREFIX*mounts WHERE mount_id = ?)'
59
-		);
60
-	}
61
-
62
-	protected function configure() {
63
-		$this
64
-			->setName('files_external:notify')
65
-			->setDescription('Listen for active update notifications for a configured external mount')
66
-			->addArgument(
67
-				'mount_id',
68
-				InputArgument::REQUIRED,
69
-				'the mount id of the mount to listen to'
70
-			)->addOption(
71
-				'user',
72
-				'u',
73
-				InputOption::VALUE_REQUIRED,
74
-				'The username for the remote mount (required only for some mount configuration that don\'t store credentials)'
75
-			)->addOption(
76
-				'password',
77
-				'p',
78
-				InputOption::VALUE_REQUIRED,
79
-				'The password for the remote mount (required only for some mount configuration that don\'t store credentials)'
80
-			)->addOption(
81
-				'path',
82
-				'',
83
-				InputOption::VALUE_REQUIRED,
84
-				'The directory in the storage to listen for updates in',
85
-				'/'
86
-			);
87
-		parent::configure();
88
-	}
89
-
90
-	protected function execute(InputInterface $input, OutputInterface $output) {
91
-		$mount = $this->globalService->getStorage($input->getArgument('mount_id'));
92
-		if (is_null($mount)) {
93
-			$output->writeln('<error>Mount not found</error>');
94
-			return 1;
95
-		}
96
-		$noAuth = false;
97
-		try {
98
-			$authBackend = $mount->getAuthMechanism();
99
-			$authBackend->manipulateStorageConfig($mount);
100
-		} catch (InsufficientDataForMeaningfulAnswerException $e) {
101
-			$noAuth = true;
102
-		} catch (StorageNotAvailableException $e) {
103
-			$noAuth = true;
104
-		}
105
-
106
-		if ($input->getOption('user')) {
107
-			$mount->setBackendOption('user', $input->getOption('user'));
108
-		}
109
-		if ($input->getOption('password')) {
110
-			$mount->setBackendOption('password', $input->getOption('password'));
111
-		}
112
-
113
-		try {
114
-			$storage = $this->createStorage($mount);
115
-		} catch (\Exception $e) {
116
-			$output->writeln('<error>Error while trying to create storage</error>');
117
-			if ($noAuth) {
118
-				$output->writeln('<error>Username and/or password required</error>');
119
-			}
120
-			return 1;
121
-		}
122
-		if (!$storage instanceof INotifyStorage) {
123
-			$output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>');
124
-			return 1;
125
-		}
126
-
127
-		$verbose = $input->getOption('verbose');
128
-
129
-		$path = trim($input->getOption('path'), '/');
130
-		$notifyHandler = $storage->notify($path);
131
-		$this->selfTest($storage, $notifyHandler, $verbose, $output);
132
-		$notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) {
133
-			if ($verbose) {
134
-				$this->logUpdate($change, $output);
135
-			}
136
-			if ($change instanceof IRenameChange) {
137
-				$this->markParentAsOutdated($mount->getId(), $change->getTargetPath());
138
-			}
139
-			$this->markParentAsOutdated($mount->getId(), $change->getPath());
140
-		});
141
-	}
142
-
143
-	private function createStorage(StorageConfig $mount) {
144
-		$class = $mount->getBackend()->getStorageClass();
145
-		return new $class($mount->getBackendOptions());
146
-	}
147
-
148
-	private function markParentAsOutdated($mountId, $path) {
149
-		$parent = dirname($path);
150
-		if ($parent === '.') {
151
-			$parent = '';
152
-		}
153
-		$this->updateQuery->execute([$parent, $mountId]);
154
-	}
155
-
156
-	private function logUpdate(IChange $change, OutputInterface $output) {
157
-		switch ($change->getType()) {
158
-			case INotifyStorage::NOTIFY_ADDED:
159
-				$text = 'added';
160
-				break;
161
-			case INotifyStorage::NOTIFY_MODIFIED:
162
-				$text = 'modified';
163
-				break;
164
-			case INotifyStorage::NOTIFY_REMOVED:
165
-				$text = 'removed';
166
-				break;
167
-			case INotifyStorage::NOTIFY_RENAMED:
168
-				$text = 'renamed';
169
-				break;
170
-			default:
171
-				return;
172
-		}
173
-
174
-		$text .= ' ' . $change->getPath();
175
-		if ($change instanceof IRenameChange) {
176
-			$text .= ' to ' . $change->getTargetPath();
177
-		}
178
-
179
-		$output->writeln($text);
180
-	}
181
-
182
-	private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) {
183
-		usleep(100 * 1000); //give time for the notify to start
184
-		$storage->file_put_contents('/.nc_test_file.txt', 'test content');
185
-		$storage->mkdir('/.nc_test_folder');
186
-		$storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content');
187
-
188
-		usleep(100 * 1000); //time for all changes to be processed
189
-		$changes = $notifyHandler->getChanges();
190
-
191
-		$storage->unlink('/.nc_test_file.txt');
192
-		$storage->unlink('/.nc_test_folder/subfile.txt');
193
-		$storage->rmdir('/.nc_test_folder');
194
-
195
-		usleep(100 * 1000); //time for all changes to be processed
196
-		$notifyHandler->getChanges(); // flush
197
-
198
-		$foundRootChange = false;
199
-		$foundSubfolderChange = false;
200
-
201
-		foreach ($changes as $change) {
202
-			if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') {
203
-				$foundRootChange = true;
204
-			} else if ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') {
205
-				$foundSubfolderChange = true;
206
-			}
207
-		}
208
-
209
-		if ($foundRootChange && $foundSubfolderChange && $verbose) {
210
-			$output->writeln('<info>Self-test successful</info>');
211
-		} else if ($foundRootChange && !$foundSubfolderChange) {
212
-			$output->writeln('<error>Error while running self-test, change is subfolder not detected</error>');
213
-		} else if (!$foundRootChange) {
214
-			$output->writeln('<error>Error while running self-test, no changes detected</error>');
215
-		}
216
-	}
59
+        );
60
+    }
61
+
62
+    protected function configure() {
63
+        $this
64
+            ->setName('files_external:notify')
65
+            ->setDescription('Listen for active update notifications for a configured external mount')
66
+            ->addArgument(
67
+                'mount_id',
68
+                InputArgument::REQUIRED,
69
+                'the mount id of the mount to listen to'
70
+            )->addOption(
71
+                'user',
72
+                'u',
73
+                InputOption::VALUE_REQUIRED,
74
+                'The username for the remote mount (required only for some mount configuration that don\'t store credentials)'
75
+            )->addOption(
76
+                'password',
77
+                'p',
78
+                InputOption::VALUE_REQUIRED,
79
+                'The password for the remote mount (required only for some mount configuration that don\'t store credentials)'
80
+            )->addOption(
81
+                'path',
82
+                '',
83
+                InputOption::VALUE_REQUIRED,
84
+                'The directory in the storage to listen for updates in',
85
+                '/'
86
+            );
87
+        parent::configure();
88
+    }
89
+
90
+    protected function execute(InputInterface $input, OutputInterface $output) {
91
+        $mount = $this->globalService->getStorage($input->getArgument('mount_id'));
92
+        if (is_null($mount)) {
93
+            $output->writeln('<error>Mount not found</error>');
94
+            return 1;
95
+        }
96
+        $noAuth = false;
97
+        try {
98
+            $authBackend = $mount->getAuthMechanism();
99
+            $authBackend->manipulateStorageConfig($mount);
100
+        } catch (InsufficientDataForMeaningfulAnswerException $e) {
101
+            $noAuth = true;
102
+        } catch (StorageNotAvailableException $e) {
103
+            $noAuth = true;
104
+        }
105
+
106
+        if ($input->getOption('user')) {
107
+            $mount->setBackendOption('user', $input->getOption('user'));
108
+        }
109
+        if ($input->getOption('password')) {
110
+            $mount->setBackendOption('password', $input->getOption('password'));
111
+        }
112
+
113
+        try {
114
+            $storage = $this->createStorage($mount);
115
+        } catch (\Exception $e) {
116
+            $output->writeln('<error>Error while trying to create storage</error>');
117
+            if ($noAuth) {
118
+                $output->writeln('<error>Username and/or password required</error>');
119
+            }
120
+            return 1;
121
+        }
122
+        if (!$storage instanceof INotifyStorage) {
123
+            $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>');
124
+            return 1;
125
+        }
126
+
127
+        $verbose = $input->getOption('verbose');
128
+
129
+        $path = trim($input->getOption('path'), '/');
130
+        $notifyHandler = $storage->notify($path);
131
+        $this->selfTest($storage, $notifyHandler, $verbose, $output);
132
+        $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) {
133
+            if ($verbose) {
134
+                $this->logUpdate($change, $output);
135
+            }
136
+            if ($change instanceof IRenameChange) {
137
+                $this->markParentAsOutdated($mount->getId(), $change->getTargetPath());
138
+            }
139
+            $this->markParentAsOutdated($mount->getId(), $change->getPath());
140
+        });
141
+    }
142
+
143
+    private function createStorage(StorageConfig $mount) {
144
+        $class = $mount->getBackend()->getStorageClass();
145
+        return new $class($mount->getBackendOptions());
146
+    }
147
+
148
+    private function markParentAsOutdated($mountId, $path) {
149
+        $parent = dirname($path);
150
+        if ($parent === '.') {
151
+            $parent = '';
152
+        }
153
+        $this->updateQuery->execute([$parent, $mountId]);
154
+    }
155
+
156
+    private function logUpdate(IChange $change, OutputInterface $output) {
157
+        switch ($change->getType()) {
158
+            case INotifyStorage::NOTIFY_ADDED:
159
+                $text = 'added';
160
+                break;
161
+            case INotifyStorage::NOTIFY_MODIFIED:
162
+                $text = 'modified';
163
+                break;
164
+            case INotifyStorage::NOTIFY_REMOVED:
165
+                $text = 'removed';
166
+                break;
167
+            case INotifyStorage::NOTIFY_RENAMED:
168
+                $text = 'renamed';
169
+                break;
170
+            default:
171
+                return;
172
+        }
173
+
174
+        $text .= ' ' . $change->getPath();
175
+        if ($change instanceof IRenameChange) {
176
+            $text .= ' to ' . $change->getTargetPath();
177
+        }
178
+
179
+        $output->writeln($text);
180
+    }
181
+
182
+    private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) {
183
+        usleep(100 * 1000); //give time for the notify to start
184
+        $storage->file_put_contents('/.nc_test_file.txt', 'test content');
185
+        $storage->mkdir('/.nc_test_folder');
186
+        $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content');
187
+
188
+        usleep(100 * 1000); //time for all changes to be processed
189
+        $changes = $notifyHandler->getChanges();
190
+
191
+        $storage->unlink('/.nc_test_file.txt');
192
+        $storage->unlink('/.nc_test_folder/subfile.txt');
193
+        $storage->rmdir('/.nc_test_folder');
194
+
195
+        usleep(100 * 1000); //time for all changes to be processed
196
+        $notifyHandler->getChanges(); // flush
197
+
198
+        $foundRootChange = false;
199
+        $foundSubfolderChange = false;
200
+
201
+        foreach ($changes as $change) {
202
+            if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') {
203
+                $foundRootChange = true;
204
+            } else if ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') {
205
+                $foundSubfolderChange = true;
206
+            }
207
+        }
208
+
209
+        if ($foundRootChange && $foundSubfolderChange && $verbose) {
210
+            $output->writeln('<info>Self-test successful</info>');
211
+        } else if ($foundRootChange && !$foundSubfolderChange) {
212
+            $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>');
213
+        } else if (!$foundRootChange) {
214
+            $output->writeln('<error>Error while running self-test, no changes detected</error>');
215
+        }
216
+    }
217 217
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Backends.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -32,91 +32,91 @@
 block discarded – undo
32 32
 use Symfony\Component\Console\Output\OutputInterface;
33 33
 
34 34
 class Backends extends Base {
35
-	/** @var BackendService */
36
-	private $backendService;
35
+    /** @var BackendService */
36
+    private $backendService;
37 37
 
38
-	function __construct(BackendService $backendService
39
-	) {
40
-		parent::__construct();
38
+    function __construct(BackendService $backendService
39
+    ) {
40
+        parent::__construct();
41 41
 
42
-		$this->backendService = $backendService;
43
-	}
42
+        $this->backendService = $backendService;
43
+    }
44 44
 
45
-	protected function configure() {
46
-		$this
47
-			->setName('files_external:backends')
48
-			->setDescription('Show available authentication and storage backends')
49
-			->addArgument(
50
-				'type',
51
-				InputArgument::OPTIONAL,
52
-				'only show backends of a certain type. Possible values are "authentication" or "storage"'
53
-			)->addArgument(
54
-				'backend',
55
-				InputArgument::OPTIONAL,
56
-				'only show information of a specific backend'
57
-			);
58
-		parent::configure();
59
-	}
45
+    protected function configure() {
46
+        $this
47
+            ->setName('files_external:backends')
48
+            ->setDescription('Show available authentication and storage backends')
49
+            ->addArgument(
50
+                'type',
51
+                InputArgument::OPTIONAL,
52
+                'only show backends of a certain type. Possible values are "authentication" or "storage"'
53
+            )->addArgument(
54
+                'backend',
55
+                InputArgument::OPTIONAL,
56
+                'only show information of a specific backend'
57
+            );
58
+        parent::configure();
59
+    }
60 60
 
61
-	protected function execute(InputInterface $input, OutputInterface $output) {
62
-		$authBackends = $this->backendService->getAuthMechanisms();
63
-		$storageBackends = $this->backendService->getBackends();
61
+    protected function execute(InputInterface $input, OutputInterface $output) {
62
+        $authBackends = $this->backendService->getAuthMechanisms();
63
+        $storageBackends = $this->backendService->getBackends();
64 64
 
65
-		$data = [
66
-			'authentication' => array_map([$this, 'serializeAuthBackend'], $authBackends),
67
-			'storage' => array_map([$this, 'serializeAuthBackend'], $storageBackends)
68
-		];
65
+        $data = [
66
+            'authentication' => array_map([$this, 'serializeAuthBackend'], $authBackends),
67
+            'storage' => array_map([$this, 'serializeAuthBackend'], $storageBackends)
68
+        ];
69 69
 
70
-		$type = $input->getArgument('type');
71
-		$backend = $input->getArgument('backend');
72
-		if ($type) {
73
-			if (!isset($data[$type])) {
74
-				$output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>');
75
-				return 1;
76
-			}
77
-			$data = $data[$type];
70
+        $type = $input->getArgument('type');
71
+        $backend = $input->getArgument('backend');
72
+        if ($type) {
73
+            if (!isset($data[$type])) {
74
+                $output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>');
75
+                return 1;
76
+            }
77
+            $data = $data[$type];
78 78
 
79
-			if ($backend) {
80
-				if (!isset($data[$backend])) {
81
-					$output->writeln('<error>Unknown backend "' . $backend . '" of type  "' . $type . '"</error>');
82
-					return 1;
83
-				}
84
-				$data = $data[$backend];
85
-			}
86
-		}
79
+            if ($backend) {
80
+                if (!isset($data[$backend])) {
81
+                    $output->writeln('<error>Unknown backend "' . $backend . '" of type  "' . $type . '"</error>');
82
+                    return 1;
83
+                }
84
+                $data = $data[$backend];
85
+            }
86
+        }
87 87
 
88
-		$this->writeArrayInOutputFormat($input, $output, $data);
89
-	}
88
+        $this->writeArrayInOutputFormat($input, $output, $data);
89
+    }
90 90
 
91
-	private function serializeAuthBackend(\JsonSerializable $backend) {
92
-		$data = $backend->jsonSerialize();
93
-		$result = [
94
-			'name' => $data['name'],
95
-			'identifier' => $data['identifier'],
96
-			'configuration' => $this->formatConfiguration($data['configuration'])
97
-		];
98
-		if ($backend instanceof Backend) {
99
-			$result['storage_class'] = $backend->getStorageClass();
100
-			$authBackends = $this->backendService->getAuthMechanismsByScheme(array_keys($backend->getAuthSchemes()));
101
-			$result['supported_authentication_backends'] = array_keys($authBackends);
102
-			$authConfig = array_map(function (AuthMechanism $auth) {
103
-				return $this->serializeAuthBackend($auth)['configuration'];
104
-			}, $authBackends);
105
-			$result['authentication_configuration'] = array_combine(array_keys($authBackends), $authConfig);
106
-		}
107
-		return $result;
108
-	}
91
+    private function serializeAuthBackend(\JsonSerializable $backend) {
92
+        $data = $backend->jsonSerialize();
93
+        $result = [
94
+            'name' => $data['name'],
95
+            'identifier' => $data['identifier'],
96
+            'configuration' => $this->formatConfiguration($data['configuration'])
97
+        ];
98
+        if ($backend instanceof Backend) {
99
+            $result['storage_class'] = $backend->getStorageClass();
100
+            $authBackends = $this->backendService->getAuthMechanismsByScheme(array_keys($backend->getAuthSchemes()));
101
+            $result['supported_authentication_backends'] = array_keys($authBackends);
102
+            $authConfig = array_map(function (AuthMechanism $auth) {
103
+                return $this->serializeAuthBackend($auth)['configuration'];
104
+            }, $authBackends);
105
+            $result['authentication_configuration'] = array_combine(array_keys($authBackends), $authConfig);
106
+        }
107
+        return $result;
108
+    }
109 109
 
110
-	/**
111
-	 * @param DefinitionParameter[] $parameters
112
-	 * @return string[]
113
-	 */
114
-	private function formatConfiguration(array $parameters) {
115
-		$configuration = array_filter($parameters, function (DefinitionParameter $parameter) {
116
-			return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN;
117
-		});
118
-		return array_map(function (DefinitionParameter $parameter) {
119
-			return $parameter->getTypeName();
120
-		}, $configuration);
121
-	}
110
+    /**
111
+     * @param DefinitionParameter[] $parameters
112
+     * @return string[]
113
+     */
114
+    private function formatConfiguration(array $parameters) {
115
+        $configuration = array_filter($parameters, function (DefinitionParameter $parameter) {
116
+            return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN;
117
+        });
118
+        return array_map(function (DefinitionParameter $parameter) {
119
+            return $parameter->getTypeName();
120
+        }, $configuration);
121
+    }
122 122
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 		$backend = $input->getArgument('backend');
72 72
 		if ($type) {
73 73
 			if (!isset($data[$type])) {
74
-				$output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>');
74
+				$output->writeln('<error>Invalid type "'.$type.'". Possible values are "authentication" or "storage"</error>');
75 75
 				return 1;
76 76
 			}
77 77
 			$data = $data[$type];
78 78
 
79 79
 			if ($backend) {
80 80
 				if (!isset($data[$backend])) {
81
-					$output->writeln('<error>Unknown backend "' . $backend . '" of type  "' . $type . '"</error>');
81
+					$output->writeln('<error>Unknown backend "'.$backend.'" of type  "'.$type.'"</error>');
82 82
 					return 1;
83 83
 				}
84 84
 				$data = $data[$backend];
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 			$result['storage_class'] = $backend->getStorageClass();
100 100
 			$authBackends = $this->backendService->getAuthMechanismsByScheme(array_keys($backend->getAuthSchemes()));
101 101
 			$result['supported_authentication_backends'] = array_keys($authBackends);
102
-			$authConfig = array_map(function (AuthMechanism $auth) {
102
+			$authConfig = array_map(function(AuthMechanism $auth) {
103 103
 				return $this->serializeAuthBackend($auth)['configuration'];
104 104
 			}, $authBackends);
105 105
 			$result['authentication_configuration'] = array_combine(array_keys($authBackends), $authConfig);
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
 	 * @return string[]
113 113
 	 */
114 114
 	private function formatConfiguration(array $parameters) {
115
-		$configuration = array_filter($parameters, function (DefinitionParameter $parameter) {
115
+		$configuration = array_filter($parameters, function(DefinitionParameter $parameter) {
116 116
 			return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN;
117 117
 		});
118
-		return array_map(function (DefinitionParameter $parameter) {
118
+		return array_map(function(DefinitionParameter $parameter) {
119 119
 			return $parameter->getTypeName();
120 120
 		}, $configuration);
121 121
 	}
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Section.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -28,55 +28,55 @@
 block discarded – undo
28 28
 use OCP\Settings\IIconSection;
29 29
 
30 30
 class Section implements IIconSection {
31
-	/** @var IL10N */
32
-	private $l;
33
-	/** @var IURLGenerator */
34
-	private $url;
31
+    /** @var IL10N */
32
+    private $l;
33
+    /** @var IURLGenerator */
34
+    private $url;
35 35
 
36
-	/**
37
-	 * @param IURLGenerator $url
38
-	 * @param IL10N $l
39
-	 */
40
-	public function __construct(IURLGenerator $url, IL10N $l) {
41
-		$this->url = $url;
42
-		$this->l = $l;
43
-	}
36
+    /**
37
+     * @param IURLGenerator $url
38
+     * @param IL10N $l
39
+     */
40
+    public function __construct(IURLGenerator $url, IL10N $l) {
41
+        $this->url = $url;
42
+        $this->l = $l;
43
+    }
44 44
 
45
-	/**
46
-	 * returns the ID of the section. It is supposed to be a lower case string,
47
-	 * e.g. 'ldap'
48
-	 *
49
-	 * @returns string
50
-	 */
51
-	public function getID() {
52
-		return 'externalstorages';
53
-	}
45
+    /**
46
+     * returns the ID of the section. It is supposed to be a lower case string,
47
+     * e.g. 'ldap'
48
+     *
49
+     * @returns string
50
+     */
51
+    public function getID() {
52
+        return 'externalstorages';
53
+    }
54 54
 
55
-	/**
56
-	 * returns the translated name as it should be displayed, e.g. 'LDAP / AD
57
-	 * integration'. Use the L10N service to translate it.
58
-	 *
59
-	 * @return string
60
-	 */
61
-	public function getName() {
62
-		return $this->l->t('External storages');
63
-	}
55
+    /**
56
+     * returns the translated name as it should be displayed, e.g. 'LDAP / AD
57
+     * integration'. Use the L10N service to translate it.
58
+     *
59
+     * @return string
60
+     */
61
+    public function getName() {
62
+        return $this->l->t('External storages');
63
+    }
64 64
 
65
-	/**
66
-	 * @return int whether the form should be rather on the top or bottom of
67
-	 * the settings navigation. The sections are arranged in ascending order of
68
-	 * the priority values. It is required to return a value between 0 and 99.
69
-	 *
70
-	 * E.g.: 70
71
-	 */
72
-	public function getPriority() {
73
-		return 10;
74
-	}
65
+    /**
66
+     * @return int whether the form should be rather on the top or bottom of
67
+     * the settings navigation. The sections are arranged in ascending order of
68
+     * the priority values. It is required to return a value between 0 and 99.
69
+     *
70
+     * E.g.: 70
71
+     */
72
+    public function getPriority() {
73
+        return 10;
74
+    }
75 75
 
76
-	/**
77
-	 * {@inheritdoc}
78
-	 */
79
-	public function getIcon() {
80
-		return $this->url->imagePath('files_external', 'app-dark.svg');
81
-	}
76
+    /**
77
+     * {@inheritdoc}
78
+     */
79
+    public function getIcon() {
80
+        return $this->url->imagePath('files_external', 'app-dark.svg');
81
+    }
82 82
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Admin.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -32,65 +32,65 @@
 block discarded – undo
32 32
 
33 33
 class Admin implements ISettings {
34 34
 
35
-	/** @var IManager */
36
-	private $encryptionManager;
35
+    /** @var IManager */
36
+    private $encryptionManager;
37 37
 
38
-	/** @var GlobalStoragesService */
39
-	private $globalStoragesService;
38
+    /** @var GlobalStoragesService */
39
+    private $globalStoragesService;
40 40
 
41
-	/** @var BackendService */
42
-	private $backendService;
41
+    /** @var BackendService */
42
+    private $backendService;
43 43
 
44
-	/** @var GlobalAuth	 */
45
-	private $globalAuth;
44
+    /** @var GlobalAuth	 */
45
+    private $globalAuth;
46 46
 
47
-	public function __construct(
48
-		IManager $encryptionManager,
49
-		GlobalStoragesService $globalStoragesService,
50
-		BackendService $backendService,
51
-		GlobalAuth $globalAuth
52
-	) {
53
-		$this->encryptionManager = $encryptionManager;
54
-		$this->globalStoragesService = $globalStoragesService;
55
-		$this->backendService = $backendService;
56
-		$this->globalAuth = $globalAuth;
57
-	}
47
+    public function __construct(
48
+        IManager $encryptionManager,
49
+        GlobalStoragesService $globalStoragesService,
50
+        BackendService $backendService,
51
+        GlobalAuth $globalAuth
52
+    ) {
53
+        $this->encryptionManager = $encryptionManager;
54
+        $this->globalStoragesService = $globalStoragesService;
55
+        $this->backendService = $backendService;
56
+        $this->globalAuth = $globalAuth;
57
+    }
58 58
 
59
-	/**
60
-	 * @return TemplateResponse
61
-	 */
62
-	public function getForm() {
63
-		$parameters = [
64
-			'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
65
-			'visibilityType'       => BackendService::VISIBILITY_ADMIN,
66
-			'storages'             => $this->globalStoragesService->getStorages(),
67
-			'backends'             => $this->backendService->getAvailableBackends(),
68
-			'authMechanisms'       => $this->backendService->getAuthMechanisms(),
69
-			'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
70
-			'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
71
-			'globalCredentials'    => $this->globalAuth->getAuth(''),
72
-			'globalCredentialsUid' => '',
73
-		];
59
+    /**
60
+     * @return TemplateResponse
61
+     */
62
+    public function getForm() {
63
+        $parameters = [
64
+            'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
65
+            'visibilityType'       => BackendService::VISIBILITY_ADMIN,
66
+            'storages'             => $this->globalStoragesService->getStorages(),
67
+            'backends'             => $this->backendService->getAvailableBackends(),
68
+            'authMechanisms'       => $this->backendService->getAuthMechanisms(),
69
+            'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
70
+            'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
71
+            'globalCredentials'    => $this->globalAuth->getAuth(''),
72
+            'globalCredentialsUid' => '',
73
+        ];
74 74
 
75
-		return new TemplateResponse('files_external', 'settings', $parameters, '');
76
-	}
75
+        return new TemplateResponse('files_external', 'settings', $parameters, '');
76
+    }
77 77
 
78
-	/**
79
-	 * @return string the section ID, e.g. 'sharing'
80
-	 */
81
-	public function getSection() {
82
-		return 'externalstorages';
83
-	}
78
+    /**
79
+     * @return string the section ID, e.g. 'sharing'
80
+     */
81
+    public function getSection() {
82
+        return 'externalstorages';
83
+    }
84 84
 
85
-	/**
86
-	 * @return int whether the form should be rather on the top or bottom of
87
-	 * the admin section. The forms are arranged in ascending order of the
88
-	 * priority values. It is required to return a value between 0 and 100.
89
-	 *
90
-	 * E.g.: 70
91
-	 */
92
-	public function getPriority() {
93
-		return 40;
94
-	}
85
+    /**
86
+     * @return int whether the form should be rather on the top or bottom of
87
+     * the admin section. The forms are arranged in ascending order of the
88
+     * priority values. It is required to return a value between 0 and 100.
89
+     *
90
+     * E.g.: 70
91
+     */
92
+    public function getPriority() {
93
+        return 40;
94
+    }
95 95
 
96 96
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -29,43 +29,43 @@
 block discarded – undo
29 29
  */
30 30
 trait LegacyDependencyCheckPolyfill {
31 31
 
32
-	/**
33
-	 * @return string
34
-	 */
35
-	abstract public function getStorageClass();
32
+    /**
33
+     * @return string
34
+     */
35
+    abstract public function getStorageClass();
36 36
 
37
-	/**
38
-	 * Check if object is valid for use
39
-	 *
40
-	 * @return MissingDependency[] Unsatisfied dependencies
41
-	 */
42
-	public function checkDependencies() {
43
-		$ret = [];
37
+    /**
38
+     * Check if object is valid for use
39
+     *
40
+     * @return MissingDependency[] Unsatisfied dependencies
41
+     */
42
+    public function checkDependencies() {
43
+        $ret = [];
44 44
 
45
-		$result = call_user_func([$this->getStorageClass(), 'checkDependencies']);
46
-		if ($result !== true) {
47
-			if (!is_array($result)) {
48
-				$result = [$result];
49
-			}
50
-			foreach ($result as $key => $value) {
51
-				if (!($value instanceof MissingDependency)) {
52
-					$module = null;
53
-					$message = null;
54
-					if (is_numeric($key)) {
55
-						$module = $value;
56
-					} else {
57
-						$module = $key;
58
-						$message = $value;
59
-					}
60
-					$value = new MissingDependency($module, $this);
61
-					$value->setMessage($message);
62
-				}
63
-				$ret[] = $value;
64
-			}
65
-		}
45
+        $result = call_user_func([$this->getStorageClass(), 'checkDependencies']);
46
+        if ($result !== true) {
47
+            if (!is_array($result)) {
48
+                $result = [$result];
49
+            }
50
+            foreach ($result as $key => $value) {
51
+                if (!($value instanceof MissingDependency)) {
52
+                    $module = null;
53
+                    $message = null;
54
+                    if (is_numeric($key)) {
55
+                        $module = $value;
56
+                    } else {
57
+                        $module = $key;
58
+                        $message = $value;
59
+                    }
60
+                    $value = new MissingDependency($module, $this);
61
+                    $value->setMessage($message);
62
+                }
63
+                $ret[] = $value;
64
+            }
65
+        }
66 66
 
67
-		return $ret;
68
-	}
67
+        return $ret;
68
+    }
69 69
 
70 70
 }
71 71
 
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/VisibilityTrait.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -36,102 +36,102 @@
 block discarded – undo
36 36
  */
37 37
 trait VisibilityTrait {
38 38
 
39
-	/** @var int visibility */
40
-	protected $visibility = BackendService::VISIBILITY_DEFAULT;
41
-
42
-	/** @var int allowed visibilities */
43
-	protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT;
44
-
45
-	/**
46
-	 * @return int
47
-	 */
48
-	public function getVisibility() {
49
-		return $this->visibility;
50
-	}
51
-
52
-	/**
53
-	 * Check if the backend is visible for a user type
54
-	 *
55
-	 * @param int $visibility
56
-	 * @return bool
57
-	 */
58
-	public function isVisibleFor($visibility) {
59
-		if ($this->visibility & $visibility) {
60
-			return true;
61
-		}
62
-		return false;
63
-	}
64
-
65
-	/**
66
-	 * @param int $visibility
67
-	 * @return self
68
-	 */
69
-	public function setVisibility($visibility) {
70
-		$this->visibility = $visibility;
71
-		$this->allowedVisibility |= $visibility;
72
-		return $this;
73
-	}
74
-
75
-	/**
76
-	 * @param int $visibility
77
-	 * @return self
78
-	 */
79
-	public function addVisibility($visibility) {
80
-		return $this->setVisibility($this->visibility | $visibility);
81
-	}
82
-
83
-	/**
84
-	 * @param int $visibility
85
-	 * @return self
86
-	 */
87
-	public function removeVisibility($visibility) {
88
-		return $this->setVisibility($this->visibility & ~$visibility);
89
-	}
90
-
91
-	/**
92
-	 * @return int
93
-	 */
94
-	public function getAllowedVisibility() {
95
-		return $this->allowedVisibility;
96
-	}
97
-
98
-	/**
99
-	 * Check if the backend is allowed to be visible for a user type
100
-	 *
101
-	 * @param int $allowedVisibility
102
-	 * @return bool
103
-	 */
104
-	public function isAllowedVisibleFor($allowedVisibility) {
105
-		if ($this->allowedVisibility & $allowedVisibility) {
106
-			return true;
107
-		}
108
-		return false;
109
-	}
110
-
111
-	/**
112
-	 * @param int $allowedVisibility
113
-	 * @return self
114
-	 */
115
-	public function setAllowedVisibility($allowedVisibility) {
116
-		$this->allowedVisibility = $allowedVisibility;
117
-		$this->visibility &= $allowedVisibility;
118
-		return $this;
119
-	}
120
-
121
-	/**
122
-	 * @param int $allowedVisibility
123
-	 * @return self
124
-	 */
125
-	public function addAllowedVisibility($allowedVisibility) {
126
-		return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility);
127
-	}
128
-
129
-	/**
130
-	 * @param int $allowedVisibility
131
-	 * @return self
132
-	 */
133
-	public function removeAllowedVisibility($allowedVisibility) {
134
-		return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility);
135
-	}
39
+    /** @var int visibility */
40
+    protected $visibility = BackendService::VISIBILITY_DEFAULT;
41
+
42
+    /** @var int allowed visibilities */
43
+    protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT;
44
+
45
+    /**
46
+     * @return int
47
+     */
48
+    public function getVisibility() {
49
+        return $this->visibility;
50
+    }
51
+
52
+    /**
53
+     * Check if the backend is visible for a user type
54
+     *
55
+     * @param int $visibility
56
+     * @return bool
57
+     */
58
+    public function isVisibleFor($visibility) {
59
+        if ($this->visibility & $visibility) {
60
+            return true;
61
+        }
62
+        return false;
63
+    }
64
+
65
+    /**
66
+     * @param int $visibility
67
+     * @return self
68
+     */
69
+    public function setVisibility($visibility) {
70
+        $this->visibility = $visibility;
71
+        $this->allowedVisibility |= $visibility;
72
+        return $this;
73
+    }
74
+
75
+    /**
76
+     * @param int $visibility
77
+     * @return self
78
+     */
79
+    public function addVisibility($visibility) {
80
+        return $this->setVisibility($this->visibility | $visibility);
81
+    }
82
+
83
+    /**
84
+     * @param int $visibility
85
+     * @return self
86
+     */
87
+    public function removeVisibility($visibility) {
88
+        return $this->setVisibility($this->visibility & ~$visibility);
89
+    }
90
+
91
+    /**
92
+     * @return int
93
+     */
94
+    public function getAllowedVisibility() {
95
+        return $this->allowedVisibility;
96
+    }
97
+
98
+    /**
99
+     * Check if the backend is allowed to be visible for a user type
100
+     *
101
+     * @param int $allowedVisibility
102
+     * @return bool
103
+     */
104
+    public function isAllowedVisibleFor($allowedVisibility) {
105
+        if ($this->allowedVisibility & $allowedVisibility) {
106
+            return true;
107
+        }
108
+        return false;
109
+    }
110
+
111
+    /**
112
+     * @param int $allowedVisibility
113
+     * @return self
114
+     */
115
+    public function setAllowedVisibility($allowedVisibility) {
116
+        $this->allowedVisibility = $allowedVisibility;
117
+        $this->visibility &= $allowedVisibility;
118
+        return $this;
119
+    }
120
+
121
+    /**
122
+     * @param int $allowedVisibility
123
+     * @return self
124
+     */
125
+    public function addAllowedVisibility($allowedVisibility) {
126
+        return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility);
127
+    }
128
+
129
+    /**
130
+     * @param int $allowedVisibility
131
+     * @return self
132
+     */
133
+    public function removeAllowedVisibility($allowedVisibility) {
134
+        return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility);
135
+    }
136 136
 
137 137
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/DefinitionParameter.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -28,167 +28,167 @@
 block discarded – undo
28 28
  */
29 29
 class DefinitionParameter implements \JsonSerializable {
30 30
 
31
-	/** Value constants */
32
-	const VALUE_TEXT = 0;
33
-	const VALUE_BOOLEAN = 1;
34
-	const VALUE_PASSWORD = 2;
35
-	const VALUE_HIDDEN = 3;
36
-
37
-	/** Flag constants */
38
-	const FLAG_NONE = 0;
39
-	const FLAG_OPTIONAL = 1;
40
-	const FLAG_USER_PROVIDED = 2;
41
-
42
-	/** @var string name of parameter */
43
-	private $name;
44
-
45
-	/** @var string human-readable parameter text */
46
-	private $text;
47
-
48
-	/** @var int value type, see self::VALUE_* constants */
49
-	private $type = self::VALUE_TEXT;
50
-
51
-	/** @var int flags, see self::FLAG_* constants */
52
-	private $flags = self::FLAG_NONE;
53
-
54
-	/**
55
-	 * @param string $name
56
-	 * @param string $text
57
-	 */
58
-	public function __construct($name, $text) {
59
-		$this->name = $name;
60
-		$this->text = $text;
61
-	}
62
-
63
-	/**
64
-	 * @return string
65
-	 */
66
-	public function getName() {
67
-		return $this->name;
68
-	}
69
-
70
-	/**
71
-	 * @return string
72
-	 */
73
-	public function getText() {
74
-		return $this->text;
75
-	}
76
-
77
-	/**
78
-	 * Get value type
79
-	 *
80
-	 * @return int
81
-	 */
82
-	public function getType() {
83
-		return $this->type;
84
-	}
85
-
86
-	/**
87
-	 * Set value type
88
-	 *
89
-	 * @param int $type
90
-	 * @return self
91
-	 */
92
-	public function setType($type) {
93
-		$this->type = $type;
94
-		return $this;
95
-	}
96
-
97
-	/**
98
-	 * @return string
99
-	 */
100
-	public function getTypeName() {
101
-		switch ($this->type) {
102
-			case self::VALUE_BOOLEAN:
103
-				return 'boolean';
104
-			case self::VALUE_TEXT:
105
-				return 'text';
106
-			case self::VALUE_PASSWORD:
107
-				return 'password';
108
-			default:
109
-				return 'unknown';
110
-		}
111
-	}
112
-
113
-	/**
114
-	 * @return int
115
-	 */
116
-	public function getFlags() {
117
-		return $this->flags;
118
-	}
119
-
120
-	/**
121
-	 * @param int $flags
122
-	 * @return self
123
-	 */
124
-	public function setFlags($flags) {
125
-		$this->flags = $flags;
126
-		return $this;
127
-	}
128
-
129
-	/**
130
-	 * @param int $flag
131
-	 * @return self
132
-	 */
133
-	public function setFlag($flag) {
134
-		$this->flags |= $flag;
135
-		return $this;
136
-	}
137
-
138
-	/**
139
-	 * @param int $flag
140
-	 * @return bool
141
-	 */
142
-	public function isFlagSet($flag) {
143
-		return (bool)($this->flags & $flag);
144
-	}
145
-
146
-	/**
147
-	 * Serialize into JSON for client-side JS
148
-	 *
149
-	 * @return string
150
-	 */
151
-	public function jsonSerialize() {
152
-		return [
153
-			'value' => $this->getText(),
154
-			'flags' => $this->getFlags(),
155
-			'type' => $this->getType()
156
-		];
157
-	}
158
-
159
-	public function isOptional() {
160
-		return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED);
161
-	}
162
-
163
-	/**
164
-	 * Validate a parameter value against this
165
-	 * Convert type as necessary
166
-	 *
167
-	 * @param mixed $value Value to check
168
-	 * @return bool success
169
-	 */
170
-	public function validateValue(&$value) {
171
-		switch ($this->getType()) {
172
-			case self::VALUE_BOOLEAN:
173
-				if (!is_bool($value)) {
174
-					switch ($value) {
175
-						case 'true':
176
-							$value = true;
177
-							break;
178
-						case 'false':
179
-							$value = false;
180
-							break;
181
-						default:
182
-							return false;
183
-					}
184
-				}
185
-				break;
186
-			default:
187
-				if (!$value && !$this->isOptional()) {
188
-					return false;
189
-				}
190
-				break;
191
-		}
192
-		return true;
193
-	}
31
+    /** Value constants */
32
+    const VALUE_TEXT = 0;
33
+    const VALUE_BOOLEAN = 1;
34
+    const VALUE_PASSWORD = 2;
35
+    const VALUE_HIDDEN = 3;
36
+
37
+    /** Flag constants */
38
+    const FLAG_NONE = 0;
39
+    const FLAG_OPTIONAL = 1;
40
+    const FLAG_USER_PROVIDED = 2;
41
+
42
+    /** @var string name of parameter */
43
+    private $name;
44
+
45
+    /** @var string human-readable parameter text */
46
+    private $text;
47
+
48
+    /** @var int value type, see self::VALUE_* constants */
49
+    private $type = self::VALUE_TEXT;
50
+
51
+    /** @var int flags, see self::FLAG_* constants */
52
+    private $flags = self::FLAG_NONE;
53
+
54
+    /**
55
+     * @param string $name
56
+     * @param string $text
57
+     */
58
+    public function __construct($name, $text) {
59
+        $this->name = $name;
60
+        $this->text = $text;
61
+    }
62
+
63
+    /**
64
+     * @return string
65
+     */
66
+    public function getName() {
67
+        return $this->name;
68
+    }
69
+
70
+    /**
71
+     * @return string
72
+     */
73
+    public function getText() {
74
+        return $this->text;
75
+    }
76
+
77
+    /**
78
+     * Get value type
79
+     *
80
+     * @return int
81
+     */
82
+    public function getType() {
83
+        return $this->type;
84
+    }
85
+
86
+    /**
87
+     * Set value type
88
+     *
89
+     * @param int $type
90
+     * @return self
91
+     */
92
+    public function setType($type) {
93
+        $this->type = $type;
94
+        return $this;
95
+    }
96
+
97
+    /**
98
+     * @return string
99
+     */
100
+    public function getTypeName() {
101
+        switch ($this->type) {
102
+            case self::VALUE_BOOLEAN:
103
+                return 'boolean';
104
+            case self::VALUE_TEXT:
105
+                return 'text';
106
+            case self::VALUE_PASSWORD:
107
+                return 'password';
108
+            default:
109
+                return 'unknown';
110
+        }
111
+    }
112
+
113
+    /**
114
+     * @return int
115
+     */
116
+    public function getFlags() {
117
+        return $this->flags;
118
+    }
119
+
120
+    /**
121
+     * @param int $flags
122
+     * @return self
123
+     */
124
+    public function setFlags($flags) {
125
+        $this->flags = $flags;
126
+        return $this;
127
+    }
128
+
129
+    /**
130
+     * @param int $flag
131
+     * @return self
132
+     */
133
+    public function setFlag($flag) {
134
+        $this->flags |= $flag;
135
+        return $this;
136
+    }
137
+
138
+    /**
139
+     * @param int $flag
140
+     * @return bool
141
+     */
142
+    public function isFlagSet($flag) {
143
+        return (bool)($this->flags & $flag);
144
+    }
145
+
146
+    /**
147
+     * Serialize into JSON for client-side JS
148
+     *
149
+     * @return string
150
+     */
151
+    public function jsonSerialize() {
152
+        return [
153
+            'value' => $this->getText(),
154
+            'flags' => $this->getFlags(),
155
+            'type' => $this->getType()
156
+        ];
157
+    }
158
+
159
+    public function isOptional() {
160
+        return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED);
161
+    }
162
+
163
+    /**
164
+     * Validate a parameter value against this
165
+     * Convert type as necessary
166
+     *
167
+     * @param mixed $value Value to check
168
+     * @return bool success
169
+     */
170
+    public function validateValue(&$value) {
171
+        switch ($this->getType()) {
172
+            case self::VALUE_BOOLEAN:
173
+                if (!is_bool($value)) {
174
+                    switch ($value) {
175
+                        case 'true':
176
+                            $value = true;
177
+                            break;
178
+                        case 'false':
179
+                            $value = false;
180
+                            break;
181
+                        default:
182
+                            return false;
183
+                    }
184
+                }
185
+                break;
186
+            default:
187
+                if (!$value && !$this->isOptional()) {
188
+                    return false;
189
+                }
190
+                break;
191
+        }
192
+        return true;
193
+    }
194 194
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@
 block discarded – undo
140 140
 	 * @return bool
141 141
 	 */
142 142
 	public function isFlagSet($flag) {
143
-		return (bool)($this->flags & $flag);
143
+		return (bool) ($this->flags & $flag);
144 144
 	}
145 145
 
146 146
 	/**
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Auth/AmazonS3/AccessKey.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -31,18 +31,18 @@
 block discarded – undo
31 31
  */
32 32
 class AccessKey extends AuthMechanism {
33 33
 
34
-	const SCHEME_AMAZONS3_ACCESSKEY = 'amazons3_accesskey';
34
+    const SCHEME_AMAZONS3_ACCESSKEY = 'amazons3_accesskey';
35 35
 
36
-	public function __construct(IL10N $l) {
37
-		$this
38
-			->setIdentifier('amazons3::accesskey')
39
-			->setScheme(self::SCHEME_AMAZONS3_ACCESSKEY)
40
-			->setText($l->t('Access key'))
41
-			->addParameters([
42
-				(new DefinitionParameter('key', $l->t('Access key'))),
43
-				(new DefinitionParameter('secret', $l->t('Secret key')))
44
-					->setType(DefinitionParameter::VALUE_PASSWORD),
45
-			]);
46
-	}
36
+    public function __construct(IL10N $l) {
37
+        $this
38
+            ->setIdentifier('amazons3::accesskey')
39
+            ->setScheme(self::SCHEME_AMAZONS3_ACCESSKEY)
40
+            ->setText($l->t('Access key'))
41
+            ->addParameters([
42
+                (new DefinitionParameter('key', $l->t('Access key'))),
43
+                (new DefinitionParameter('secret', $l->t('Secret key')))
44
+                    ->setType(DefinitionParameter::VALUE_PASSWORD),
45
+            ]);
46
+    }
47 47
 
48 48
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -39,31 +39,31 @@
 block discarded – undo
39 39
  */
40 40
 class SessionCredentials extends AuthMechanism {
41 41
 
42
-	/** @var CredentialsStore */
43
-	private $credentialsStore;
42
+    /** @var CredentialsStore */
43
+    private $credentialsStore;
44 44
 
45
-	public function __construct(IL10N $l, CredentialsStore $credentialsStore) {
46
-		$this->credentialsStore = $credentialsStore;
45
+    public function __construct(IL10N $l, CredentialsStore $credentialsStore) {
46
+        $this->credentialsStore = $credentialsStore;
47 47
 
48
-		$this->setIdentifier('password::sessioncredentials')
49
-			->setScheme(self::SCHEME_PASSWORD)
50
-			->setText($l->t('Log-in credentials, save in session'))
51
-			->addParameters([]);
52
-	}
48
+        $this->setIdentifier('password::sessioncredentials')
49
+            ->setScheme(self::SCHEME_PASSWORD)
50
+            ->setText($l->t('Log-in credentials, save in session'))
51
+            ->addParameters([]);
52
+    }
53 53
 
54
-	public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
55
-		try {
56
-			$credentials = $this->credentialsStore->getLoginCredentials();
57
-		} catch (CredentialsUnavailableException $e) {
58
-			throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved');
59
-		}
54
+    public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
55
+        try {
56
+            $credentials = $this->credentialsStore->getLoginCredentials();
57
+        } catch (CredentialsUnavailableException $e) {
58
+            throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved');
59
+        }
60 60
 
61
-		$storage->setBackendOption('user', $credentials->getLoginName());
62
-		$storage->setBackendOption('password', $credentials->getPassword());
63
-	}
61
+        $storage->setBackendOption('user', $credentials->getLoginName());
62
+        $storage->setBackendOption('password', $credentials->getPassword());
63
+    }
64 64
 
65
-	public function wrapStorage(Storage $storage) {
66
-		return new SessionStorageWrapper(['storage' => $storage]);
67
-	}
65
+    public function wrapStorage(Storage $storage) {
66
+        return new SessionStorageWrapper(['storage' => $storage]);
67
+    }
68 68
 
69 69
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 			->addParameters([]);
52 52
 	}
53 53
 
54
-	public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
54
+	public function manipulateStorageConfig(StorageConfig & $storage, IUser $user = null) {
55 55
 		try {
56 56
 			$credentials = $this->credentialsStore->getLoginCredentials();
57 57
 		} catch (CredentialsUnavailableException $e) {
Please login to merge, or discard this patch.