Completed
Pull Request — master (#93)
by Janis
13:17
created
lib/Settings/Section.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 	 *
39 39
 	 */
40 40
 	public function getName() {
41
-		return $this->l->t ( 'OCR' );
41
+		return $this->l->t('OCR');
42 42
 	}
43 43
 	/**
44 44
 	 *
Please login to merge, or discard this patch.
lib/Controller/JobController.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 *        	$UserId
48 48
 	 */
49 49
 	public function __construct($AppName, IRequest $request, JobService $service, $UserId) {
50
-		parent::__construct ( $AppName, $request );
50
+		parent::__construct($AppName, $request);
51 51
 		$this->userId = $UserId;
52 52
 		$this->service = $service;
53 53
 	}
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @return DataResponse
63 63
 	 */
64 64
 	public function process($languages, $files) {
65
-		return $this->handleNotFound ( function () use ($languages, $files) {
66
-			return $this->service->process ( $languages, $files );
65
+		return $this->handleNotFound(function() use ($languages, $files) {
66
+			return $this->service->process($languages, $files);
67 67
 		} );
68 68
 	}
69 69
 	
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 * @return \OCP\AppFramework\Http\DataResponse
74 74
 	 */
75 75
 	public function getAllJobs() {
76
-		return $this->handleNotFound ( function () {
77
-			return $this->service->getAllJobsForUser ( $this->userId );
76
+		return $this->handleNotFound(function() {
77
+			return $this->service->getAllJobsForUser($this->userId);
78 78
 		} );
79 79
 	}
80 80
 	
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 	 * @return \OCP\AppFramework\Http\DataResponse
86 86
 	 */
87 87
 	public function deleteJob($id) {
88
-		return $this->handleNotFound ( function () use ($id) {
89
-			return $this->service->deleteJob ( $id, $this->userId );
88
+		return $this->handleNotFound(function() use ($id) {
89
+			return $this->service->deleteJob($id, $this->userId);
90 90
 		} );
91 91
 	}
92 92
 }
93 93
\ No newline at end of file
Please login to merge, or discard this patch.
appinfo/routes.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@
 block discarded – undo
18 18
  * it's instantiated in there
19 19
  */
20 20
 return [
21
-    'routes' => [
21
+	'routes' => [
22 22
 		['name' => 'Job#process', 'url' => '/', 'verb' => 'POST'],
23
-    	['name' => 'Job#deleteJob', 'url' => '/', 'verb' => 'DELETE'],
24
-    	['name' => 'Job#getAllJobs', 'url' => '/', 'verb' => 'GET'],
23
+		['name' => 'Job#deleteJob', 'url' => '/', 'verb' => 'DELETE'],
24
+		['name' => 'Job#getAllJobs', 'url' => '/', 'verb' => 'GET'],
25 25
 		['name' => 'Status#getStatus', 'url' => '/status', 'verb' => 'GET'],
26
-    	// settings
27
-    	['name' => 'AdminSettings#setLanguages', 'url' => '/admin/languages', 'verb' => 'POST'],
28
-    	['name' => 'AdminSettings#setRedis', 'url' => '/admin/redis', 'verb' => 'POST'],
29
-    	['name' => 'AdminSettings#getLanguages', 'url' => '/languages', 'verb' => 'GET'],
30
-    	['name' => 'AdminSettings#evaluateRedisSettings', 'url' => '/redis', 'verb' => 'GET']
31
-    ]
26
+		// settings
27
+		['name' => 'AdminSettings#setLanguages', 'url' => '/admin/languages', 'verb' => 'POST'],
28
+		['name' => 'AdminSettings#setRedis', 'url' => '/admin/redis', 'verb' => 'POST'],
29
+		['name' => 'AdminSettings#getLanguages', 'url' => '/languages', 'verb' => 'GET'],
30
+		['name' => 'AdminSettings#evaluateRedisSettings', 'url' => '/redis', 'verb' => 'GET']
31
+	]
32 32
 ];
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Controller/AdminSettingsController.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 * @param string $userId        	
41 41
 	 */
42 42
 	public function __construct($appName, IRequest $request, IL10N $l10n, AppConfigService $appConfig, $userId) {
43
-		parent::__construct ( $appName, $request );
43
+		parent::__construct($appName, $request);
44 44
 		$this->l10n = $l10n;
45 45
 		$this->appConfig = $appConfig;
46 46
 	}
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * @return DataResponse
52 52
 	 */
53 53
 	public function getLanguages() {
54
-		return $this->handleNotFound ( function () {
55
-			return [ 'languages' => $this->appConfig->getAppValue ( OcrConstants::LANGUAGES_CONFIG_KEY )];
54
+		return $this->handleNotFound(function() {
55
+			return ['languages' => $this->appConfig->getAppValue(OcrConstants::LANGUAGES_CONFIG_KEY)];
56 56
 		} );
57 57
 	}
58 58
 	
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @return DataResponse
63 63
 	 */
64 64
 	public function evaluateRedisSettings() {
65
-		return $this->handleNotFound ( function () {
66
-			return [ 'set' => $this->appConfig->evaluateRedisSettings ()];
65
+		return $this->handleNotFound(function() {
66
+			return ['set' => $this->appConfig->evaluateRedisSettings()];
67 67
 		} );
68 68
 	}
69 69
 	
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
 	 * @return DataResponse
75 75
 	 */
76 76
 	public function setLanguages($languages) {
77
-		return $this->handleNotFound ( function () use ($languages) {
77
+		return $this->handleNotFound(function() use ($languages) {
78 78
 			if ($languages !== null) {
79
-				$this->appConfig->setAppValue ( OcrConstants::LANGUAGES_CONFIG_KEY, $languages );
80
-				return $this->l10n->t ( 'Saved' );
79
+				$this->appConfig->setAppValue(OcrConstants::LANGUAGES_CONFIG_KEY, $languages);
80
+				return $this->l10n->t('Saved');
81 81
 			} else {
82
-				throw new NotFoundException ( $this->l10n->t ( 'The languages are not specified in the correct format.' ) );
82
+				throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.'));
83 83
 			}
84 84
 		} );
85 85
 	}
@@ -93,14 +93,14 @@  discard block
 block discarded – undo
93 93
 	 * @return DataResponse
94 94
 	 */
95 95
 	public function setRedis($redisHost, $redisPort, $redisDb) {
96
-		return $this->handleNotFound ( function () use ($redisHost, $redisPort, $redisDb) {
96
+		return $this->handleNotFound(function() use ($redisHost, $redisPort, $redisDb) {
97 97
 			if ($redisHost !== null && $redisPort !== null && $redisDb !== null) {
98
-				$this->appConfig->setAppValue ( OcrConstants::REDIS_CONFIG_KEY_HOST, $redisHost );
99
-				$this->appConfig->setAppValue ( OcrConstants::REDIS_CONFIG_KEY_PORT, $redisPort );
100
-				$this->appConfig->setAppValue ( OcrConstants::REDIS_CONFIG_KEY_DB, $redisDb );
101
-				return $this->l10n->t ( 'Saved' );
98
+				$this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_HOST, $redisHost);
99
+				$this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_PORT, $redisPort);
100
+				$this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_DB, $redisDb);
101
+				return $this->l10n->t('Saved');
102 102
 			} else {
103
-				throw new NotFoundException ( $this->l10n->t ( 'The Redis settings do not have the right format.' ) );
103
+				throw new NotFoundException($this->l10n->t('The Redis settings do not have the right format.'));
104 104
 			}
105 105
 		} );
106 106
 	}
Please login to merge, or discard this patch.
lib/Service/AppConfigService.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @return string
53 53
 	 */
54 54
 	public function getAppValue($key) {
55
-		return $this->config->getAppValue ( $this->appName, $key );
55
+		return $this->config->getAppValue($this->appName, $key);
56 56
 	}
57 57
 	/**
58 58
 	 * Evaluate if all redis related settings are set.
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public function evaluateRedisSettings() {
63 63
 		
64
-		if ($this->config->getAppValue ( $this->appName, OcrConstants::REDIS_CONFIG_KEY_HOST ) !== '' && $this->config->getAppValue ( $this->appName, OcrConstants::REDIS_CONFIG_KEY_PORT ) !== '' && $this->config->getAppValue ( $this->appName, OcrConstants::REDIS_CONFIG_KEY_DB ) !== '') {
64
+		if ($this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_HOST) !== '' && $this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_PORT) !== '' && $this->config->getAppValue($this->appName, OcrConstants::REDIS_CONFIG_KEY_DB) !== '') {
65 65
 			return true;
66 66
 		} else {
67 67
 			return false;
@@ -76,27 +76,27 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public function setAppValue($key, $value) {
78 78
 		if ($key === OcrConstants::LANGUAGES_CONFIG_KEY) {
79
-			if (! preg_match ( '/^(([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4});)*([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4})$/', $value )) {
80
-				throw new NotFoundException ( $this->l10n->t ( 'The languages are not specified in the correct format.' ) );
79
+			if (!preg_match('/^(([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4});)*([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4})$/', $value)) {
80
+				throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.'));
81 81
 			}
82 82
 		}
83 83
 		if ($key === OcrConstants::REDIS_CONFIG_KEY_HOST) {
84
-			if (! preg_match ( '/(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$)/', $value )) {
85
-				throw new NotFoundException ( $this->l10n->t ( 'The redis host is not specified in the correct format.' ) );
84
+			if (!preg_match('/(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$)/', $value)) {
85
+				throw new NotFoundException($this->l10n->t('The redis host is not specified in the correct format.'));
86 86
 			}
87 87
 		}
88 88
 		if ($key === OcrConstants::REDIS_CONFIG_KEY_PORT) {
89
-			$value = intval ( $value );
90
-			if (! ($value > 0 && $value < 65535)) {
91
-				throw new NotFoundException ( $this->l10n->t ( 'The redis port number is not specified in the correct format.' ) );
89
+			$value = intval($value);
90
+			if (!($value > 0 && $value < 65535)) {
91
+				throw new NotFoundException($this->l10n->t('The redis port number is not specified in the correct format.'));
92 92
 			}
93 93
 		}
94 94
 		if ($key === OcrConstants::REDIS_CONFIG_KEY_DB) {
95
-			$value = intval ( $value );
96
-			if (! ($value >= 0)) {
97
-				throw new NotFoundException ( $this->l10n->t ( 'The redis db is not specified in the correct format.' ) );
95
+			$value = intval($value);
96
+			if (!($value >= 0)) {
97
+				throw new NotFoundException($this->l10n->t('The redis db is not specified in the correct format.'));
98 98
 			}
99 99
 		}
100
-		return $this->config->setAppValue ( $this->appName, $key, $value );
100
+		return $this->config->setAppValue($this->appName, $key, $value);
101 101
 	}
102 102
 }
103 103
\ No newline at end of file
Please login to merge, or discard this patch.
lib/Db/OcrJob.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@
 block discarded – undo
99 99
 	 * @param string $originalFilename
100 100
 	 * @param string $errorLog
101 101
 	 */
102
-	public function __construct($status = null, $source = null, $target = null, $tempFile = null, $type = null, $userId = null, $errorDisplayed = null, $originalFilename = null, $errorLog= null) {
102
+	public function __construct($status = null, $source = null, $target = null, $tempFile = null, $type = null, $userId = null, $errorDisplayed = null, $originalFilename = null, $errorLog = null) {
103 103
 		$this->setStatus($status);
104 104
 		$this->setSource($source);
105 105
 		$this->setTarget($target);
Please login to merge, or discard this patch.
lib/Settings/Admin.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,12 +32,12 @@
 block discarded – undo
32 32
 	 * @return TemplateResponse
33 33
 	 */
34 34
 	public function getForm() {
35
-		return new TemplateResponse( 'ocr', 'settings-admin', [ 
36
-				OcrConstants::LANGUAGES_CONFIG_KEY => $this->config->getAppValue ( 'ocr', OcrConstants::LANGUAGES_CONFIG_KEY), 
37
-				OcrConstants::REDIS_CONFIG_KEY_HOST => $this->config->getAppValue ( 'ocr', OcrConstants::REDIS_CONFIG_KEY_HOST),
35
+		return new TemplateResponse('ocr', 'settings-admin', [ 
36
+				OcrConstants::LANGUAGES_CONFIG_KEY => $this->config->getAppValue('ocr', OcrConstants::LANGUAGES_CONFIG_KEY), 
37
+				OcrConstants::REDIS_CONFIG_KEY_HOST => $this->config->getAppValue('ocr', OcrConstants::REDIS_CONFIG_KEY_HOST),
38 38
 				OcrConstants::REDIS_CONFIG_KEY_PORT => $this->config->getAppValue('ocr', OcrConstants::REDIS_CONFIG_KEY_PORT),
39 39
 				OcrConstants::REDIS_CONFIG_KEY_DB => $this->config->getAppValue('ocr', OcrConstants::REDIS_CONFIG_KEY_DB)
40
-		], 'blank' );
40
+		], 'blank');
41 41
 	}
42 42
 	/**
43 43
 	 *
Please login to merge, or discard this patch.
lib/Service/JobService.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,6 @@
 block discarded – undo
17 17
 use OCP\IL10N;
18 18
 use OCP\ITempManager;
19 19
 use OCA\Ocr\Db\OcrJob;
20
-use OCA\Ocr\Db\File;
21 20
 use OCA\Ocr\Constants\OcrConstants;
22 21
 use OCA\Ocr\Util\PHPUtil;
23 22
 
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -124,44 +124,44 @@  discard block
 block discarded – undo
124 124
 	 */
125 125
 	public function process($languages, $files) {
126 126
 		try {
127
-			$this->logger->debug ( 'Will now process files: {files} with languages: {languages}', [ 
128
-					'files' => json_encode ( $files ),
129
-					'languages' => json_encode ( $languages )
130
-			] );
127
+			$this->logger->debug('Will now process files: {files} with languages: {languages}', [ 
128
+					'files' => json_encode($files),
129
+					'languages' => json_encode($languages)
130
+			]);
131 131
 			// Check if files and language not empty
132
-			$noLang = $this->noLanguage ( $languages );
133
-			if (! empty ( $files ) && ($this->checkForAcceptedLanguages ( $languages ) || $noLang)) {
132
+			$noLang = $this->noLanguage($languages);
133
+			if (!empty ($files) && ($this->checkForAcceptedLanguages($languages) || $noLang)) {
134 134
 				// language part:
135 135
 				if ($noLang) {
136
-					$languages = [ ];
136
+					$languages = [];
137 137
 				}
138 138
 				// file part:
139
-				$fileInfo = $this->fileService->buildFileInfo ( $files );
140
-				foreach ( $fileInfo as $fInfo ) {
139
+				$fileInfo = $this->fileService->buildFileInfo($files);
140
+				foreach ($fileInfo as $fInfo) {
141 141
 					// Check Shared
142
-					$shared = $this->fileService->checkSharedWithInitiator ( $fInfo );
143
-					$target = $this->fileService->buildTarget ( $fInfo, $shared );
144
-					$source = $this->fileService->buildSource ( $fInfo, $shared );
142
+					$shared = $this->fileService->checkSharedWithInitiator($fInfo);
143
+					$target = $this->fileService->buildTarget($fInfo, $shared);
144
+					$source = $this->fileService->buildSource($fInfo, $shared);
145 145
 					
146 146
 					// set the running type
147
-					$fType = $this->fileService->getCorrectType ( $fInfo );
147
+					$fType = $this->fileService->getCorrectType($fInfo);
148 148
 					
149 149
 					// create a temp file for ocr processing purposes
150
-					$tempFile = $this->getTempFile ( $fType );
150
+					$tempFile = $this->getTempFile($fType);
151 151
 					
152 152
 					// Create job object
153
-					$job = new OcrJob ( OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, false, $fInfo->getName (), null );
153
+					$job = new OcrJob(OcrConstants::STATUS_PENDING, $source, $target, $tempFile, $fType, $this->userId, false, $fInfo->getName(), null);
154 154
 					
155 155
 					// Init client and send task / job
156 156
 					// Feed the worker
157
-					$this->redisService->sendJob ( $job, $languages, \OC::$SERVERROOT );
157
+					$this->redisService->sendJob($job, $languages, \OC::$SERVERROOT);
158 158
 				}
159 159
 				return 'PROCESSING';
160 160
 			} else {
161
-				throw new NotFoundException ( $this->l10n->t ( 'Empty parameters passed.' ) );
161
+				throw new NotFoundException($this->l10n->t('Empty parameters passed.'));
162 162
 			}
163
-		} catch ( Exception $e ) {
164
-			$this->handleException ( $e );
163
+		} catch (Exception $e) {
164
+			$this->handleException($e);
165 165
 		}
166 166
 	}
167 167
 	
@@ -175,26 +175,26 @@  discard block
 block discarded – undo
175 175
 	 */
176 176
 	public function deleteJob($jobId, $userId) {
177 177
 		try {
178
-			$job = $this->jobMapper->find ( $jobId );
179
-			if ($job->getUserId () !== $userId) {
180
-				throw new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong owner.' ) );
178
+			$job = $this->jobMapper->find($jobId);
179
+			if ($job->getUserId() !== $userId) {
180
+				throw new NotFoundException($this->l10n->t('Cannot delete. Wrong owner.'));
181 181
 			} else {
182
-				$job = $this->jobMapper->delete ( $job );
182
+				$job = $this->jobMapper->delete($job);
183 183
 			}
184
-			$job->setTarget ( null );
185
-			$job->setSource ( null );
186
-			$job->setStatus ( null );
187
-			$job->setTempFile ( null );
188
-			$job->setType ( null );
189
-			$job->setUserId ( null );
190
-			$job->setErrorDisplayed ( null );
184
+			$job->setTarget(null);
185
+			$job->setSource(null);
186
+			$job->setStatus(null);
187
+			$job->setTempFile(null);
188
+			$job->setType(null);
189
+			$job->setUserId(null);
190
+			$job->setErrorDisplayed(null);
191 191
 			return $job;
192
-		} catch ( Exception $e ) {
192
+		} catch (Exception $e) {
193 193
 			if ($e instanceof DoesNotExistException) {
194
-				$ex = new NotFoundException ( $this->l10n->t ( 'Cannot delete. Wrong ID.' ) );
195
-				$this->handleException ( $ex );
194
+				$ex = new NotFoundException($this->l10n->t('Cannot delete. Wrong ID.'));
195
+				$this->handleException($ex);
196 196
 			} else {
197
-				$this->handleException ( $e );
197
+				$this->handleException($e);
198 198
 			}
199 199
 		}
200 200
 	}
@@ -207,21 +207,21 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	public function getAllJobsForUser($userId) {
209 209
 		try {
210
-			$jobs = $this->jobMapper->findAll ( $userId );
211
-			$jobsNew = array ();
212
-			foreach ( $jobs as $job ) {
213
-				$job->setTarget ( null );
214
-				$job->setSource ( null );
215
-				$job->setTempFile ( null );
216
-				$job->setType ( null );
217
-				$job->setUserId ( null );
218
-				$job->setErrorDisplayed ( null );
210
+			$jobs = $this->jobMapper->findAll($userId);
211
+			$jobsNew = array();
212
+			foreach ($jobs as $job) {
213
+				$job->setTarget(null);
214
+				$job->setSource(null);
215
+				$job->setTempFile(null);
216
+				$job->setType(null);
217
+				$job->setUserId(null);
218
+				$job->setErrorDisplayed(null);
219 219
 				
220
-				array_push ( $jobsNew, $job );
220
+				array_push($jobsNew, $job);
221 221
 			}
222 222
 			return $jobsNew;
223
-		} catch ( Exception $e ) {
224
-			$this->handleException ( $e );
223
+		} catch (Exception $e) {
224
+			$this->handleException($e);
225 225
 		}
226 226
 	}
227 227
 	
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
 	 */
232 232
 	public function checkForFinishedJobs() {
233 233
 		try {
234
-			$finishedJobs = $this->redisService->readingFinishedJobs ();
235
-			foreach ( $finishedJobs as $finishedJob ) {
236
-				$fJob = $this->transformJob( $finishedJob );
234
+			$finishedJobs = $this->redisService->readingFinishedJobs();
235
+			foreach ($finishedJobs as $finishedJob) {
236
+				$fJob = $this->transformJob($finishedJob);
237 237
 				$this->logger->debug('The following job finished: {job}', ['job' => $fJob]);
238
-				$this->jobFinished ( $fJob->id, $fJob->error, $fJob->log );
238
+				$this->jobFinished($fJob->id, $fJob->error, $fJob->log);
239 239
 			}
240
-		} catch ( Exception $e ) {
241
-			throw new NotFoundException ( $this->l10n->t ( 'Reading the finished jobs from redis went wrong.' ) );
240
+		} catch (Exception $e) {
241
+			throw new NotFoundException($this->l10n->t('Reading the finished jobs from redis went wrong.'));
242 242
 		}
243 243
 	}
244 244
 	
@@ -252,18 +252,18 @@  discard block
 block discarded – undo
252 252
 	 */
253 253
 	public function jobFinished($jobId, $error, $log) {
254 254
 		try {
255
-			$job = $this->jobMapper->find ( $jobId );
256
-			if (! $error) {
257
-				$job->setStatus ( OcrConstants::STATUS_PROCESSED );
258
-				$this->jobMapper->update ( $job );
255
+			$job = $this->jobMapper->find($jobId);
256
+			if (!$error) {
257
+				$job->setStatus(OcrConstants::STATUS_PROCESSED);
258
+				$this->jobMapper->update($job);
259 259
 			} else {
260
-				$job->setStatus ( OcrConstants::STATUS_FAILED );
261
-				$job->setErrorLog( $log );
262
-				$this->jobMapper->update ( $job );
263
-				$this->logger->error ( $log);
260
+				$job->setStatus(OcrConstants::STATUS_FAILED);
261
+				$job->setErrorLog($log);
262
+				$this->jobMapper->update($job);
263
+				$this->logger->error($log);
264 264
 			}
265
-		} catch ( Exception $e ) {
266
-			$this->handleException ( $e );
265
+		} catch (Exception $e) {
266
+			$this->handleException($e);
267 267
 		}
268 268
 	}
269 269
 	
@@ -275,24 +275,24 @@  discard block
 block discarded – undo
275 275
 	 */
276 276
 	public function handleProcessed() {
277 277
 		try {
278
-			$this->logger->debug ( 'Check if files were processed by ocr and if so, put them to the right dirs.');
279
-			$processed = $this->jobMapper->findAllProcessed ( $this->userId );
280
-			foreach ( $processed as $job ) {
281
-				if ($this->fileService->fileExists ( $job->getTempFile () )) {
278
+			$this->logger->debug('Check if files were processed by ocr and if so, put them to the right dirs.');
279
+			$processed = $this->jobMapper->findAllProcessed($this->userId);
280
+			foreach ($processed as $job) {
281
+				if ($this->fileService->fileExists($job->getTempFile())) {
282 282
 					// Save the tmp file with newname
283
-					$this->view->file_put_contents ( $job->getTarget (), $this->fileService->getFileContents ( $job->getTempFile () ) );
284
-					$this->jobMapper->delete ( $job );
285
-					$this->fileService->execRemove ( $job->getTempFile () );
283
+					$this->view->file_put_contents($job->getTarget(), $this->fileService->getFileContents($job->getTempFile()));
284
+					$this->jobMapper->delete($job);
285
+					$this->fileService->execRemove($job->getTempFile());
286 286
 				} else {
287
-					$job->setStatus ( OcrConstants::STATUS_FAILED );
287
+					$job->setStatus(OcrConstants::STATUS_FAILED);
288 288
 					$job->setErrorLog('Temp file does not exist.');
289
-					$this->jobMapper->update ( $job );
290
-					throw new NotFoundException ( $this->l10n->t ( 'Temp file does not exist.' ) );
289
+					$this->jobMapper->update($job);
290
+					throw new NotFoundException($this->l10n->t('Temp file does not exist.'));
291 291
 				}
292 292
 			}
293 293
 			return $processed;
294
-		} catch ( Exception $e ) {
295
-			$this->handleException ( $e );
294
+		} catch (Exception $e) {
295
+			$this->handleException($e);
296 296
 		}
297 297
 	}
298 298
 	
@@ -303,20 +303,20 @@  discard block
 block discarded – undo
303 303
 	 */
304 304
 	public function handleFailed() {
305 305
 		try {
306
-			$failed = $this->jobMapper->findAllFailed ( $this->userId );
307
-			foreach ( $failed as $job ) {
306
+			$failed = $this->jobMapper->findAllFailed($this->userId);
307
+			foreach ($failed as $job) {
308 308
 				// clean the tempfile
309
-				$this->fileService->execRemove ( $job->getTempFile () );
309
+				$this->fileService->execRemove($job->getTempFile());
310 310
 				// set error displayed
311
-				$job->setErrorDisplayed ( true );
312
-				$this->jobMapper->update ( $job );
311
+				$job->setErrorDisplayed(true);
312
+				$this->jobMapper->update($job);
313 313
 			}
314
-			$this->logger->debug ( 'Following jobs failed: {failed}', [ 
315
-					'failed' => json_encode ( $failed )
316
-			] );
314
+			$this->logger->debug('Following jobs failed: {failed}', [ 
315
+					'failed' => json_encode($failed)
316
+			]);
317 317
 			return $failed;
318
-		} catch ( Exception $e ) {
319
-			$this->handleException ( $e );
318
+		} catch (Exception $e) {
319
+			$this->handleException($e);
320 320
 		}
321 321
 	}
322 322
 	
@@ -329,14 +329,14 @@  discard block
 block discarded – undo
329 329
 	 */
330 330
 	private function getTempFile($type) {
331 331
 		if ($type === OcrConstants::TESSERACT) {
332
-			$fileName = $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir (), OcrConstants::TEMPFILE_PREFIX);
332
+			$fileName = $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir(), OcrConstants::TEMPFILE_PREFIX);
333 333
 			$this->phpUtil->unlinkWrapper($fileName);
334 334
 			$fileNameWithPostfix = $fileName . '.txt';
335
-			$this->phpUtil->touchWrapper( $fileNameWithPostfix );
336
-			$this->phpUtil->chmodWrapper( $fileNameWithPostfix, 0600 );
335
+			$this->phpUtil->touchWrapper($fileNameWithPostfix);
336
+			$this->phpUtil->chmodWrapper($fileNameWithPostfix, 0600);
337 337
 			return $fileNameWithPostfix;
338 338
 		} else {
339
-			return $this->phpUtil->tempnamWrapper( $this->tempM->getTempBaseDir (), 'ocr_' );
339
+			return $this->phpUtil->tempnamWrapper($this->tempM->getTempBaseDir(), 'ocr_');
340 340
 		}
341 341
 	}
342 342
 	
@@ -348,11 +348,11 @@  discard block
 block discarded – undo
348 348
 	 * @return mixed
349 349
 	 */
350 350
 	private function transformJob($job) {
351
-		$decoded = json_decode ( $job );
352
-		if($decoded !== null && isset($decoded->id)) {
351
+		$decoded = json_decode($job);
352
+		if ($decoded !== null && isset($decoded->id)) {
353 353
 			return $decoded;
354 354
 		} else {
355
-			throw new NotFoundException($this->l10n->t ( 'The finished job retrieved by Redis was corrupt.' ));
355
+			throw new NotFoundException($this->l10n->t('The finished job retrieved by Redis was corrupt.'));
356 356
 		}
357 357
 	}
358 358
 	
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 	 * @return boolean
364 364
 	 */
365 365
 	private function checkForAcceptedLanguages($languages) {
366
-		$installedLanguages = explode ( ';', $this->appConfigService->getAppValue ( 'languages' ) );
367
-		if (count ( array_diff ( $languages, $installedLanguages ) ) === 0) {
366
+		$installedLanguages = explode(';', $this->appConfigService->getAppValue('languages'));
367
+		if (count(array_diff($languages, $installedLanguages)) === 0) {
368 368
 			return true;
369 369
 		} else {
370 370
 			return false;
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	 * @return boolean
379 379
 	 */
380 380
 	private function noLanguage($languages) {
381
-		if (in_array ( 'any', $languages )) {
381
+		if (in_array('any', $languages)) {
382 382
 			return true;
383 383
 		} else {
384 384
 			return false;
@@ -393,9 +393,9 @@  discard block
 block discarded – undo
393 393
 	 * @throws NotFoundException
394 394
 	 */
395 395
 	private function handleException($e) {
396
-		$this->logger->logException ( $e, [ 
396
+		$this->logger->logException($e, [ 
397 397
 				'message' => 'Exception during job service function processing' 
398
-		] );
398
+		]);
399 399
 		throw $e;
400 400
 	}
401 401
 }
402 402
\ No newline at end of file
Please login to merge, or discard this patch.
lib/AppInfo/Application.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -40,139 +40,139 @@  discard block
 block discarded – undo
40 40
 	 * @param array $urlParams        	
41 41
 	 */
42 42
 	public function __construct(array $urlParams = array()) {
43
-		parent::__construct ( 'ocr', $urlParams );
44
-		$container = $this->getContainer ();
43
+		parent::__construct('ocr', $urlParams);
44
+		$container = $this->getContainer();
45 45
 		
46 46
 		/**
47 47
 		 * Add the js and style if OCA\Files app is loaded
48 48
 		 */
49
-		$eventDispatcher = \OC::$server->getEventDispatcher ();
50
-		$eventDispatcher->addListener ( 'OCA\Files::loadAdditionalScripts', function () {
51
-			script ( 'ocr', 'dist/ocrapp' );
52
-			style ( 'ocr', 'ocrstyle' );
49
+		$eventDispatcher = \OC::$server->getEventDispatcher();
50
+		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
51
+			script('ocr', 'dist/ocrapp');
52
+			style('ocr', 'ocrstyle');
53 53
 			// if not loaded before - load select2 for multi select languages
54
-			vendor_script ( 'select2/select2' );
55
-			vendor_style ( 'select2/select2' );
54
+			vendor_script('select2/select2');
55
+			vendor_style('select2/select2');
56 56
 		} );
57 57
 		
58 58
 		/**
59 59
 		 * Register core services
60 60
 		 */
61
-		$container->registerService ( 'CurrentUID', function (IContainer $c) {
61
+		$container->registerService('CurrentUID', function(IContainer $c) {
62 62
 			/** @var \OC\Server $server */
63
-			$server = $c->query ( 'ServerContainer' );
64
-			$user = $server->getUserSession ()->getUser ();
65
-			return ($user) ? $user->getUID () : '';
63
+			$server = $c->query('ServerContainer');
64
+			$user = $server->getUserSession()->getUser();
65
+			return ($user) ? $user->getUID() : '';
66 66
 		} );
67 67
 		
68 68
 		// Allow automatic DI for the View, until they migrated to Nodes API
69
-		$container->registerService ( View::class, function () {
70
-			return new View ( '' );
71
-		}, false );
69
+		$container->registerService(View::class, function() {
70
+			return new View('');
71
+		}, false);
72 72
 		
73 73
 		/**
74 74
 		 * Register the PHPUtil
75 75
 		 */
76
-		$container->registerService ( 'PHPUtil', function (IContainer $c) {
76
+		$container->registerService('PHPUtil', function(IContainer $c) {
77 77
 			/** @var \OC\Server $server */
78
-			$server = $c->query ( 'ServerContainer' );
79
-			return new PHPUtil ( $server->getL10N ( 'ocr' ), $server->getLogger () );
78
+			$server = $c->query('ServerContainer');
79
+			return new PHPUtil($server->getL10N('ocr'), $server->getLogger());
80 80
 		} );
81 81
 		
82 82
 		/**
83 83
 		 * Register the Ocr Job mapper
84 84
 		 */
85
-		$container->registerService ( 'OcrJobMapper', function (IContainer $c) {
85
+		$container->registerService('OcrJobMapper', function(IContainer $c) {
86 86
 			/** @var \OC\Server $server */
87
-			$server = $c->query ( 'ServerContainer' );
88
-			return new OcrJobMapper ( $server->getDatabaseConnection () );
87
+			$server = $c->query('ServerContainer');
88
+			return new OcrJobMapper($server->getDatabaseConnection());
89 89
 		} );
90 90
 		
91 91
 		/**
92 92
 		 * Register the File mapper
93 93
 		 */
94
-		$container->registerService ( 'FileMapper', function (IContainer $c) {
94
+		$container->registerService('FileMapper', function(IContainer $c) {
95 95
 			/** @var \OC\Server $server */
96
-			$server = $c->query ( 'ServerContainer' );
97
-			return new FileMapper ( $server->getDatabaseConnection () );
96
+			$server = $c->query('ServerContainer');
97
+			return new FileMapper($server->getDatabaseConnection());
98 98
 		} );
99 99
 		
100 100
 		/**
101 101
 		 * Register the Share mapper
102 102
 		 */
103
-		$container->registerService ( 'ShareMapper', function (IContainer $c) {
103
+		$container->registerService('ShareMapper', function(IContainer $c) {
104 104
 			/** @var \OC\Server $server */
105
-			$server = $c->query ( 'ServerContainer' );
106
-			return new ShareMapper ( $server->getDatabaseConnection () );
105
+			$server = $c->query('ServerContainer');
106
+			return new ShareMapper($server->getDatabaseConnection());
107 107
 		} );
108 108
 		
109 109
 		/**
110 110
 		 * Register the App Config Service
111 111
 		 */
112
-		$container->registerService ( 'AppConfigService', function (IAppContainer $c) {
112
+		$container->registerService('AppConfigService', function(IAppContainer $c) {
113 113
 			/** @var \OC\Server $server */
114
-			$server = $c->query ( 'ServerContainer' );
115
-			return new AppConfigService ( $server->getConfig (), $server->getL10N ( 'ocr' ) );
114
+			$server = $c->query('ServerContainer');
115
+			return new AppConfigService($server->getConfig(), $server->getL10N('ocr'));
116 116
 		} );
117 117
 		
118 118
 		/**
119 119
 		 * Register the Job Service
120 120
 		 */
121
-		$container->registerService ( 'FileService', function (IAppContainer $c) {
121
+		$container->registerService('FileService', function(IAppContainer $c) {
122 122
 			/** @var \OC\Server $server */
123
-			$server = $c->query ( 'ServerContainer' );
124
-			return new FileService ( $server->getL10N ( 'ocr' ), $server->getLogger (), $c->query ( 'CurrentUID' ), $c->query ( 'FileMapper' ), $c->query ( 'ShareMapper' ) );
123
+			$server = $c->query('ServerContainer');
124
+			return new FileService($server->getL10N('ocr'), $server->getLogger(), $c->query('CurrentUID'), $c->query('FileMapper'), $c->query('ShareMapper'));
125 125
 		} );
126 126
 		
127 127
 		/**
128 128
 		 * Register the Redis Service
129 129
 		 */
130
-		$container->registerService ( 'RedisService', function (IAppContainer $c) {
130
+		$container->registerService('RedisService', function(IAppContainer $c) {
131 131
 			/** @var \OC\Server $server */
132
-			$server = $c->query ( 'ServerContainer' );
133
-			return new RedisService ( $c->query ( 'OcrJobMapper' ), $c->query ( 'FileService' ), $server->getConfig (), $server->getL10N ( 'ocr' ), $server->getLogger () );
132
+			$server = $c->query('ServerContainer');
133
+			return new RedisService($c->query('OcrJobMapper'), $c->query('FileService'), $server->getConfig(), $server->getL10N('ocr'), $server->getLogger());
134 134
 		} );
135 135
 		
136 136
 		/**
137 137
 		 * Register the Job Service
138 138
 		 */
139
-		$container->registerService ( 'JobService', function (IAppContainer $c) {
139
+		$container->registerService('JobService', function(IAppContainer $c) {
140 140
 			/** @var \OC\Server $server */
141
-			$server = $c->query ( 'ServerContainer' );
142
-			return new JobService ( $server->getL10N ( 'ocr' ), $server->getLogger (), $c->query ( 'CurrentUID' ), new View ( '/' . $c->query ( 'CurrentUID' ) . '/files' ), $server->getTempManager (), $c->query ( 'RedisService' ), $c->query ( 'OcrJobMapper' ), $c->query ( 'FileService' ), $c->query ( 'AppConfigService' ), $c->query ( 'PHPUtil' ) );
141
+			$server = $c->query('ServerContainer');
142
+			return new JobService($server->getL10N('ocr'), $server->getLogger(), $c->query('CurrentUID'), new View('/' . $c->query('CurrentUID') . '/files'), $server->getTempManager(), $c->query('RedisService'), $c->query('OcrJobMapper'), $c->query('FileService'), $c->query('AppConfigService'), $c->query('PHPUtil'));
143 143
 		} );
144 144
 		
145 145
 		/**
146 146
 		 * Register the Status Service
147 147
 		 */
148
-		$container->registerService ( 'StatusService', function (IAppContainer $c) {
148
+		$container->registerService('StatusService', function(IAppContainer $c) {
149 149
 			/** @var \OC\Server $server */
150
-			$server = $c->query ( 'ServerContainer' );
151
-			return new StatusService ( $server->getL10N ( 'ocr' ), $server->getLogger (), $c->query ( 'CurrentUID' ), $c->query ( 'OcrJobMapper' ), $c->query ( 'JobService' ) );
150
+			$server = $c->query('ServerContainer');
151
+			return new StatusService($server->getL10N('ocr'), $server->getLogger(), $c->query('CurrentUID'), $c->query('OcrJobMapper'), $c->query('JobService'));
152 152
 		} );
153 153
 		
154 154
 		/**
155 155
 		 * Controller
156 156
 		 */
157
-		$container->registerService ( 'StatusController', function (IAppContainer $c) {
157
+		$container->registerService('StatusController', function(IAppContainer $c) {
158 158
 			/** @var \OC\Server $server */
159
-			$server = $c->query ( 'ServerContainer' );
160
-			return new StatusController ( $c->getAppName (), $server->getRequest (), $c->query ( 'StatusService' ) );
159
+			$server = $c->query('ServerContainer');
160
+			return new StatusController($c->getAppName(), $server->getRequest(), $c->query('StatusService'));
161 161
 		} );
162 162
 		
163 163
 		/**
164 164
 		 * Controller
165 165
 		 */
166
-		$container->registerService ( 'JobController', function (IAppContainer $c) {
166
+		$container->registerService('JobController', function(IAppContainer $c) {
167 167
 			/** @var \OC\Server $server */
168
-			$server = $c->query ( 'ServerContainer' );
169
-			return new JobController ( $c->getAppName (), $server->getRequest (), $c->query ( 'JobService' ), $c->query ( 'CurrentUID' ) );
168
+			$server = $c->query('ServerContainer');
169
+			return new JobController($c->getAppName(), $server->getRequest(), $c->query('JobService'), $c->query('CurrentUID'));
170 170
 		} );
171 171
 		
172 172
 		/**
173 173
 		 * Controller
174 174
 		 */
175
-		$container->registerAlias ( 'PersonalSettingsController', PersonalSettingsController::class );
175
+		$container->registerAlias('PersonalSettingsController', PersonalSettingsController::class);
176 176
 	}
177 177
 	
178 178
 	/**
@@ -180,6 +180,6 @@  discard block
 block discarded – undo
180 180
 	 * @codeCoverageIgnore
181 181
 	 */
182 182
 	public function registerPersonal() {
183
-		\OCP\App::registerPersonal ( $this->getContainer ()->getAppName (), 'personal' );
183
+		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
184 184
 	}
185 185
 }
Please login to merge, or discard this patch.