@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | if ($this->config->getSystemValue('installed', false)) { |
74 | 74 | $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath(null)); |
75 | 75 | } else { |
76 | - $this->client->setDefaultOption('verify', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); |
|
76 | + $this->client->setDefaultOption('verify', \OC::$SERVERROOT.'/resources/config/ca-bundle.crt'); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $proxyUri = ''; |
96 | 96 | |
97 | 97 | if ($proxyUserPwd !== null) { |
98 | - $proxyUri .= $proxyUserPwd . '@'; |
|
98 | + $proxyUri .= $proxyUserPwd.'@'; |
|
99 | 99 | } |
100 | 100 | if ($proxyHost !== null) { |
101 | 101 | $proxyUri .= $proxyHost; |
@@ -48,7 +48,7 @@ |
||
48 | 48 | try { |
49 | 49 | session_start(); |
50 | 50 | } catch (\Exception $e) { |
51 | - setcookie(session_name(), null, -1, \OC::$WEBROOT ? : '/'); |
|
51 | + setcookie(session_name(), null, -1, \OC::$WEBROOT ?: '/'); |
|
52 | 52 | } |
53 | 53 | restore_error_handler(); |
54 | 54 | if (!isset($_SESSION)) { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @return string|null Either the value or null |
98 | 98 | */ |
99 | 99 | public function get($key) { |
100 | - if(isset($this->sessionValues[$key])) { |
|
100 | + if (isset($this->sessionValues[$key])) { |
|
101 | 101 | return $this->sessionValues[$key]; |
102 | 102 | } |
103 | 103 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * Close the session and release the lock, also writes all changed data in batch |
160 | 160 | */ |
161 | 161 | public function close() { |
162 | - if($this->isModified) { |
|
162 | + if ($this->isModified) { |
|
163 | 163 | $encryptedValue = $this->crypto->encrypt(json_encode($this->sessionValues), $this->passphrase); |
164 | 164 | $this->session->set(self::encryptedSessionName, $encryptedValue); |
165 | 165 | $this->isModified = false; |
@@ -81,7 +81,7 @@ |
||
81 | 81 | // FIXME: Required for CI |
82 | 82 | if (!defined('PHPUNIT_RUN')) { |
83 | 83 | $webRoot = \OC::$WEBROOT; |
84 | - if($webRoot === '') { |
|
84 | + if ($webRoot === '') { |
|
85 | 85 | $webRoot = '/'; |
86 | 86 | } |
87 | 87 | setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * the comments database scheme |
52 | 52 | */ |
53 | 53 | public function __construct(array $data = null) { |
54 | - if(is_array($data)) { |
|
54 | + if (is_array($data)) { |
|
55 | 55 | $this->fromArray($data); |
56 | 56 | } |
57 | 57 | } |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | * @since 9.0.0 |
85 | 85 | */ |
86 | 86 | public function setId($id) { |
87 | - if(!is_string($id)) { |
|
87 | + if (!is_string($id)) { |
|
88 | 88 | throw new \InvalidArgumentException('String expected.'); |
89 | 89 | } |
90 | 90 | |
91 | 91 | $id = trim($id); |
92 | - if($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
92 | + if ($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
93 | 93 | $this->data['id'] = $id; |
94 | 94 | return $this; |
95 | 95 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @since 9.0.0 |
116 | 116 | */ |
117 | 117 | public function setParentId($parentId) { |
118 | - if(!is_string($parentId)) { |
|
118 | + if (!is_string($parentId)) { |
|
119 | 119 | throw new \InvalidArgumentException('String expected.'); |
120 | 120 | } |
121 | 121 | $this->data['parentId'] = trim($parentId); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @since 9.0.0 |
142 | 142 | */ |
143 | 143 | public function setTopmostParentId($id) { |
144 | - if(!is_string($id)) { |
|
144 | + if (!is_string($id)) { |
|
145 | 145 | throw new \InvalidArgumentException('String expected.'); |
146 | 146 | } |
147 | 147 | $this->data['topmostParentId'] = trim($id); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @since 9.0.0 |
167 | 167 | */ |
168 | 168 | public function setChildrenCount($count) { |
169 | - if(!is_int($count)) { |
|
169 | + if (!is_int($count)) { |
|
170 | 170 | throw new \InvalidArgumentException('Integer expected.'); |
171 | 171 | } |
172 | 172 | $this->data['childrenCount'] = $count; |
@@ -192,12 +192,12 @@ discard block |
||
192 | 192 | * @since 9.0.0 |
193 | 193 | */ |
194 | 194 | public function setMessage($message) { |
195 | - if(!is_string($message)) { |
|
195 | + if (!is_string($message)) { |
|
196 | 196 | throw new \InvalidArgumentException('String expected.'); |
197 | 197 | } |
198 | 198 | $message = trim($message); |
199 | - if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { |
|
200 | - throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters'); |
|
199 | + if (mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { |
|
200 | + throw new MessageTooLongException('Comment message must not exceed '.IComment::MAX_MESSAGE_LENGTH.' characters'); |
|
201 | 201 | } |
202 | 202 | $this->data['message'] = $message; |
203 | 203 | return $this; |
@@ -225,14 +225,14 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function getMentions() { |
227 | 227 | $ok = preg_match_all('/\B@[a-z0-9_\-@\.\']+/i', $this->getMessage(), $mentions); |
228 | - if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
228 | + if (!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
229 | 229 | return []; |
230 | 230 | } |
231 | 231 | $uids = array_unique($mentions[0]); |
232 | 232 | $result = []; |
233 | 233 | foreach ($uids as $uid) { |
234 | 234 | // exclude author, no self-mentioning |
235 | - if($uid === '@' . $this->getActorId()) { |
|
235 | + if ($uid === '@'.$this->getActorId()) { |
|
236 | 236 | continue; |
237 | 237 | } |
238 | 238 | $result[] = ['type' => 'user', 'id' => substr($uid, 1)]; |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @since 9.0.0 |
259 | 259 | */ |
260 | 260 | public function setVerb($verb) { |
261 | - if(!is_string($verb) || !trim($verb)) { |
|
261 | + if (!is_string($verb) || !trim($verb)) { |
|
262 | 262 | throw new \InvalidArgumentException('Non-empty String expected.'); |
263 | 263 | } |
264 | 264 | $this->data['verb'] = trim($verb); |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | * @since 9.0.0 |
295 | 295 | */ |
296 | 296 | public function setActor($actorType, $actorId) { |
297 | - if( |
|
297 | + if ( |
|
298 | 298 | !is_string($actorType) || !trim($actorType) |
299 | - || !is_string($actorId) || !trim($actorId) |
|
299 | + || !is_string($actorId) || !trim($actorId) |
|
300 | 300 | ) { |
301 | 301 | throw new \InvalidArgumentException('String expected.'); |
302 | 302 | } |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | * @since 9.0.0 |
381 | 381 | */ |
382 | 382 | public function setObject($objectType, $objectId) { |
383 | - if( |
|
383 | + if ( |
|
384 | 384 | !is_string($objectType) || !trim($objectType) |
385 | - || !is_string($objectId) || !trim($objectId) |
|
385 | + || !is_string($objectId) || !trim($objectId) |
|
386 | 386 | ) { |
387 | 387 | throw new \InvalidArgumentException('String expected.'); |
388 | 388 | } |
@@ -399,20 +399,20 @@ discard block |
||
399 | 399 | * @return IComment |
400 | 400 | */ |
401 | 401 | protected function fromArray($data) { |
402 | - foreach(array_keys($data) as $key) { |
|
402 | + foreach (array_keys($data) as $key) { |
|
403 | 403 | // translate DB keys to internal setter names |
404 | - $setter = 'set' . implode('', array_map('ucfirst', explode('_', $key))); |
|
404 | + $setter = 'set'.implode('', array_map('ucfirst', explode('_', $key))); |
|
405 | 405 | $setter = str_replace('Timestamp', 'DateTime', $setter); |
406 | 406 | |
407 | - if(method_exists($this, $setter)) { |
|
407 | + if (method_exists($this, $setter)) { |
|
408 | 408 | $this->$setter($data[$key]); |
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | - foreach(['actor', 'object'] as $role) { |
|
413 | - if(isset($data[$role . '_type']) && isset($data[$role . '_id'])) { |
|
414 | - $setter = 'set' . ucfirst($role); |
|
415 | - $this->$setter($data[$role . '_type'], $data[$role . '_id']); |
|
412 | + foreach (['actor', 'object'] as $role) { |
|
413 | + if (isset($data[$role.'_type']) && isset($data[$role.'_id'])) { |
|
414 | + $setter = 'set'.ucfirst($role); |
|
415 | + $this->$setter($data[$role.'_type'], $data[$role.'_id']); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @throws \UnexpectedValueException |
105 | 105 | */ |
106 | 106 | protected function prepareCommentForDatabaseWrite(IComment $comment) { |
107 | - if( !$comment->getActorType() |
|
107 | + if (!$comment->getActorType() |
|
108 | 108 | || !$comment->getActorId() |
109 | 109 | || !$comment->getObjectType() |
110 | 110 | || !$comment->getObjectId() |
@@ -113,17 +113,17 @@ discard block |
||
113 | 113 | throw new \UnexpectedValueException('Actor, Object and Verb information must be provided for saving'); |
114 | 114 | } |
115 | 115 | |
116 | - if($comment->getId() === '') { |
|
116 | + if ($comment->getId() === '') { |
|
117 | 117 | $comment->setChildrenCount(0); |
118 | 118 | $comment->setLatestChildDateTime(new \DateTime('0000-00-00 00:00:00', new \DateTimeZone('UTC'))); |
119 | 119 | $comment->setLatestChildDateTime(null); |
120 | 120 | } |
121 | 121 | |
122 | - if(is_null($comment->getCreationDateTime())) { |
|
122 | + if (is_null($comment->getCreationDateTime())) { |
|
123 | 123 | $comment->setCreationDateTime(new \DateTime()); |
124 | 124 | } |
125 | 125 | |
126 | - if($comment->getParentId() !== '0') { |
|
126 | + if ($comment->getParentId() !== '0') { |
|
127 | 127 | $comment->setTopmostParentId($this->determineTopmostParentId($comment->getParentId())); |
128 | 128 | } else { |
129 | 129 | $comment->setTopmostParentId('0'); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function determineTopmostParentId($id) { |
145 | 145 | $comment = $this->get($id); |
146 | - if($comment->getParentId() === '0') { |
|
146 | + if ($comment->getParentId() === '0') { |
|
147 | 147 | return $comment->getId(); |
148 | 148 | } else { |
149 | 149 | return $this->determineTopmostParentId($comment->getId()); |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * @throws \InvalidArgumentException |
186 | 186 | */ |
187 | 187 | protected function checkRoleParameters($role, $type, $id) { |
188 | - if( |
|
188 | + if ( |
|
189 | 189 | !is_string($type) || empty($type) |
190 | 190 | || !is_string($id) || empty($id) |
191 | 191 | ) { |
192 | - throw new \InvalidArgumentException($role . ' parameters must be string and not empty'); |
|
192 | + throw new \InvalidArgumentException($role.' parameters must be string and not empty'); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | protected function cache(IComment $comment) { |
202 | 202 | $id = $comment->getId(); |
203 | - if(empty($id)) { |
|
203 | + if (empty($id)) { |
|
204 | 204 | return; |
205 | 205 | } |
206 | 206 | $this->commentsCache[strval($id)] = $comment; |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | * @since 9.0.0 |
229 | 229 | */ |
230 | 230 | public function get($id) { |
231 | - if(intval($id) === 0) { |
|
231 | + if (intval($id) === 0) { |
|
232 | 232 | throw new \InvalidArgumentException('IDs must be translatable to a number in this implementation.'); |
233 | 233 | } |
234 | 234 | |
235 | - if(isset($this->commentsCache[$id])) { |
|
235 | + if (isset($this->commentsCache[$id])) { |
|
236 | 236 | return $this->commentsCache[$id]; |
237 | 237 | } |
238 | 238 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | |
246 | 246 | $data = $resultStatement->fetch(); |
247 | 247 | $resultStatement->closeCursor(); |
248 | - if(!$data) { |
|
248 | + if (!$data) { |
|
249 | 249 | throw new NotFoundException(); |
250 | 250 | } |
251 | 251 | |
@@ -295,15 +295,15 @@ discard block |
||
295 | 295 | ->orderBy('creation_timestamp', 'DESC') |
296 | 296 | ->setParameter('id', $id); |
297 | 297 | |
298 | - if($limit > 0) { |
|
298 | + if ($limit > 0) { |
|
299 | 299 | $query->setMaxResults($limit); |
300 | 300 | } |
301 | - if($offset > 0) { |
|
301 | + if ($offset > 0) { |
|
302 | 302 | $query->setFirstResult($offset); |
303 | 303 | } |
304 | 304 | |
305 | 305 | $resultStatement = $query->execute(); |
306 | - while($data = $resultStatement->fetch()) { |
|
306 | + while ($data = $resultStatement->fetch()) { |
|
307 | 307 | $comment = new Comment($this->normalizeDatabaseData($data)); |
308 | 308 | $this->cache($comment); |
309 | 309 | $tree['replies'][] = [ |
@@ -349,20 +349,20 @@ discard block |
||
349 | 349 | ->setParameter('type', $objectType) |
350 | 350 | ->setParameter('id', $objectId); |
351 | 351 | |
352 | - if($limit > 0) { |
|
352 | + if ($limit > 0) { |
|
353 | 353 | $query->setMaxResults($limit); |
354 | 354 | } |
355 | - if($offset > 0) { |
|
355 | + if ($offset > 0) { |
|
356 | 356 | $query->setFirstResult($offset); |
357 | 357 | } |
358 | - if(!is_null($notOlderThan)) { |
|
358 | + if (!is_null($notOlderThan)) { |
|
359 | 359 | $query |
360 | 360 | ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
361 | 361 | ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
362 | 362 | } |
363 | 363 | |
364 | 364 | $resultStatement = $query->execute(); |
365 | - while($data = $resultStatement->fetch()) { |
|
365 | + while ($data = $resultStatement->fetch()) { |
|
366 | 366 | $comment = new Comment($this->normalizeDatabaseData($data)); |
367 | 367 | $this->cache($comment); |
368 | 368 | $comments[] = $comment; |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | ->setParameter('type', $objectType) |
390 | 390 | ->setParameter('id', $objectId); |
391 | 391 | |
392 | - if(!is_null($notOlderThan)) { |
|
392 | + if (!is_null($notOlderThan)) { |
|
393 | 393 | $query |
394 | 394 | ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
395 | 395 | ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * @since 9.0.0 |
434 | 434 | */ |
435 | 435 | public function delete($id) { |
436 | - if(!is_string($id)) { |
|
436 | + if (!is_string($id)) { |
|
437 | 437 | throw new \InvalidArgumentException('Parameter must be string'); |
438 | 438 | } |
439 | 439 | |
@@ -481,13 +481,13 @@ discard block |
||
481 | 481 | * @since 9.0.0 |
482 | 482 | */ |
483 | 483 | public function save(IComment $comment) { |
484 | - if($this->prepareCommentForDatabaseWrite($comment)->getId() === '') { |
|
484 | + if ($this->prepareCommentForDatabaseWrite($comment)->getId() === '') { |
|
485 | 485 | $result = $this->insert($comment); |
486 | 486 | } else { |
487 | 487 | $result = $this->update($comment); |
488 | 488 | } |
489 | 489 | |
490 | - if($result && !!$comment->getParentId()) { |
|
490 | + if ($result && !!$comment->getParentId()) { |
|
491 | 491 | $this->updateChildrenInformation( |
492 | 492 | $comment->getParentId(), |
493 | 493 | $comment->getCreationDateTime() |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | * @param IComment $comment |
505 | 505 | * @return bool |
506 | 506 | */ |
507 | - protected function insert(IComment &$comment) { |
|
507 | + protected function insert(IComment & $comment) { |
|
508 | 508 | $qb = $this->dbConn->getQueryBuilder(); |
509 | 509 | $affectedRows = $qb |
510 | 510 | ->insert('comments') |
@@ -548,22 +548,22 @@ discard block |
||
548 | 548 | $qb = $this->dbConn->getQueryBuilder(); |
549 | 549 | $affectedRows = $qb |
550 | 550 | ->update('comments') |
551 | - ->set('parent_id', $qb->createNamedParameter($comment->getParentId())) |
|
552 | - ->set('topmost_parent_id', $qb->createNamedParameter($comment->getTopmostParentId())) |
|
553 | - ->set('children_count', $qb->createNamedParameter($comment->getChildrenCount())) |
|
554 | - ->set('actor_type', $qb->createNamedParameter($comment->getActorType())) |
|
555 | - ->set('actor_id', $qb->createNamedParameter($comment->getActorId())) |
|
556 | - ->set('message', $qb->createNamedParameter($comment->getMessage())) |
|
557 | - ->set('verb', $qb->createNamedParameter($comment->getVerb())) |
|
558 | - ->set('creation_timestamp', $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime')) |
|
559 | - ->set('latest_child_timestamp', $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime')) |
|
560 | - ->set('object_type', $qb->createNamedParameter($comment->getObjectType())) |
|
561 | - ->set('object_id', $qb->createNamedParameter($comment->getObjectId())) |
|
551 | + ->set('parent_id', $qb->createNamedParameter($comment->getParentId())) |
|
552 | + ->set('topmost_parent_id', $qb->createNamedParameter($comment->getTopmostParentId())) |
|
553 | + ->set('children_count', $qb->createNamedParameter($comment->getChildrenCount())) |
|
554 | + ->set('actor_type', $qb->createNamedParameter($comment->getActorType())) |
|
555 | + ->set('actor_id', $qb->createNamedParameter($comment->getActorId())) |
|
556 | + ->set('message', $qb->createNamedParameter($comment->getMessage())) |
|
557 | + ->set('verb', $qb->createNamedParameter($comment->getVerb())) |
|
558 | + ->set('creation_timestamp', $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime')) |
|
559 | + ->set('latest_child_timestamp', $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime')) |
|
560 | + ->set('object_type', $qb->createNamedParameter($comment->getObjectType())) |
|
561 | + ->set('object_id', $qb->createNamedParameter($comment->getObjectId())) |
|
562 | 562 | ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
563 | 563 | ->setParameter('id', $comment->getId()) |
564 | 564 | ->execute(); |
565 | 565 | |
566 | - if($affectedRows === 0) { |
|
566 | + if ($affectedRows === 0) { |
|
567 | 567 | throw new NotFoundException('Comment to update does ceased to exist'); |
568 | 568 | } |
569 | 569 | |
@@ -587,8 +587,8 @@ discard block |
||
587 | 587 | $qb = $this->dbConn->getQueryBuilder(); |
588 | 588 | $affectedRows = $qb |
589 | 589 | ->update('comments') |
590 | - ->set('actor_type', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
591 | - ->set('actor_id', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
590 | + ->set('actor_type', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
591 | + ->set('actor_id', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
592 | 592 | ->where($qb->expr()->eq('actor_type', $qb->createParameter('type'))) |
593 | 593 | ->andWhere($qb->expr()->eq('actor_id', $qb->createParameter('id'))) |
594 | 594 | ->setParameter('type', $actorType) |
@@ -671,10 +671,10 @@ discard block |
||
671 | 671 | // Strategy: try to update, if this does not return affected rows, do an insert. |
672 | 672 | $affectedRows = $qb |
673 | 673 | ->update('comments_read_markers') |
674 | - ->set('user_id', $values['user_id']) |
|
674 | + ->set('user_id', $values['user_id']) |
|
675 | 675 | ->set('marker_datetime', $values['marker_datetime']) |
676 | - ->set('object_type', $values['object_type']) |
|
677 | - ->set('object_id', $values['object_id']) |
|
676 | + ->set('object_type', $values['object_type']) |
|
677 | + ->set('object_id', $values['object_id']) |
|
678 | 678 | ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
679 | 679 | ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
680 | 680 | ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | |
718 | 718 | $data = $resultStatement->fetch(); |
719 | 719 | $resultStatement->closeCursor(); |
720 | - if(!$data || is_null($data['marker_datetime'])) { |
|
720 | + if (!$data || is_null($data['marker_datetime'])) { |
|
721 | 721 | return null; |
722 | 722 | } |
723 | 723 | |
@@ -774,10 +774,10 @@ discard block |
||
774 | 774 | * \OutOfBoundsException has to thrown. |
775 | 775 | */ |
776 | 776 | public function registerDisplayNameResolver($type, \Closure $closure) { |
777 | - if(!is_string($type)) { |
|
777 | + if (!is_string($type)) { |
|
778 | 778 | throw new \InvalidArgumentException('String expected.'); |
779 | 779 | } |
780 | - if(isset($this->displayNameResolvers[$type])) { |
|
780 | + if (isset($this->displayNameResolvers[$type])) { |
|
781 | 781 | throw new \OutOfBoundsException('Displayname resolver for this type already registered'); |
782 | 782 | } |
783 | 783 | $this->displayNameResolvers[$type] = $closure; |
@@ -797,13 +797,13 @@ discard block |
||
797 | 797 | * provided ID is unknown. It must be ensured that a string is returned. |
798 | 798 | */ |
799 | 799 | public function resolveDisplayName($type, $id) { |
800 | - if(!is_string($type)) { |
|
800 | + if (!is_string($type)) { |
|
801 | 801 | throw new \InvalidArgumentException('String expected.'); |
802 | 802 | } |
803 | - if(!isset($this->displayNameResolvers[$type])) { |
|
803 | + if (!isset($this->displayNameResolvers[$type])) { |
|
804 | 804 | throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
805 | 805 | } |
806 | - return (string)$this->displayNameResolvers[$type]($id); |
|
806 | + return (string) $this->displayNameResolvers[$type]($id); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | * @return \OCP\Comments\ICommentsEventHandler[] |
813 | 813 | */ |
814 | 814 | private function getEventHandlers() { |
815 | - if(!empty($this->eventHandlers)) { |
|
815 | + if (!empty($this->eventHandlers)) { |
|
816 | 816 | return $this->eventHandlers; |
817 | 817 | } |
818 | 818 |
@@ -146,7 +146,7 @@ |
||
146 | 146 | throw new \InvalidArgumentException('The given notifier information is invalid'); |
147 | 147 | } |
148 | 148 | if (isset($this->notifiersInfo[$notifier['id']])) { |
149 | - throw new \InvalidArgumentException('The given notifier ID ' . $notifier['id'] . ' is already in use'); |
|
149 | + throw new \InvalidArgumentException('The given notifier ID '.$notifier['id'].' is already in use'); |
|
150 | 150 | } |
151 | 151 | $this->notifiersInfo[$notifier['id']] = $notifier['name']; |
152 | 152 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return bool |
97 | 97 | */ |
98 | 98 | public function isCodeCheckEnforced() { |
99 | - $notSignedChannels = [ '', 'git']; |
|
99 | + $notSignedChannels = ['', 'git']; |
|
100 | 100 | if (in_array($this->environmentHelper->getChannel(), $notSignedChannels, true)) { |
101 | 101 | return false; |
102 | 102 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $folderToIterate, |
132 | 132 | \RecursiveDirectoryIterator::SKIP_DOTS |
133 | 133 | ); |
134 | - if($root === '') { |
|
134 | + if ($root === '') { |
|
135 | 135 | $root = \OC::$SERVERROOT; |
136 | 136 | } |
137 | 137 | $root = rtrim($root, '/'); |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | $tmpFolder = ''; |
161 | 161 | |
162 | 162 | $baseDirectoryLength = strlen($path); |
163 | - foreach($iterator as $filename => $data) { |
|
163 | + foreach ($iterator as $filename => $data) { |
|
164 | 164 | /** @var \DirectoryIterator $data */ |
165 | - if($data->isDir()) { |
|
165 | + if ($data->isDir()) { |
|
166 | 166 | continue; |
167 | 167 | } |
168 | 168 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | $relativeFileName = ltrim($relativeFileName, '/'); |
171 | 171 | |
172 | 172 | // Exclude signature.json files in the appinfo and root folder |
173 | - if($relativeFileName === 'appinfo/signature.json') { |
|
173 | + if ($relativeFileName === 'appinfo/signature.json') { |
|
174 | 174 | continue; |
175 | 175 | } |
176 | 176 | // Exclude signature.json files in the appinfo and core folder |
177 | - if($relativeFileName === 'core/signature.json') { |
|
177 | + if ($relativeFileName === 'core/signature.json') { |
|
178 | 178 | continue; |
179 | 179 | } |
180 | 180 | |
@@ -183,18 +183,18 @@ discard block |
||
183 | 183 | // to ensure that this will not lead to false positives this will |
184 | 184 | // copy the file to a temporary folder and reset it to the default |
185 | 185 | // values. |
186 | - if($filename === $this->environmentHelper->getServerRoot() . '/.htaccess' |
|
187 | - || $filename === $this->environmentHelper->getServerRoot() . '/.user.ini') { |
|
186 | + if ($filename === $this->environmentHelper->getServerRoot().'/.htaccess' |
|
187 | + || $filename === $this->environmentHelper->getServerRoot().'/.user.ini') { |
|
188 | 188 | |
189 | - if(!$copiedWebserverSettingFiles) { |
|
189 | + if (!$copiedWebserverSettingFiles) { |
|
190 | 190 | $tmpFolder = rtrim($this->tempManager->getTemporaryFolder(), '/'); |
191 | - copy($this->environmentHelper->getServerRoot() . '/.htaccess', $tmpFolder . '/.htaccess'); |
|
192 | - copy($this->environmentHelper->getServerRoot() . '/.user.ini', $tmpFolder . '/.user.ini'); |
|
191 | + copy($this->environmentHelper->getServerRoot().'/.htaccess', $tmpFolder.'/.htaccess'); |
|
192 | + copy($this->environmentHelper->getServerRoot().'/.user.ini', $tmpFolder.'/.user.ini'); |
|
193 | 193 | \OC_Files::setUploadLimit( |
194 | 194 | \OCP\Util::computerFileSize('511MB'), |
195 | 195 | [ |
196 | - '.htaccess' => $tmpFolder . '/.htaccess', |
|
197 | - '.user.ini' => $tmpFolder . '/.user.ini', |
|
196 | + '.htaccess' => $tmpFolder.'/.htaccess', |
|
197 | + '.user.ini' => $tmpFolder.'/.user.ini', |
|
198 | 198 | ] |
199 | 199 | ); |
200 | 200 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | |
203 | 203 | // The .user.ini file can contain custom modifications to the file size |
204 | 204 | // as well. |
205 | - if($filename === $this->environmentHelper->getServerRoot() . '/.user.ini') { |
|
206 | - $fileContent = file_get_contents($tmpFolder . '/.user.ini'); |
|
205 | + if ($filename === $this->environmentHelper->getServerRoot().'/.user.ini') { |
|
206 | + $fileContent = file_get_contents($tmpFolder.'/.user.ini'); |
|
207 | 207 | $hashes[$relativeFileName] = hash('sha512', $fileContent); |
208 | 208 | continue; |
209 | 209 | } |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | // Thus we ignore everything below the first occurrence of |
216 | 216 | // "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####" and have the |
217 | 217 | // hash generated based on this. |
218 | - if($filename === $this->environmentHelper->getServerRoot() . '/.htaccess') { |
|
219 | - $fileContent = file_get_contents($tmpFolder . '/.htaccess'); |
|
218 | + if ($filename === $this->environmentHelper->getServerRoot().'/.htaccess') { |
|
219 | + $fileContent = file_get_contents($tmpFolder.'/.htaccess'); |
|
220 | 220 | $explodedArray = explode('#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####', $fileContent); |
221 | - if(count($explodedArray) === 2) { |
|
221 | + if (count($explodedArray) === 2) { |
|
222 | 222 | $hashes[$relativeFileName] = hash('sha512', $explodedArray[0]); |
223 | 223 | continue; |
224 | 224 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | public function writeAppSignature($path, |
268 | 268 | X509 $certificate, |
269 | 269 | RSA $privateKey) { |
270 | - $appInfoDir = $path . '/appinfo'; |
|
270 | + $appInfoDir = $path.'/appinfo'; |
|
271 | 271 | try { |
272 | 272 | $this->fileAccessHelper->assertDirectoryExists($appInfoDir); |
273 | 273 | |
@@ -275,12 +275,12 @@ discard block |
||
275 | 275 | $hashes = $this->generateHashes($iterator, $path); |
276 | 276 | $signature = $this->createSignatureData($hashes, $certificate, $privateKey); |
277 | 277 | $this->fileAccessHelper->file_put_contents( |
278 | - $appInfoDir . '/signature.json', |
|
278 | + $appInfoDir.'/signature.json', |
|
279 | 279 | json_encode($signature, JSON_PRETTY_PRINT) |
280 | 280 | ); |
281 | - } catch (\Exception $e){ |
|
281 | + } catch (\Exception $e) { |
|
282 | 282 | if (!$this->fileAccessHelper->is_writable($appInfoDir)) { |
283 | - throw new \Exception($appInfoDir . ' is not writable'); |
|
283 | + throw new \Exception($appInfoDir.' is not writable'); |
|
284 | 284 | } |
285 | 285 | throw $e; |
286 | 286 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | public function writeCoreSignature(X509 $certificate, |
298 | 298 | RSA $rsa, |
299 | 299 | $path) { |
300 | - $coreDir = $path . '/core'; |
|
300 | + $coreDir = $path.'/core'; |
|
301 | 301 | try { |
302 | 302 | |
303 | 303 | $this->fileAccessHelper->assertDirectoryExists($coreDir); |
@@ -305,12 +305,12 @@ discard block |
||
305 | 305 | $hashes = $this->generateHashes($iterator, $path); |
306 | 306 | $signatureData = $this->createSignatureData($hashes, $certificate, $rsa); |
307 | 307 | $this->fileAccessHelper->file_put_contents( |
308 | - $coreDir . '/signature.json', |
|
308 | + $coreDir.'/signature.json', |
|
309 | 309 | json_encode($signatureData, JSON_PRETTY_PRINT) |
310 | 310 | ); |
311 | - } catch (\Exception $e){ |
|
311 | + } catch (\Exception $e) { |
|
312 | 312 | if (!$this->fileAccessHelper->is_writable($coreDir)) { |
313 | - throw new \Exception($coreDir . ' is not writable'); |
|
313 | + throw new \Exception($coreDir.' is not writable'); |
|
314 | 314 | } |
315 | 315 | throw $e; |
316 | 316 | } |
@@ -327,12 +327,12 @@ discard block |
||
327 | 327 | * @throws \Exception |
328 | 328 | */ |
329 | 329 | private function verify($signaturePath, $basePath, $certificateCN) { |
330 | - if(!$this->isCodeCheckEnforced()) { |
|
330 | + if (!$this->isCodeCheckEnforced()) { |
|
331 | 331 | return []; |
332 | 332 | } |
333 | 333 | |
334 | 334 | $signatureData = json_decode($this->fileAccessHelper->file_get_contents($signaturePath), true); |
335 | - if(!is_array($signatureData)) { |
|
335 | + if (!is_array($signatureData)) { |
|
336 | 336 | throw new InvalidSignatureException('Signature data not found.'); |
337 | 337 | } |
338 | 338 | |
@@ -346,18 +346,18 @@ discard block |
||
346 | 346 | $rootCertificatePublicKey = $this->fileAccessHelper->file_get_contents($this->environmentHelper->getServerRoot().'/resources/codesigning/root.crt'); |
347 | 347 | $x509->loadCA($rootCertificatePublicKey); |
348 | 348 | $x509->loadX509($certificate); |
349 | - if(!$x509->validateSignature()) { |
|
349 | + if (!$x509->validateSignature()) { |
|
350 | 350 | // FIXME: Once Nextcloud has it's own appstore we should remove the ownCloud Root Authority from here |
351 | 351 | $x509 = new \phpseclib\File\X509(); |
352 | 352 | $rootCertificatePublicKey = $this->fileAccessHelper->file_get_contents($this->environmentHelper->getServerRoot().'/resources/codesigning/owncloud.crt'); |
353 | 353 | $x509->loadCA($rootCertificatePublicKey); |
354 | 354 | $x509->loadX509($certificate); |
355 | - if(!$x509->validateSignature()) { |
|
355 | + if (!$x509->validateSignature()) { |
|
356 | 356 | throw new InvalidSignatureException('Certificate is not valid.'); |
357 | 357 | } |
358 | 358 | } |
359 | 359 | // Verify if certificate has proper CN. "core" CN is always trusted. |
360 | - if($x509->getDN(X509::DN_OPENSSL)['CN'] !== $certificateCN && $x509->getDN(X509::DN_OPENSSL)['CN'] !== 'core') { |
|
360 | + if ($x509->getDN(X509::DN_OPENSSL)['CN'] !== $certificateCN && $x509->getDN(X509::DN_OPENSSL)['CN'] !== 'core') { |
|
361 | 361 | throw new InvalidSignatureException( |
362 | 362 | sprintf('Certificate is not valid for required scope. (Requested: %s, current: CN=%s)', $certificateCN, $x509->getDN(true)['CN']) |
363 | 363 | ); |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $rsa->setMGFHash('sha512'); |
371 | 371 | // See https://tools.ietf.org/html/rfc3447#page-38 |
372 | 372 | $rsa->setSaltLength(0); |
373 | - if(!$rsa->verify(json_encode($expectedHashes), $signature)) { |
|
373 | + if (!$rsa->verify(json_encode($expectedHashes), $signature)) { |
|
374 | 374 | throw new InvalidSignatureException('Signature could not get verified.'); |
375 | 375 | } |
376 | 376 | |
@@ -379,9 +379,9 @@ discard block |
||
379 | 379 | // |
380 | 380 | // Due to this reason we exclude the whole updater/ folder from the code |
381 | 381 | // integrity check. |
382 | - if($basePath === $this->environmentHelper->getServerRoot()) { |
|
383 | - foreach($expectedHashes as $fileName => $hash) { |
|
384 | - if(strpos($fileName, 'updater/') === 0) { |
|
382 | + if ($basePath === $this->environmentHelper->getServerRoot()) { |
|
383 | + foreach ($expectedHashes as $fileName => $hash) { |
|
384 | + if (strpos($fileName, 'updater/') === 0) { |
|
385 | 385 | unset($expectedHashes[$fileName]); |
386 | 386 | } |
387 | 387 | } |
@@ -393,23 +393,23 @@ discard block |
||
393 | 393 | $differencesB = array_diff($currentInstanceHashes, $expectedHashes); |
394 | 394 | $differences = array_unique(array_merge($differencesA, $differencesB)); |
395 | 395 | $differenceArray = []; |
396 | - foreach($differences as $filename => $hash) { |
|
396 | + foreach ($differences as $filename => $hash) { |
|
397 | 397 | // Check if file should not exist in the new signature table |
398 | - if(!array_key_exists($filename, $expectedHashes)) { |
|
398 | + if (!array_key_exists($filename, $expectedHashes)) { |
|
399 | 399 | $differenceArray['EXTRA_FILE'][$filename]['expected'] = ''; |
400 | 400 | $differenceArray['EXTRA_FILE'][$filename]['current'] = $hash; |
401 | 401 | continue; |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Check if file is missing |
405 | - if(!array_key_exists($filename, $currentInstanceHashes)) { |
|
405 | + if (!array_key_exists($filename, $currentInstanceHashes)) { |
|
406 | 406 | $differenceArray['FILE_MISSING'][$filename]['expected'] = $expectedHashes[$filename]; |
407 | 407 | $differenceArray['FILE_MISSING'][$filename]['current'] = ''; |
408 | 408 | continue; |
409 | 409 | } |
410 | 410 | |
411 | 411 | // Check if hash does mismatch |
412 | - if($expectedHashes[$filename] !== $currentInstanceHashes[$filename]) { |
|
412 | + if ($expectedHashes[$filename] !== $currentInstanceHashes[$filename]) { |
|
413 | 413 | $differenceArray['INVALID_HASH'][$filename]['expected'] = $expectedHashes[$filename]; |
414 | 414 | $differenceArray['INVALID_HASH'][$filename]['current'] = $currentInstanceHashes[$filename]; |
415 | 415 | continue; |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | */ |
430 | 430 | public function hasPassedCheck() { |
431 | 431 | $results = $this->getResults(); |
432 | - if(empty($results)) { |
|
432 | + if (empty($results)) { |
|
433 | 433 | return true; |
434 | 434 | } |
435 | 435 | |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function getResults() { |
443 | 443 | $cachedResults = $this->cache->get(self::CACHE_KEY); |
444 | - if(!is_null($cachedResults)) { |
|
444 | + if (!is_null($cachedResults)) { |
|
445 | 445 | return json_decode($cachedResults, true); |
446 | 446 | } |
447 | 447 | |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | private function storeResults($scope, array $result) { |
461 | 461 | $resultArray = $this->getResults(); |
462 | 462 | unset($resultArray[$scope]); |
463 | - if(!empty($result)) { |
|
463 | + if (!empty($result)) { |
|
464 | 464 | $resultArray[$scope] = $result; |
465 | 465 | } |
466 | 466 | if ($this->config !== null) { |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | */ |
513 | 513 | public function verifyAppSignature($appId, $path = '') { |
514 | 514 | try { |
515 | - if($path === '') { |
|
515 | + if ($path === '') { |
|
516 | 516 | $path = $this->appLocator->getAppPath($appId); |
517 | 517 | } |
518 | 518 | $result = $this->verify( |
519 | - $path . '/appinfo/signature.json', |
|
519 | + $path.'/appinfo/signature.json', |
|
520 | 520 | $path, |
521 | 521 | $appId |
522 | 522 | ); |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | public function verifyCoreSignature() { |
567 | 567 | try { |
568 | 568 | $result = $this->verify( |
569 | - $this->environmentHelper->getServerRoot() . '/core/signature.json', |
|
569 | + $this->environmentHelper->getServerRoot().'/core/signature.json', |
|
570 | 570 | $this->environmentHelper->getServerRoot(), |
571 | 571 | 'core' |
572 | 572 | ); |
@@ -591,18 +591,18 @@ discard block |
||
591 | 591 | $this->cleanResults(); |
592 | 592 | $this->verifyCoreSignature(); |
593 | 593 | $appIds = $this->appLocator->getAllApps(); |
594 | - foreach($appIds as $appId) { |
|
594 | + foreach ($appIds as $appId) { |
|
595 | 595 | // If an application is shipped a valid signature is required |
596 | 596 | $isShipped = $this->appManager->isShipped($appId); |
597 | 597 | $appNeedsToBeChecked = false; |
598 | 598 | if ($isShipped) { |
599 | 599 | $appNeedsToBeChecked = true; |
600 | - } elseif ($this->fileAccessHelper->file_exists($this->appLocator->getAppPath($appId) . '/appinfo/signature.json')) { |
|
600 | + } elseif ($this->fileAccessHelper->file_exists($this->appLocator->getAppPath($appId).'/appinfo/signature.json')) { |
|
601 | 601 | // Otherwise only if the application explicitly ships a signature.json file |
602 | 602 | $appNeedsToBeChecked = true; |
603 | 603 | } |
604 | 604 | |
605 | - if($appNeedsToBeChecked) { |
|
605 | + if ($appNeedsToBeChecked) { |
|
606 | 606 | $this->verifyAppSignature($appId); |
607 | 607 | } |
608 | 608 | } |
@@ -48,7 +48,7 @@ |
||
48 | 48 | * @return bool |
49 | 49 | */ |
50 | 50 | public function accept() { |
51 | - if($this->isDir()) { |
|
51 | + if ($this->isDir()) { |
|
52 | 52 | return true; |
53 | 53 | } |
54 | 54 |