Passed
Branch master (ff9d34)
by Mike
09:14
created
lib/core/zpush.php 1 patch
Braces   +121 added lines, -94 removed lines patch added patch discarded remove patch
@@ -161,19 +161,23 @@  discard block
 block discarded – undo
161 161
         }
162 162
 
163 163
         // some basic checks
164
-        if (!defined('BASE_PATH'))
165
-            throw new FatalMisconfigurationException("The BASE_PATH is not configured. Check if the config.php file is in place.");
164
+        if (!defined('BASE_PATH')) {
165
+                    throw new FatalMisconfigurationException("The BASE_PATH is not configured. Check if the config.php file is in place.");
166
+        }
166 167
 
167
-        if (substr(BASE_PATH, -1,1) != "/")
168
-            throw new FatalMisconfigurationException("The BASE_PATH should terminate with a '/'");
168
+        if (substr(BASE_PATH, -1,1) != "/") {
169
+                    throw new FatalMisconfigurationException("The BASE_PATH should terminate with a '/'");
170
+        }
169 171
 
170
-        if (!file_exists(BASE_PATH))
171
-            throw new FatalMisconfigurationException("The configured BASE_PATH does not exist or can not be accessed.");
172
+        if (!file_exists(BASE_PATH)) {
173
+                    throw new FatalMisconfigurationException("The configured BASE_PATH does not exist or can not be accessed.");
174
+        }
172 175
 
173
-        if (defined('BASE_PATH_CLI') && file_exists(BASE_PATH_CLI))
174
-            define('REAL_BASE_PATH', BASE_PATH_CLI);
175
-        else
176
-            define('REAL_BASE_PATH', BASE_PATH);
176
+        if (defined('BASE_PATH_CLI') && file_exists(BASE_PATH_CLI)) {
177
+                    define('REAL_BASE_PATH', BASE_PATH_CLI);
178
+        } else {
179
+                    define('REAL_BASE_PATH', BASE_PATH);
180
+        }
177 181
 
178 182
         if (!defined('LOGBACKEND')) {
179 183
             define('LOGBACKEND', 'filelog');
@@ -204,39 +208,42 @@  discard block
 block discarded – undo
204 208
             if (LOG_SYSLOG_HOST && LOG_SYSLOG_PORT <= 0) {
205 209
                 throw new FatalMisconfigurationException("LOG_SYSLOG_HOST is defined but the LOG_SYSLOG_PORT does not seem to be valid.");
206 210
             }
207
-        }
208
-        elseif (strtolower(LOGBACKEND) == 'filelog') {
211
+        } elseif (strtolower(LOGBACKEND) == 'filelog') {
209 212
             define('LOGBACKEND_CLASS', 'FileLog');
210
-            if (!defined('LOGFILEDIR'))
211
-                throw new FatalMisconfigurationException("The LOGFILEDIR is not configured. Check if the config.php file is in place.");
213
+            if (!defined('LOGFILEDIR')) {
214
+                            throw new FatalMisconfigurationException("The LOGFILEDIR is not configured. Check if the config.php file is in place.");
215
+            }
212 216
 
213
-            if (substr(LOGFILEDIR, -1,1) != "/")
214
-                throw new FatalMisconfigurationException("The LOGFILEDIR should terminate with a '/'");
217
+            if (substr(LOGFILEDIR, -1,1) != "/") {
218
+                            throw new FatalMisconfigurationException("The LOGFILEDIR should terminate with a '/'");
219
+            }
215 220
 
216
-            if (!file_exists(LOGFILEDIR))
217
-                throw new FatalMisconfigurationException("The configured LOGFILEDIR does not exist or can not be accessed.");
221
+            if (!file_exists(LOGFILEDIR)) {
222
+                            throw new FatalMisconfigurationException("The configured LOGFILEDIR does not exist or can not be accessed.");
223
+            }
218 224
 
219
-            if ((!file_exists(LOGFILE) && !touch(LOGFILE)) || !is_writable(LOGFILE))
220
-                throw new FatalMisconfigurationException("The configured LOGFILE can not be modified.");
225
+            if ((!file_exists(LOGFILE) && !touch(LOGFILE)) || !is_writable(LOGFILE)) {
226
+                            throw new FatalMisconfigurationException("The configured LOGFILE can not be modified.");
227
+            }
221 228
 
222
-            if ((!file_exists(LOGERRORFILE) && !touch(LOGERRORFILE)) || !is_writable(LOGERRORFILE))
223
-                throw new FatalMisconfigurationException("The configured LOGERRORFILE can not be modified.");
229
+            if ((!file_exists(LOGERRORFILE) && !touch(LOGERRORFILE)) || !is_writable(LOGERRORFILE)) {
230
+                            throw new FatalMisconfigurationException("The configured LOGERRORFILE can not be modified.");
231
+            }
224 232
 
225 233
             // check ownership on the (eventually) just created files
226 234
             Utils::FixFileOwner(LOGFILE);
227 235
             Utils::FixFileOwner(LOGERRORFILE);
228
-        }
229
-        else {
236
+        } else {
230 237
             define('LOGBACKEND_CLASS', LOGBACKEND);
231 238
         }
232 239
 
233 240
         // set time zone
234 241
         // code contributed by Robert Scheck (rsc)
235 242
         if(defined('TIMEZONE') ? constant('TIMEZONE') : false) {
236
-            if (! @date_default_timezone_set(TIMEZONE))
237
-                throw new FatalMisconfigurationException(sprintf("The configured TIMEZONE '%s' is not valid. Please check supported timezones at http://www.php.net/manual/en/timezones.php", constant('TIMEZONE')));
238
-        }
239
-        else if(!ini_get('date.timezone')) {
243
+            if (! @date_default_timezone_set(TIMEZONE)) {
244
+                            throw new FatalMisconfigurationException(sprintf("The configured TIMEZONE '%s' is not valid. Please check supported timezones at http://www.php.net/manual/en/timezones.php", constant('TIMEZONE')));
245
+            }
246
+        } else if(!ini_get('date.timezone')) {
240 247
             date_default_timezone_set('Europe/Vienna');
241 248
         }
242 249
 
@@ -267,14 +274,15 @@  discard block
 block discarded – undo
267 274
     static public function CheckAdvancedConfig() {
268 275
         global $specialLogUsers, $additionalFolders;
269 276
 
270
-        if (!is_array($specialLogUsers))
271
-            throw new FatalMisconfigurationException("The WBXML log users is not an array.");
277
+        if (!is_array($specialLogUsers)) {
278
+                    throw new FatalMisconfigurationException("The WBXML log users is not an array.");
279
+        }
272 280
 
273 281
         if (!defined('SYNC_CONTACTS_MAXPICTURESIZE')) {
274 282
             define('SYNC_CONTACTS_MAXPICTURESIZE', 49152);
283
+        } else if ((!is_int(SYNC_CONTACTS_MAXPICTURESIZE) || SYNC_CONTACTS_MAXPICTURESIZE < 1)) {
284
+                    throw new FatalMisconfigurationException("The SYNC_CONTACTS_MAXPICTURESIZE value must be a number higher than 0.");
275 285
         }
276
-        else if ((!is_int(SYNC_CONTACTS_MAXPICTURESIZE) || SYNC_CONTACTS_MAXPICTURESIZE < 1))
277
-            throw new FatalMisconfigurationException("The SYNC_CONTACTS_MAXPICTURESIZE value must be a number higher than 0.");
278 286
 
279 287
         if (!defined('USE_PARTIAL_FOLDERSYNC')) {
280 288
             define('USE_PARTIAL_FOLDERSYNC', false);
@@ -282,14 +290,12 @@  discard block
 block discarded – undo
282 290
 
283 291
         if (!defined('PING_LOWER_BOUND_LIFETIME')) {
284 292
             define('PING_LOWER_BOUND_LIFETIME', false);
285
-        }
286
-        elseif(PING_LOWER_BOUND_LIFETIME !== false && (!is_int(PING_LOWER_BOUND_LIFETIME) || PING_LOWER_BOUND_LIFETIME < 1 || PING_LOWER_BOUND_LIFETIME > 3540)){
293
+        } elseif(PING_LOWER_BOUND_LIFETIME !== false && (!is_int(PING_LOWER_BOUND_LIFETIME) || PING_LOWER_BOUND_LIFETIME < 1 || PING_LOWER_BOUND_LIFETIME > 3540)){
287 294
             throw new FatalMisconfigurationException("The PING_LOWER_BOUND_LIFETIME value must be 'false' or a number between 1 and 3540 inclusively.");
288 295
         }
289 296
         if (!defined('PING_HIGHER_BOUND_LIFETIME')) {
290 297
             define('PING_HIGHER_BOUND_LIFETIME', false);
291
-        }
292
-        elseif(PING_HIGHER_BOUND_LIFETIME !== false && (!is_int(PING_HIGHER_BOUND_LIFETIME) || PING_HIGHER_BOUND_LIFETIME < 1 || PING_HIGHER_BOUND_LIFETIME > 3540)){
298
+        } elseif(PING_HIGHER_BOUND_LIFETIME !== false && (!is_int(PING_HIGHER_BOUND_LIFETIME) || PING_HIGHER_BOUND_LIFETIME < 1 || PING_HIGHER_BOUND_LIFETIME > 3540)){
293 299
             throw new FatalMisconfigurationException("The PING_HIGHER_BOUND_LIFETIME value must be 'false' or a number between 1 and 3540 inclusively.");
294 300
         }
295 301
         if(PING_HIGHER_BOUND_LIFETIME !== false && PING_LOWER_BOUND_LIFETIME !== false && PING_HIGHER_BOUND_LIFETIME < PING_LOWER_BOUND_LIFETIME){
@@ -298,8 +304,7 @@  discard block
 block discarded – undo
298 304
 
299 305
         if (!defined('RETRY_AFTER_DELAY')) {
300 306
             define('RETRY_AFTER_DELAY', 300);
301
-        }
302
-        elseif (RETRY_AFTER_DELAY !== false && (!is_int(RETRY_AFTER_DELAY) || RETRY_AFTER_DELAY < 1))  {
307
+        } elseif (RETRY_AFTER_DELAY !== false && (!is_int(RETRY_AFTER_DELAY) || RETRY_AFTER_DELAY < 1))  {
303 308
             throw new FatalMisconfigurationException("The RETRY_AFTER_DELAY value must be 'false' or a number greater than 0.");
304 309
         }
305 310
 
@@ -312,9 +317,9 @@  discard block
 block discarded – undo
312 317
         }
313 318
 
314 319
         // the check on additional folders will not throw hard errors, as this is probably changed on live systems
315
-        if (isset($additionalFolders) && !is_array($additionalFolders))
316
-            ZLog::Write(LOGLEVEL_ERROR, "ZPush::CheckConfig() : The additional folders synchronization not available as array.");
317
-        else {
320
+        if (isset($additionalFolders) && !is_array($additionalFolders)) {
321
+                    ZLog::Write(LOGLEVEL_ERROR, "ZPush::CheckConfig() : The additional folders synchronization not available as array.");
322
+        } else {
318 323
             // check configured data
319 324
             foreach ($additionalFolders as $af) {
320 325
 
@@ -358,7 +363,9 @@  discard block
 block discarded – undo
358 363
             ZPush::$stateMachine = self::GetBackend()->GetStateMachine();
359 364
 
360 365
             if (ZPush::$stateMachine->GetStateVersion() !== ZPush::GetLatestStateVersion()) {
361
-                if (class_exists("TopCollector")) self::GetTopCollector()->AnnounceInformation("Run migration script!", true);
366
+                if (class_exists("TopCollector")) {
367
+                    self::GetTopCollector()->AnnounceInformation("Run migration script!", true);
368
+                }
362 369
                 throw new ServiceUnavailableException(sprintf("The state version available to the %s is not the latest version - please run the state upgrade script. See release notes for more information.", get_class(ZPush::$stateMachine)));
363 370
             }
364 371
         }
@@ -373,8 +380,9 @@  discard block
 block discarded – undo
373 380
      * @return object Redis
374 381
      */
375 382
     static public function GetRedis() {
376
-        if (!isset(ZPush::$redis))
377
-            ZPush::$redis = new RedisConnection();
383
+        if (!isset(ZPush::$redis)) {
384
+                    ZPush::$redis = new RedisConnection();
385
+        }
378 386
 
379 387
         return ZPush::$redis;
380 388
     }
@@ -412,8 +420,9 @@  discard block
 block discarded – undo
412 420
      * @return object DeviceManager
413 421
      */
414 422
     static public function GetDeviceManager($initialize = true) {
415
-        if (!isset(ZPush::$deviceManager) && $initialize)
416
-            ZPush::$deviceManager = new DeviceManager();
423
+        if (!isset(ZPush::$deviceManager) && $initialize) {
424
+                    ZPush::$deviceManager = new DeviceManager();
425
+        }
417 426
 
418 427
         return ZPush::$deviceManager;
419 428
     }
@@ -425,8 +434,9 @@  discard block
 block discarded – undo
425 434
      * @return object TopCollector
426 435
      */
427 436
     static public function GetTopCollector() {
428
-        if (!isset(ZPush::$topCollector))
429
-            ZPush::$topCollector = new TopCollector();
437
+        if (!isset(ZPush::$topCollector)) {
438
+                    ZPush::$topCollector = new TopCollector();
439
+        }
430 440
 
431 441
         return ZPush::$topCollector;
432 442
     }
@@ -441,23 +451,27 @@  discard block
 block discarded – undo
441 451
      * @return boolean
442 452
      */
443 453
     static public function IncludeBackend($backendname) {
444
-        if ($backendname == false) return false;
454
+        if ($backendname == false) {
455
+            return false;
456
+        }
445 457
 
446 458
         $backendname = strtolower($backendname);
447
-        if (substr($backendname, 0, 7) !== 'backend')
448
-            throw new FatalNotImplementedException(sprintf("Backend '%s' is not allowed",$backendname));
459
+        if (substr($backendname, 0, 7) !== 'backend') {
460
+                    throw new FatalNotImplementedException(sprintf("Backend '%s' is not allowed",$backendname));
461
+        }
449 462
 
450 463
         $rbn = substr($backendname, 7);
451 464
 
452 465
         $subdirbackend = REAL_BASE_PATH . "backend/" . $rbn . "/" . $rbn . ".php";
453 466
         $stdbackend = REAL_BASE_PATH . "backend/" . $rbn . ".php";
454 467
 
455
-        if (is_file($subdirbackend))
456
-            $toLoad = $subdirbackend;
457
-        else if (is_file($stdbackend))
458
-            $toLoad = $stdbackend;
459
-        else
460
-            return false;
468
+        if (is_file($subdirbackend)) {
469
+                    $toLoad = $subdirbackend;
470
+        } else if (is_file($stdbackend)) {
471
+                    $toLoad = $stdbackend;
472
+        } else {
473
+                    return false;
474
+        }
461 475
 
462 476
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("Including backend file: '%s'", $toLoad));
463 477
         return include_once($toLoad);
@@ -518,16 +532,16 @@  discard block
 block discarded – undo
518 532
     static public function GetAdditionalSyncFolderStore($backendid, $noDebug = false) {
519 533
         if(isset(self::getAddSyncFolders()[$backendid]->Store)) {
520 534
             $val = self::getAddSyncFolders()[$backendid]->Store;
521
-        }
522
-        else {
535
+        } else {
523 536
             $val = self::GetDeviceManager()->GetAdditionalUserSyncFolder($backendid);
524 537
             if (isset($val['store'])) {
525 538
                 $val = $val['store'];
526 539
             }
527 540
         }
528 541
 
529
-        if (!$noDebug)
530
-            ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPush::GetAdditionalSyncFolderStore('%s'): '%s'", $backendid, Utils::PrintAsString($val)));
542
+        if (!$noDebug) {
543
+                    ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPush::GetAdditionalSyncFolderStore('%s'): '%s'", $backendid, Utils::PrintAsString($val)));
544
+        }
531 545
         return $val;
532 546
     }
533 547
 
@@ -541,14 +555,16 @@  discard block
 block discarded – undo
541 555
      * @throws FatalNotImplementedException
542 556
      */
543 557
     static public function getSyncObjectFromFolderClass($folderclass) {
544
-        if (!isset(self::$classes[$folderclass]))
545
-            throw new FatalNotImplementedException("Class '$folderclass' is not supported");
558
+        if (!isset(self::$classes[$folderclass])) {
559
+                    throw new FatalNotImplementedException("Class '$folderclass' is not supported");
560
+        }
546 561
 
547 562
         $class = self::$classes[$folderclass][self::CLASS_NAME];
548
-        if (self::$classes[$folderclass][self::CLASS_REQUIRESPROTOCOLVERSION])
549
-            return new $class(Request::GetProtocolVersion());
550
-        else
551
-            return new $class();
563
+        if (self::$classes[$folderclass][self::CLASS_REQUIRESPROTOCOLVERSION]) {
564
+                    return new $class(Request::GetProtocolVersion());
565
+        } else {
566
+                    return new $class();
567
+        }
552 568
     }
553 569
 
554 570
     /**
@@ -565,8 +581,7 @@  discard block
 block discarded – undo
565 581
 
566 582
             if (isset($additionalFolders) && !is_array($additionalFolders)) {
567 583
                 ZLog::Write(LOGLEVEL_ERROR, "ZPush::getAddSyncFolders() : The additional folders synchronization not available as array.");
568
-            }
569
-            else {
584
+            } else {
570 585
                 foreach ($additionalFolders as $af) {
571 586
                     if (!is_array($af) || !isset($af['store']) || !isset($af['folderid']) || !isset($af['name']) || !isset($af['type'])) {
572 587
                         ZLog::Write(LOGLEVEL_ERROR, "ZPush::getAddSyncFolders() : the additional folder synchronization is not configured correctly. Missing parameters. Entry will be ignored.");
@@ -644,10 +659,12 @@  discard block
 block discarded – undo
644 659
     static public function PrintGrommunioSyncLegal($message = "", $additionalMessage = "") {
645 660
         ZLog::Write(LOGLEVEL_DEBUG,"ZPush::PrintGrommunioSyncLegal()");
646 661
 
647
-        if ($message)
648
-            $message = "<h3>". $message . "</h3>";
649
-        if ($additionalMessage)
650
-            $additionalMessage .= "<br>";
662
+        if ($message) {
663
+                    $message = "<h3>". $message . "</h3>";
664
+        }
665
+        if ($additionalMessage) {
666
+                    $additionalMessage .= "<br>";
667
+        }
651 668
 
652 669
         header("Content-type: text/html");
653 670
         print <<<END
@@ -687,8 +704,9 @@  discard block
 block discarded – undo
687 704
      */
688 705
     static public function GetSupportedASVersion() {
689 706
         $version = self::GetBackend()->GetSupportedASVersion();
690
-        if (!in_array($version, self::$supportedASVersions))
691
-            throw new FatalNotImplementedException(sprintf("AS version '%s' reported by the backend is not supported", $version));
707
+        if (!in_array($version, self::$supportedASVersions)) {
708
+                    throw new FatalNotImplementedException(sprintf("AS version '%s' reported by the backend is not supported", $version));
709
+        }
692 710
 
693 711
         return $version;
694 712
     }
@@ -700,10 +718,11 @@  discard block
 block discarded – undo
700 718
      * @return string
701 719
      */
702 720
     static public function GetServerHeader() {
703
-        if (self::GetSupportedASVersion() == self::ASV_25)
704
-            return "MS-Server-ActiveSync: 6.5.7638.1";
705
-        else
706
-            return "MS-Server-ActiveSync: ". self::GetSupportedASVersion();
721
+        if (self::GetSupportedASVersion() == self::ASV_25) {
722
+                    return "MS-Server-ActiveSync: 6.5.7638.1";
723
+        } else {
724
+                    return "MS-Server-ActiveSync: ". self::GetSupportedASVersion();
725
+        }
707 726
     }
708 727
 
709 728
     /**
@@ -718,8 +737,9 @@  discard block
 block discarded – undo
718 737
         $versions = implode(',', array_slice(self::$supportedASVersions, 0, (array_search(self::GetSupportedASVersion(), self::$supportedASVersions)+1)));
719 738
         ZLog::Write(LOGLEVEL_DEBUG, "ZPush::GetSupportedProtocolVersions(): " . $versions);
720 739
 
721
-        if ($valueOnly === true)
722
-            return $versions;
740
+        if ($valueOnly === true) {
741
+                    return $versions;
742
+        }
723 743
 
724 744
         return "MS-ASProtocolVersions: " . $versions;
725 745
     }
@@ -733,10 +753,11 @@  discard block
 block discarded – undo
733 753
     static public function GetSupportedCommands() {
734 754
         $asCommands = array();
735 755
         // filter all non-activesync commands
736
-        foreach (self::$supportedCommands as $c=>$v)
737
-            if (!self::checkCommandOptions($c, self::NOACTIVESYNCCOMMAND) &&
756
+        foreach (self::$supportedCommands as $c=>$v) {
757
+                    if (!self::checkCommandOptions($c, self::NOACTIVESYNCCOMMAND) &&
738 758
                 self::checkCommandOptions($c, self::GetSupportedASVersion()))
739 759
                 $asCommands[] = Utils::GetCommandFromCode($c);
760
+        }
740 761
 
741 762
         $commands = implode(',', $asCommands);
742 763
         ZLog::Write(LOGLEVEL_DEBUG, "ZPush::GetSupportedCommands(): " . $commands);
@@ -753,19 +774,22 @@  discard block
 block discarded – undo
753 774
      */
754 775
     static public function GetRequestHandlerForCommand($commandCode) {
755 776
         if (!array_key_exists($commandCode, self::$supportedCommands) ||
756
-            !array_key_exists(self::REQUESTHANDLER, self::$supportedCommands[$commandCode]) )
757
-            throw new FatalNotImplementedException(sprintf("Command '%s' has no request handler or class", Utils::GetCommandFromCode($commandCode)));
777
+            !array_key_exists(self::REQUESTHANDLER, self::$supportedCommands[$commandCode]) ) {
778
+                    throw new FatalNotImplementedException(sprintf("Command '%s' has no request handler or class", Utils::GetCommandFromCode($commandCode)));
779
+        }
758 780
 
759 781
         $class = self::$supportedCommands[$commandCode][self::REQUESTHANDLER];
760 782
         $handlerclass = REAL_BASE_PATH . "lib/request/" . strtolower($class) . ".php";
761 783
 
762
-        if (is_file($handlerclass))
763
-            include($handlerclass);
784
+        if (is_file($handlerclass)) {
785
+                    include($handlerclass);
786
+        }
764 787
 
765
-        if (class_exists($class))
766
-            return new $class();
767
-        else
768
-            throw new FatalNotImplementedException(sprintf("Request handler '%s' can not be loaded", $class));
788
+        if (class_exists($class)) {
789
+                    return new $class();
790
+        } else {
791
+                    throw new FatalNotImplementedException(sprintf("Request handler '%s' can not be loaded", $class));
792
+        }
769 793
     }
770 794
 
771 795
     /**
@@ -835,10 +859,13 @@  discard block
 block discarded – undo
835 859
      * @return object StateMachine
836 860
      */
837 861
     static private function checkCommandOptions($commandCode, $option) {
838
-        if ($commandCode === false) return false;
862
+        if ($commandCode === false) {
863
+            return false;
864
+        }
839 865
 
840
-        if (!array_key_exists($commandCode, self::$supportedCommands))
841
-            throw new FatalNotImplementedException(sprintf("Command '%s' is not supported", Utils::GetCommandFromCode($commandCode)));
866
+        if (!array_key_exists($commandCode, self::$supportedCommands)) {
867
+                    throw new FatalNotImplementedException(sprintf("Command '%s' is not supported", Utils::GetCommandFromCode($commandCode)));
868
+        }
842 869
 
843 870
         $capa = self::$supportedCommands[$commandCode];
844 871
         $defcapa = in_array($option, $capa, true);
Please login to merge, or discard this patch.
lib/core/devicemanager.php 1 patch
Braces   +69 added lines, -56 removed lines patch added patch discarded remove patch
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
             $this->loadDeviceData();
77 77
 
78 78
             ZPush::GetTopCollector()->SetUserAgent($this->device->GetDeviceUserAgent());
79
+        } else {
80
+                    throw new FatalNotImplementedException("Can not proceed without a device id.");
79 81
         }
80
-        else
81
-            throw new FatalNotImplementedException("Can not proceed without a device id.");
82 82
 
83 83
         $this->loopdetection = new LoopDetection();
84 84
         $this->loopdetection->ProcessLoopDetectionInit();
@@ -139,8 +139,9 @@  discard block
 block discarded – undo
139 139
 
140 140
         // check if previousily ignored messages were synchronized for the current folder
141 141
         // on multifolder operations of AS14 this is done by setLatestFolder()
142
-        if ($this->latestFolder !== false)
143
-            $this->checkBrokenMessages($this->latestFolder);
142
+        if ($this->latestFolder !== false) {
143
+                    $this->checkBrokenMessages($this->latestFolder);
144
+        }
144 145
 
145 146
         // update the user agent and AS version on the device
146 147
         $this->device->SetUserAgent(Request::GetUserAgent());
@@ -166,8 +167,7 @@  discard block
 block discarded – undo
166 167
                     $this->setDeviceUserData($this->type, array(self::$user => $this->device), self::$devid, -1, $doCas="merge");
167 168
                     ZLog::Write(LOGLEVEL_DEBUG, "DeviceManager->Save(): Device data saved");
168 169
                 }
169
-            }
170
-            catch (StateNotFoundException $snfex) {
170
+            } catch (StateNotFoundException $snfex) {
171 171
                 ZLog::Write(LOGLEVEL_ERROR, "DeviceManager->Save(): Exception: ". $snfex->getMessage());
172 172
             }
173 173
         }
@@ -179,8 +179,9 @@  discard block
 block discarded – undo
179 179
         }
180 180
 
181 181
         // we terminated this process
182
-        if ($this->loopdetection)
183
-            $this->loopdetection->ProcessLoopDetectionTerminate();
182
+        if ($this->loopdetection) {
183
+                    $this->loopdetection->ProcessLoopDetectionTerminate();
184
+        }
184 185
 
185 186
         return true;
186 187
     }
@@ -211,8 +212,9 @@  discard block
 block discarded – undo
211 212
         ZLog::Write(LOGLEVEL_DEBUG, "Saving submitted device information");
212 213
 
213 214
         // set the user agent
214
-        if (isset($deviceinformation->useragent))
215
-            $this->device->SetUserAgent($deviceinformation->useragent);
215
+        if (isset($deviceinformation->useragent)) {
216
+                    $this->device->SetUserAgent($deviceinformation->useragent);
217
+        }
216 218
 
217 219
         // save other information
218 220
         foreach (array("model", "imei", "friendlyname", "os", "oslanguage", "phonenumber", "mobileoperator", "enableoutboundsms") as $info) {
@@ -294,8 +296,9 @@  discard block
 block discarded – undo
294 296
             // Old Palm Treos always do initial sync for calendar and contacts, even if they are not made available by the backend.
295 297
             // We need to fake these folderids, allowing a fake sync/ping, even if they are not supported by the backend
296 298
             // if the folderid would be available, they would already be returned in the above statement
297
-            if ($folderidforClass == false && ($type == SYNC_FOLDER_TYPE_APPOINTMENT || $type == SYNC_FOLDER_TYPE_CONTACT))
298
-                $folderidforClass = SYNC_FOLDER_TYPE_DUMMY;
299
+            if ($folderidforClass == false && ($type == SYNC_FOLDER_TYPE_APPOINTMENT || $type == SYNC_FOLDER_TYPE_CONTACT)) {
300
+                            $folderidforClass = SYNC_FOLDER_TYPE_DUMMY;
301
+            }
299 302
         }
300 303
 
301 304
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("DeviceManager->GetFolderIdFromCacheByClass('%s'): '%s' => '%s'", $class, $type, $folderidforClass));
@@ -314,12 +317,14 @@  discard block
 block discarded – undo
314 317
     public function GetFolderClassFromCacheByID($folderid) {
315 318
         //TODO check if the parent folder exists and is also being synchronized
316 319
         $typeFromCache = $this->device->GetFolderType($folderid);
317
-        if ($typeFromCache === false)
318
-            throw new NoHierarchyCacheAvailableException(sprintf("Folderid '%s' is not fully synchronized on the device", $folderid));
320
+        if ($typeFromCache === false) {
321
+                    throw new NoHierarchyCacheAvailableException(sprintf("Folderid '%s' is not fully synchronized on the device", $folderid));
322
+        }
319 323
 
320 324
         $class = ZPush::GetFolderClassFromFolderType($typeFromCache);
321
-        if ($class === false)
322
-            throw new NotImplementedException(sprintf("Folderid '%s' is saved to be of type '%d' but this type is not implemented", $folderid, $typeFromCache));
325
+        if ($class === false) {
326
+                    throw new NotImplementedException(sprintf("Folderid '%s' is saved to be of type '%d' but this type is not implemented", $folderid, $typeFromCache));
327
+        }
323 328
 
324 329
         return $class;
325 330
     }
@@ -386,8 +391,9 @@  discard block
 block discarded – undo
386 391
     public function DoNotStreamMessage($id, &$message) {
387 392
         $folderid = $this->getLatestFolder();
388 393
 
389
-        if (isset($message->parentid))
390
-            $folder = $message->parentid;
394
+        if (isset($message->parentid)) {
395
+                    $folder = $message->parentid;
396
+        }
391 397
 
392 398
         // message was identified to be causing a loop
393 399
         if ($this->loopdetection->IgnoreNextMessage(true, $id, $folderid)) {
@@ -439,10 +445,12 @@  discard block
 block discarded – undo
439 445
      * @return int
440 446
      */
441 447
     public function GetWindowSize($folderid, $uuid, $statecounter, $queuedmessages) {
442
-        if (isset($this->windowSize[$folderid]))
443
-            $items = $this->windowSize[$folderid];
444
-        else
445
-            $items = WINDOW_SIZE_MAX; // 512 by default
448
+        if (isset($this->windowSize[$folderid])) {
449
+                    $items = $this->windowSize[$folderid];
450
+        } else {
451
+                    $items = WINDOW_SIZE_MAX;
452
+        }
453
+        // 512 by default
446 454
 
447 455
         $this->setLatestFolder($folderid);
448 456
 
@@ -451,16 +459,16 @@  discard block
 block discarded – undo
451 459
         if ($loop !== false) {
452 460
             if ($loop === true) {
453 461
                 $items = ($items == 0) ? 0: 1+($this->loopdetection->IgnoreNextMessage(false)?1:0) ;
454
-            }
455
-            else {
462
+            } else {
456 463
                 // we got a new suggested window size
457 464
                 $items = $loop;
458 465
                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("Mobile loop pre stage detected! Forcing smaller window size of %d before entering loop detection mode", $items));
459 466
             }
460 467
         }
461 468
 
462
-        if ($items >= 0 && $items <= 2)
463
-            ZLog::Write(LOGLEVEL_WARN, sprintf("Mobile loop detected! Messages sent to the mobile will be restricted to %d items in order to identify the conflict", $items));
469
+        if ($items >= 0 && $items <= 2) {
470
+                    ZLog::Write(LOGLEVEL_WARN, sprintf("Mobile loop detected! Messages sent to the mobile will be restricted to %d items in order to identify the conflict", $items));
471
+        }
464 472
 
465 473
         return $items;
466 474
     }
@@ -536,8 +544,7 @@  discard block
 block discarded – undo
536 544
                 // do not limit when the owner or impersonated user is syncing!
537 545
                 if ($origin == DeviceManager::FLD_ORIGIN_USER || $origin == DeviceManager::FLD_ORIGIN_IMPERSONATED) {
538 546
                     ZLog::Write(LOGLEVEL_DEBUG, "Not checking for specific sync limit as this is the owner/impersonated user.");
539
-                }
540
-                else {
547
+                } else {
541 548
                     $spKey = false;
542 549
                     $spFilter = false;
543 550
                     // 1. step: check if there is a general limitation for the store
@@ -598,8 +605,9 @@  discard block
 block discarded – undo
598 605
         ZLog::Write(LOGLEVEL_INFO, "Full device resync requested");
599 606
 
600 607
         // delete all other uuids
601
-        foreach ($this->device->GetAllFolderIds() as $folderid)
602
-            $uuid = StateManager::UnLinkState($this->device, $folderid);
608
+        foreach ($this->device->GetAllFolderIds() as $folderid) {
609
+                    $uuid = StateManager::UnLinkState($this->device, $folderid);
610
+        }
603 611
 
604 612
         // delete hierarchy states
605 613
         StateManager::UnLinkState($this->device, false);
@@ -627,8 +635,9 @@  discard block
 block discarded – undo
627 635
         }
628 636
 
629 637
         // check if a hierarchy sync might be necessary
630
-        if ($this->device->GetFolderUUID(false) === false)
631
-            $this->hierarchySyncRequired = true;
638
+        if ($this->device->GetFolderUUID(false) === false) {
639
+                    $this->hierarchySyncRequired = true;
640
+        }
632 641
 
633 642
         return $this->hierarchySyncRequired;
634 643
     }
@@ -915,13 +924,15 @@  discard block
 block discarded – undo
915 924
      * @return boolean
916 925
      */
917 926
     private function loadDeviceData() {
918
-        if (!Request::IsValidDeviceID())
919
-            return false;
927
+        if (!Request::IsValidDeviceID()) {
928
+                    return false;
929
+        }
920 930
         try {
921 931
             $deviceHash = $this->statemachine->GetStateHash(self::$devid, IStateMachine::DEVICEDATA);
922 932
             if ($deviceHash != $this->deviceHash) {
923
-                if ($this->deviceHash)
924
-                    ZLog::Write(LOGLEVEL_DEBUG, "DeviceManager->loadDeviceData(): Device data was changed, reloading");
933
+                if ($this->deviceHash) {
934
+                                    ZLog::Write(LOGLEVEL_DEBUG, "DeviceManager->loadDeviceData(): Device data was changed, reloading");
935
+                }
925 936
                 $device = $this->statemachine->GetState(self::$devid, IStateMachine::DEVICEDATA);
926 937
                 // TODO: case should be removed when removing ASDevice backwards compatibility
927 938
                 // fallback for old grosync like devicedata
@@ -932,8 +943,7 @@  discard block
 block discarded – undo
932 943
                         ZLog::Write(LOGLEVEL_INFO, "Using old style device for this request and updating when concluding");
933 944
                         $device = $device->devices[$_deviceuser];
934 945
                         $device->lastupdatetime = time();
935
-                    }
936
-                    else {
946
+                    } else {
937 947
                         ZLog::Write(LOGLEVEL_WARN, sprintf("Could not find '%s' in device state. Dropping previous device state!", $_deviceuser));
938 948
                     }
939 949
                 }
@@ -941,17 +951,14 @@  discard block
 block discarded – undo
941 951
                     $this->device = $device;
942 952
                     $this->device->LoadedDevice();
943 953
                     $this->deviceHash = $deviceHash;
944
-                }
945
-                else {
954
+                } else {
946 955
                     ZLog::Write(LOGLEVEL_WARN, "Loaded device is not a device object. Dropping new loaded state and keeping initialized object!");
947 956
                 }
948 957
                 $this->stateManager->SetDevice($this->device);
949 958
             }
950
-        }
951
-        catch (StateNotFoundException $snfex) {
959
+        } catch (StateNotFoundException $snfex) {
952 960
             $this->hierarchySyncRequired = true;
953
-        }
954
-        catch (UnavailableException $uaex) {
961
+        } catch (UnavailableException $uaex) {
955 962
             // This is temporary and can be ignored e.g. in PING - see https://jira.z-hub.io/browse/ZP-1054
956 963
             // If the hash was not available before we treat it like a StateNotFoundException.
957 964
             if ($this->deviceHash === false) {
@@ -974,8 +981,9 @@  discard block
 block discarded – undo
974 981
      * @return boolean
975 982
      */
976 983
     public function AnnounceIgnoredMessage($folderid, $id, SyncObject $message, $reason = self::MSG_BROKEN_UNKNOWN) {
977
-        if ($folderid === false)
978
-            $folderid = $this->getLatestFolder();
984
+        if ($folderid === false) {
985
+                    $folderid = $this->getLatestFolder();
986
+        }
979 987
 
980 988
         $class = get_class($message);
981 989
 
@@ -988,14 +996,18 @@  discard block
 block discarded – undo
988 996
         $brokenMessage->reasonString = 'unknown cause';
989 997
         $brokenMessage->timestamp = time();
990 998
         $info = "";
991
-        if (isset($message->subject))
992
-            $info .= sprintf("Subject: '%s'", $message->subject);
993
-        if (isset($message->fileas))
994
-            $info .= sprintf("FileAs: '%s'", $message->fileas);
995
-        if (isset($message->from))
996
-            $info .= sprintf(" - From: '%s'", $message->from);
997
-        if (isset($message->starttime))
998
-            $info .= sprintf(" - On: '%s'", strftime("%Y-%m-%d %H:%M", $message->starttime));
999
+        if (isset($message->subject)) {
1000
+                    $info .= sprintf("Subject: '%s'", $message->subject);
1001
+        }
1002
+        if (isset($message->fileas)) {
1003
+                    $info .= sprintf("FileAs: '%s'", $message->fileas);
1004
+        }
1005
+        if (isset($message->from)) {
1006
+                    $info .= sprintf(" - From: '%s'", $message->from);
1007
+        }
1008
+        if (isset($message->starttime)) {
1009
+                    $info .= sprintf(" - On: '%s'", strftime("%Y-%m-%d %H:%M", $message->starttime));
1010
+        }
999 1011
         $brokenMessage->info = $info;
1000 1012
         $brokenMessage->reasonString = ZLog::GetLastMessage(LOGLEVEL_WARN);
1001 1013
 
@@ -1052,8 +1064,9 @@  discard block
 block discarded – undo
1052 1064
     private function setLatestFolder($folderid) {
1053 1065
         // this is a multi folder operation
1054 1066
         // check on ignoredmessages before discaring the folderid
1055
-        if ($this->latestFolder !== false)
1056
-            $this->checkBrokenMessages($this->latestFolder);
1067
+        if ($this->latestFolder !== false) {
1068
+                    $this->checkBrokenMessages($this->latestFolder);
1069
+        }
1057 1070
 
1058 1071
         $this->latestFolder = $folderid;
1059 1072
 
Please login to merge, or discard this patch.
lib/core/streamimporter.php 1 patch
Braces   +24 added lines, -15 removed lines patch added patch discarded remove patch
@@ -76,17 +76,25 @@  discard block
 block discarded – undo
76 76
             return $stat;
77 77
         }
78 78
 
79
-        if ($message->flags === false || $message->flags === SYNC_NEWMESSAGE)
80
-            $this->encoder->startTag(SYNC_ADD);
81
-        else {
79
+        if ($message->flags === false || $message->flags === SYNC_NEWMESSAGE) {
80
+                    $this->encoder->startTag(SYNC_ADD);
81
+        } else {
82 82
             // on update of an SyncEmail we only export the flags and categories
83 83
             if($message instanceof SyncMail && ((isset($message->flag) && $message->flag instanceof SyncMailFlags) || isset($message->categories))) {
84 84
                 $newmessage = new SyncMail();
85 85
                 $newmessage->read = $message->read;
86
-                if (isset($message->flag))              $newmessage->flag = $message->flag;
87
-                if (isset($message->lastverbexectime))  $newmessage->lastverbexectime = $message->lastverbexectime;
88
-                if (isset($message->lastverbexecuted))  $newmessage->lastverbexecuted = $message->lastverbexecuted;
89
-                if (isset($message->categories))        $newmessage->categories = $message->categories;
86
+                if (isset($message->flag)) {
87
+                    $newmessage->flag = $message->flag;
88
+                }
89
+                if (isset($message->lastverbexectime)) {
90
+                    $newmessage->lastverbexectime = $message->lastverbexectime;
91
+                }
92
+                if (isset($message->lastverbexecuted)) {
93
+                    $newmessage->lastverbexecuted = $message->lastverbexecuted;
94
+                }
95
+                if (isset($message->categories)) {
96
+                    $newmessage->categories = $message->categories;
97
+                }
90 98
                 $message = $newmessage;
91 99
                 unset($newmessage);
92 100
                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesStream->ImportMessageChange('%s'): SyncMail message updated. Message content is striped, only flags/categories are streamed.", $id));
@@ -124,8 +132,7 @@  discard block
 block discarded – undo
124 132
         $this->importedMsgs++;
125 133
         if ($asSoftDelete) {
126 134
             $this->encoder->startTag(SYNC_SOFTDELETE);
127
-        }
128
-        else {
135
+        } else {
129 136
             $this->encoder->startTag(SYNC_REMOVE);
130 137
         }
131 138
             $this->encoder->startTag(SYNC_SERVERENTRYID);
@@ -148,8 +155,9 @@  discard block
 block discarded – undo
148 155
      * @return boolean
149 156
      */
150 157
     public function ImportMessageReadFlag($id, $flags, $categories = array()) {
151
-        if(!($this->objclass instanceof SyncMail))
152
-            return false;
158
+        if(!($this->objclass instanceof SyncMail)) {
159
+                    return false;
160
+        }
153 161
 
154 162
         $this->importedMsgs++;
155 163
 
@@ -205,10 +213,11 @@  discard block
 block discarded – undo
205 213
         }
206 214
 
207 215
         // send a modify flag if the folder is already known on the device
208
-        if (isset($folder->flags) && $folder->flags === SYNC_NEWMESSAGE)
209
-            $this->encoder->startTag(SYNC_FOLDERHIERARCHY_ADD);
210
-        else
211
-            $this->encoder->startTag(SYNC_FOLDERHIERARCHY_UPDATE);
216
+        if (isset($folder->flags) && $folder->flags === SYNC_NEWMESSAGE) {
217
+                    $this->encoder->startTag(SYNC_FOLDERHIERARCHY_ADD);
218
+        } else {
219
+                    $this->encoder->startTag(SYNC_FOLDERHIERARCHY_UPDATE);
220
+        }
212 221
 
213 222
         $folder->Encode($this->encoder);
214 223
         $this->encoder->endTag();
Please login to merge, or discard this patch.
lib/core/hierarchycache.php 1 patch
Braces   +12 added lines, -10 removed lines patch added patch discarded remove patch
@@ -59,8 +59,7 @@  discard block
 block discarded – undo
59 59
     public function GetFolder($serverid, $oldState = false) {
60 60
         if (!$oldState && array_key_exists($serverid, $this->data)) {
61 61
             return $this->data[$serverid];
62
-        }
63
-        else if ($oldState && array_key_exists($serverid, $this->dataOld)) {
62
+        } else if ($oldState && array_key_exists($serverid, $this->dataOld)) {
64 63
             return $this->dataOld[$serverid];
65 64
         }
66 65
         return false;
@@ -117,14 +116,16 @@  discard block
 block discarded – undo
117 116
      * @return boolean
118 117
      */
119 118
     public function ImportFolders($folders) {
120
-        if (!is_array($folders))
121
-            return false;
119
+        if (!is_array($folders)) {
120
+                    return false;
121
+        }
122 122
 
123 123
         $this->data = array();
124 124
 
125 125
         foreach ($folders as $folder) {
126
-            if (!isset($folder->type))
127
-                continue;
126
+            if (!isset($folder->type)) {
127
+                            continue;
128
+            }
128 129
             $this->AddFolder($folder);
129 130
         }
130 131
         return true;
@@ -139,10 +140,11 @@  discard block
 block discarded – undo
139 140
      * @return array
140 141
      */
141 142
     public function ExportFolders($oldstate = false) {
142
-        if ($oldstate === false)
143
-            return $this->data;
144
-        else
145
-            return $this->dataOld;
143
+        if ($oldstate === false) {
144
+                    return $this->data;
145
+        } else {
146
+                    return $this->dataOld;
147
+        }
146 148
     }
147 149
 
148 150
     /**
Please login to merge, or discard this patch.
lib/wbxml/wbxmlencoder.php 1 patch
Braces   +41 added lines, -35 removed lines patch added patch discarded remove patch
@@ -58,8 +58,7 @@  discard block
 block discarded – undo
58 58
         if ($this->multipart) {
59 59
             header("Content-Type: application/vnd.ms-sync.multipart");
60 60
             ZLog::Write(LOGLEVEL_DEBUG, "WBXMLEncoder->startWBXML() type: vnd.ms-sync.multipart");
61
-        }
62
-        else {
61
+        } else {
63 62
             header("Content-Type: application/vnd.ms-sync.wbxml");
64 63
             ZLog::Write(LOGLEVEL_DEBUG, "WBXMLEncoder->startWBXML() type: vnd.ms-sync.wbxml");
65 64
         }
@@ -111,14 +110,16 @@  discard block
 block discarded – undo
111 110
         if($stackelem['sent']) {
112 111
             $this->_endTag();
113 112
 
114
-            if(count($this->_stack) == 0)
115
-                ZLog::Write(LOGLEVEL_DEBUG, "WBXMLEncoder->endTag() WBXML output completed");
113
+            if(count($this->_stack) == 0) {
114
+                            ZLog::Write(LOGLEVEL_DEBUG, "WBXMLEncoder->endTag() WBXML output completed");
115
+            }
116 116
 
117 117
             if(count($this->_stack) == 0 && $this->multipart == true) {
118 118
                 $this->processMultipart();
119 119
             }
120
-            if(count($this->_stack) == 0)
121
-                $this->writeLog();
120
+            if(count($this->_stack) == 0) {
121
+                            $this->writeLog();
122
+            }
122 123
         }
123 124
     }
124 125
 
@@ -135,8 +136,9 @@  discard block
 block discarded – undo
135 136
         // cannot send \0 characters within the XML content anywhere.
136 137
         $content = str_replace("\0","",$content);
137 138
 
138
-        if("x" . $content == "x")
139
-            return;
139
+        if("x" . $content == "x") {
140
+                    return;
141
+        }
140 142
         $this->_outputStack();
141 143
         $this->_content($content);
142 144
     }
@@ -187,10 +189,12 @@  discard block
 block discarded – undo
187 189
      * @return void
188 190
      */
189 191
     public function addBodypartStream($bp) {
190
-        if (!is_resource($bp))
191
-            throw new WBXMLException("WBXMLEncoder->addBodypartStream(): trying to add a ".gettype($bp)." instead of a stream");
192
-        if ($this->multipart)
193
-            $this->bodyparts[] = $bp;
192
+        if (!is_resource($bp)) {
193
+                    throw new WBXMLException("WBXMLEncoder->addBodypartStream(): trying to add a ".gettype($bp)." instead of a stream");
194
+        }
195
+        if ($this->multipart) {
196
+                    $this->bodyparts[] = $bp;
197
+        }
194 198
     }
195 199
 
196 200
     /**
@@ -229,13 +233,15 @@  discard block
 block discarded – undo
229 233
      * @return
230 234
      */
231 235
     private function _startTag($tag, $nocontent = false) {
232
-        if ($this->log)
233
-            $this->logStartTag($tag, $nocontent);
236
+        if ($this->log) {
237
+                    $this->logStartTag($tag, $nocontent);
238
+        }
234 239
 
235 240
         $mapping = $this->getMapping($tag);
236 241
 
237
-        if(!$mapping)
238
-            return false;
242
+        if(!$mapping) {
243
+                    return false;
244
+        }
239 245
 
240 246
         if($this->_tagcp != $mapping["cp"]) {
241 247
             $this->outSwitchPage($mapping["cp"]);
@@ -244,8 +250,9 @@  discard block
 block discarded – undo
244 250
 
245 251
         $code = $mapping["code"];
246 252
 
247
-        if(!isset($nocontent) || !$nocontent)
248
-            $code |= 0x40;
253
+        if(!isset($nocontent) || !$nocontent) {
254
+                    $code |= 0x40;
255
+        }
249 256
 
250 257
         $this->outByte($code);
251 258
     }
@@ -258,8 +265,9 @@  discard block
 block discarded – undo
258 265
      * @return
259 266
      */
260 267
     private function _content($content) {
261
-        if ($this->log)
262
-            $this->logContent($content);
268
+        if ($this->log) {
269
+                    $this->logContent($content);
270
+        }
263 271
         $this->outByte(self::WBXML_STR_I);
264 272
         $this->outTermStr($content);
265 273
     }
@@ -278,8 +286,7 @@  discard block
 block discarded – undo
278 286
         if ($opaque) {
279 287
             $this->outByte(self::WBXML_OPAQUE);
280 288
             $this->outMBUInt($stat['size']);
281
-        }
282
-        else {
289
+        } else {
283 290
             $this->outByte(self::WBXML_STR_I);
284 291
         }
285 292
 
@@ -307,8 +314,9 @@  discard block
 block discarded – undo
307 314
      * @return
308 315
      */
309 316
     private function _endTag() {
310
-        if ($this->log)
311
-            $this->logEndTag();
317
+        if ($this->log) {
318
+                    $this->logEndTag();
319
+        }
312 320
         $this->outByte(self::WBXML_END);
313 321
     }
314 322
 
@@ -352,8 +360,7 @@  discard block
 block discarded – undo
352 360
             $uint = $uint >> 7;
353 361
             if ($i == 0) {
354 362
                 $out = chr($byte) . $out;
355
-            }
356
-            else {
363
+            } else {
357 364
                 $out = chr($byte | 0x80) . $out;
358 365
             }
359 366
         }
@@ -401,8 +408,7 @@  discard block
 block discarded – undo
401 408
 
402 409
         if(isset($split["ns"])) {
403 410
             $cp = $this->_dtd["namespaces"][$split["ns"]];
404
-        }
405
-        else {
411
+        } else {
406 412
             $cp = 0;
407 413
         }
408 414
 
@@ -429,14 +435,14 @@  discard block
 block discarded – undo
429 435
         if($pos) {
430 436
             $ns = substr($fulltag, 0, $pos);
431 437
             $tag = substr($fulltag, $pos+1);
432
-        }
433
-        else {
438
+        } else {
434 439
             $tag = $fulltag;
435 440
         }
436 441
 
437 442
         $ret = array();
438
-        if($ns)
439
-            $ret["ns"] = $ns;
443
+        if($ns) {
444
+                    $ret["ns"] = $ns;
445
+        }
440 446
         $ret["tag"] = $tag;
441 447
 
442 448
         return $ret;
@@ -453,9 +459,9 @@  discard block
 block discarded – undo
453 459
      */
454 460
     private function logStartTag($tag, $nocontent) {
455 461
         $spaces = str_repeat(" ", count($this->logStack));
456
-        if($nocontent)
457
-            ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . " <$tag/>");
458
-        else {
462
+        if($nocontent) {
463
+                    ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . " <$tag/>");
464
+        } else {
459 465
             array_push($this->logStack, $tag);
460 466
             ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . " <$tag>");
461 467
         }
Please login to merge, or discard this patch.
lib/wbxml/wbxmldecoder.php 1 patch
Braces   +62 added lines, -52 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@  discard block
 block discarded – undo
36 36
     static public function InWhile($name) {
37 37
         if (!isset(self::$loopCounter[$name])) {
38 38
             self::$loopCounter[$name] = 0;
39
-        }
40
-        else {
39
+        } else {
41 40
             self::$loopCounter[$name]++;
42 41
         }
43 42
 
@@ -81,16 +80,19 @@  discard block
 block discarded – undo
81 80
         }
82 81
 
83 82
         $publicid = $this->getMBUInt();
84
-        if($publicid !== 1)
85
-            throw new WBXMLException("Wrong publicid : ".$publicid);
83
+        if($publicid !== 1) {
84
+                    throw new WBXMLException("Wrong publicid : ".$publicid);
85
+        }
86 86
 
87 87
         $charsetid = $this->getMBUInt();
88
-        if ($charsetid !== 106)
89
-            throw new WBXMLException("Wrong charset : ".$charsetid);
88
+        if ($charsetid !== 106) {
89
+                    throw new WBXMLException("Wrong charset : ".$charsetid);
90
+        }
90 91
 
91 92
         $stringtablesize = $this->getMBUInt();
92
-        if ($stringtablesize !== 0)
93
-            throw new WBXMLException("Wrong string table size : ".$stringtablesize);
93
+        if ($stringtablesize !== 0) {
94
+                    throw new WBXMLException("Wrong string table size : ".$stringtablesize);
95
+        }
94 96
     }
95 97
 
96 98
     /**
@@ -111,9 +113,9 @@  discard block
 block discarded – undo
111 113
                 WBXMLDecoder::ResetInWhile("decoderGetElement");
112 114
                 while(WBXMLDecoder::InWhile("decoderGetElement")) {
113 115
                     $next = $this->getToken();
114
-                    if($next == false)
115
-                        return false;
116
-                    else if($next[EN_TYPE] == EN_CONTENT) {
116
+                    if($next == false) {
117
+                                            return false;
118
+                    } else if($next[EN_TYPE] == EN_CONTENT) {
117 119
                         $element[EN_CONTENT] .= $next[EN_CONTENT];
118 120
                     } else {
119 121
                         $this->ungetElement($next);
@@ -149,12 +151,13 @@  discard block
 block discarded – undo
149 151
     public function getElementStartTag($tag) {
150 152
         $element = $this->getToken();
151 153
 
152
-        if (!$element)
153
-            return false;
154
+        if (!$element) {
155
+                    return false;
156
+        }
154 157
 
155
-        if($element[EN_TYPE] == EN_TYPE_STARTTAG && $element[EN_TAG] == $tag)
156
-            return $element;
157
-        else {
158
+        if($element[EN_TYPE] == EN_TYPE_STARTTAG && $element[EN_TAG] == $tag) {
159
+                    return $element;
160
+        } else {
158 161
             ZLog::Write(LOGLEVEL_WBXMLSTACK, sprintf("WBXMLDecoder->getElementStartTag(): unmatched WBXML tag: '%s' matching '%s' type '%s' flags '%s'", $tag, ((isset($element[EN_TAG]))?$element[EN_TAG]:""), ((isset($element[EN_TYPE]))?$element[EN_TYPE]:""), ((isset($element[EN_FLAGS]))?$element[EN_FLAGS]:"")));
159 162
             $this->ungetElement($element);
160 163
         }
@@ -171,9 +174,9 @@  discard block
 block discarded – undo
171 174
     public function getElementEndTag() {
172 175
         $element = $this->getToken();
173 176
 
174
-        if($element[EN_TYPE] == EN_TYPE_ENDTAG)
175
-            return $element;
176
-        else {
177
+        if($element[EN_TYPE] == EN_TYPE_ENDTAG) {
178
+                    return $element;
179
+        } else {
177 180
             ZLog::Write(LOGLEVEL_WBXMLSTACK, sprintf("WBXMLDecoder->getElementEndTag(): unmatched WBXML tag: '%s' type '%s' flags '%s'", ((isset($element[EN_TAG]))?$element[EN_TAG]:""), ((isset($element[EN_TYPE]))?$element[EN_TYPE]:""), ((isset($element[EN_FLAGS]))?$element[EN_FLAGS]:"")));
178 181
 
179 182
             $bt = debug_backtrace();
@@ -198,8 +201,7 @@  discard block
 block discarded – undo
198 201
 
199 202
         if($element[EN_TYPE] == EN_TYPE_CONTENT) {
200 203
             return $element[EN_CONTENT];
201
-        }
202
-        else {
204
+        } else {
203 205
             ZLog::Write(LOGLEVEL_WBXMLSTACK, sprintf("WBXMLDecoder->getElementContent(): unmatched WBXML content: '%s' type '%s' flags '%s'", ((isset($element[EN_TAG]))?$element[EN_TAG]:""), ((isset($element[EN_TYPE]))?$element[EN_TYPE]:""), ((isset($element[EN_FLAGS]))?$element[EN_FLAGS]:"")));
204 206
             $this->ungetElement($element);
205 207
         }
@@ -216,8 +218,9 @@  discard block
 block discarded – undo
216 218
      * @return
217 219
      */
218 220
     public function ungetElement($element) {
219
-        if($this->ungetbuffer)
220
-            ZLog::Write(LOGLEVEL_ERROR,sprintf("WBXMLDecoder->ungetElement(): WBXML double unget on tag: '%s' type '%s' flags '%s'", ((isset($element[EN_TAG]))?$element[EN_TAG]:""), ((isset($element[EN_TYPE]))?$element[EN_TYPE]:""), ((isset($element[EN_FLAGS]))?$element[EN_FLAGS]:"")));
221
+        if($this->ungetbuffer) {
222
+                    ZLog::Write(LOGLEVEL_ERROR,sprintf("WBXMLDecoder->ungetElement(): WBXML double unget on tag: '%s' type '%s' flags '%s'", ((isset($element[EN_TAG]))?$element[EN_TAG]:""), ((isset($element[EN_TYPE]))?$element[EN_TYPE]:""), ((isset($element[EN_FLAGS]))?$element[EN_FLAGS]:"")));
223
+        }
221 224
 
222 225
         $this->ungetbuffer = $element;
223 226
     }
@@ -272,8 +275,9 @@  discard block
 block discarded – undo
272 275
         }
273 276
 
274 277
         $el = $this->_getToken();
275
-        if($this->log && $el)
276
-            $this->logToken($el);
278
+        if($this->log && $el) {
279
+                    $this->logToken($el);
280
+        }
277 281
 
278 282
         return $el;
279 283
     }
@@ -294,8 +298,9 @@  discard block
 block discarded – undo
294 298
                 if($el[EN_FLAGS] & EN_FLAGS_CONTENT) {
295 299
                     ZLog::Write(LOGLEVEL_WBXML,"I " . $spaces . " <". $el[EN_TAG] . ">");
296 300
                     array_push($this->logStack, $el[EN_TAG]);
297
-                } else
298
-                    ZLog::Write(LOGLEVEL_WBXML,"I " . $spaces . " <" . $el[EN_TAG] . "/>");
301
+                } else {
302
+                                    ZLog::Write(LOGLEVEL_WBXML,"I " . $spaces . " <" . $el[EN_TAG] . "/>");
303
+                }
299 304
 
300 305
                 break;
301 306
             case EN_TYPE_ENDTAG:
@@ -309,8 +314,7 @@  discard block
 block discarded – undo
309 314
                 $messagesize = strlen($el[EN_CONTENT]);
310 315
                 if ($messagesize > 10240 && !defined('WBXML_DEBUGGING')) {
311 316
                     $content = substr($el[EN_CONTENT], 0, 10240) . sprintf(" <log message with %d bytes truncated>", $messagesize);
312
-                }
313
-                else {
317
+                } else {
314 318
                     $content = $el[EN_CONTENT];
315 319
                 }
316 320
                 // Log but make sure it's not truncated again (will be slightly bigger than 10KB)
@@ -332,8 +336,9 @@  discard block
 block discarded – undo
332 336
         WBXMLDecoder::ResetInWhile("decoderGetToken");
333 337
         while(WBXMLDecoder::InWhile("decoderGetToken")) {
334 338
             $byte = fread($this->in, 1);
335
-            if($byte === "" || $byte === false)
336
-                break;
339
+            if($byte === "" || $byte === false) {
340
+                            break;
341
+            }
337 342
             $byte = ord($byte);
338 343
 
339 344
             switch($byte) {
@@ -375,8 +380,9 @@  discard block
 block discarded – undo
375 380
                     throw new WBXMLException("Invalid token :".$byte);
376 381
 
377 382
                 default:
378
-                    if($byte & self::WBXML_WITH_ATTRIBUTES)
379
-                        throw new WBXMLException("Attributes are not allowed :".$byte);
383
+                    if($byte & self::WBXML_WITH_ATTRIBUTES) {
384
+                                            throw new WBXMLException("Attributes are not allowed :".$byte);
385
+                    }
380 386
                     $element[EN_TYPE] = EN_TYPE_STARTTAG;
381 387
                     $element[EN_TAG] = $this->getMapping($this->tagcp, $byte & 0x3f);
382 388
                     $element[EN_FLAGS] = ($byte & self::WBXML_WITH_CONTENT ? EN_FLAGS_CONTENT : 0);
@@ -398,8 +404,7 @@  discard block
 block discarded – undo
398 404
                 $in = $this->getByte();
399 405
                 if ($in == 0) {
400 406
                     break;
401
-                }
402
-                else {
407
+                } else {
403 408
                     $str .= chr($in);
404 409
                 }
405 410
             }
@@ -425,11 +430,13 @@  discard block
 block discarded – undo
425 430
      */
426 431
     private function getOpaque($len) {
427 432
         $d = stream_get_contents($this->in, $len);
428
-        if ($d === false)
429
-            throw new HTTPReturnCodeException("WBXMLDecoder->getOpaque(): stream_get_contents === false", HTTP_CODE_500, null, LOGLEVEL_WARN);
433
+        if ($d === false) {
434
+                    throw new HTTPReturnCodeException("WBXMLDecoder->getOpaque(): stream_get_contents === false", HTTP_CODE_500, null, LOGLEVEL_WARN);
435
+        }
430 436
         $l = strlen($d);
431
-        if ($l !== $len)
432
-            throw new HTTPReturnCodeException("WBXMLDecoder->getOpaque(): only $l byte read instead of $len", HTTP_CODE_500, null, LOGLEVEL_WARN);
437
+        if ($l !== $len) {
438
+                    throw new HTTPReturnCodeException("WBXMLDecoder->getOpaque(): only $l byte read instead of $len", HTTP_CODE_500, null, LOGLEVEL_WARN);
439
+        }
433 440
         return $d;
434 441
     }
435 442
 
@@ -441,10 +448,11 @@  discard block
 block discarded – undo
441 448
      */
442 449
     private function getByte() {
443 450
         $ch = fread($this->in, 1);
444
-        if(strlen($ch) > 0)
445
-            return ord($ch);
446
-        else
447
-            return;
451
+        if(strlen($ch) > 0) {
452
+                    return ord($ch);
453
+        } else {
454
+                    return;
455
+        }
448 456
     }
449 457
 
450 458
     /**
@@ -461,10 +469,11 @@  discard block
 block discarded – undo
461 469
 
462 470
           $uint |= $byte & 0x7f;
463 471
 
464
-          if($byte & 0x80)
465
-              $uint = $uint << 7;
466
-          else
467
-              break;
472
+          if($byte & 0x80) {
473
+                        $uint = $uint << 7;
474
+          } else {
475
+                        break;
476
+          }
468 477
         }
469 478
 
470 479
         return $uint;
@@ -480,13 +489,14 @@  discard block
 block discarded – undo
480 489
      * @return string
481 490
      */
482 491
     private function getMapping($cp, $id) {
483
-        if(!isset($this->dtd["codes"][$cp]) || !isset($this->dtd["codes"][$cp][$id]))
484
-            return false;
485
-        else {
492
+        if(!isset($this->dtd["codes"][$cp]) || !isset($this->dtd["codes"][$cp][$id])) {
493
+                    return false;
494
+        } else {
486 495
             if(isset($this->dtd["namespaces"][$cp])) {
487 496
                 return $this->dtd["namespaces"][$cp] . ":" . $this->dtd["codes"][$cp][$id];
488
-            } else
489
-                return $this->dtd["codes"][$cp][$id];
497
+            } else {
498
+                            return $this->dtd["codes"][$cp][$id];
499
+            }
490 500
         }
491 501
     }
492 502
 }
Please login to merge, or discard this patch.
lib/utils/stringstreamwrapper.php 1 patch
Braces   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -32,8 +32,9 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function stream_open($path, $mode, $options, &$opened_path) {
34 34
         $contextOptions = stream_context_get_options($this->context);
35
-        if (!isset($contextOptions[self::PROTOCOL]['string']))
36
-            return false;
35
+        if (!isset($contextOptions[self::PROTOCOL]['string'])) {
36
+                    return false;
37
+        }
37 38
 
38 39
         $this->position = 0;
39 40
 
@@ -84,11 +85,9 @@  discard block
 block discarded – undo
84 85
     public function stream_seek($offset, $whence = SEEK_SET) {
85 86
         if ($whence == SEEK_CUR) {
86 87
             $this->position += $offset;
87
-        }
88
-        else if ($whence == SEEK_END) {
88
+        } else if ($whence == SEEK_END) {
89 89
             $this->position = $this->stringlength + $offset;
90
-        }
91
-        else {
90
+        } else {
92 91
             $this->position = $offset;
93 92
         }
94 93
         return true;
Please login to merge, or discard this patch.
lib/utils/g_RFC822.php 1 patch
Braces   +69 added lines, -28 removed lines patch added patch discarded remove patch
@@ -154,11 +154,21 @@  discard block
 block discarded – undo
154 154
      */
155 155
     public function __construct($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
156 156
     {
157
-        if (isset($address))        $this->address        = $address;
158
-        if (isset($default_domain)) $this->default_domain = $default_domain;
159
-        if (isset($nest_groups))    $this->nestGroups     = $nest_groups;
160
-        if (isset($validate))       $this->validate       = $validate;
161
-        if (isset($limit))          $this->limit          = $limit;
157
+        if (isset($address)) {
158
+            $this->address        = $address;
159
+        }
160
+        if (isset($default_domain)) {
161
+            $this->default_domain = $default_domain;
162
+        }
163
+        if (isset($nest_groups)) {
164
+            $this->nestGroups     = $nest_groups;
165
+        }
166
+        if (isset($validate)) {
167
+            $this->validate       = $validate;
168
+        }
169
+        if (isset($limit)) {
170
+            $this->limit          = $limit;
171
+        }
162 172
     }
163 173
 
164 174
     /**
@@ -179,13 +189,25 @@  discard block
 block discarded – undo
179 189
             return $obj->parseAddressList();
180 190
         }
181 191
 
182
-        if (isset($address))        $this->address        = $address;
192
+        if (isset($address)) {
193
+            $this->address        = $address;
194
+        }
183 195
         // grommunio-sync addition
184
-        if (strlen(trim($this->address)) == 0) return array();
185
-        if (isset($default_domain)) $this->default_domain = $default_domain;
186
-        if (isset($nest_groups))    $this->nestGroups     = $nest_groups;
187
-        if (isset($validate))       $this->validate       = $validate;
188
-        if (isset($limit))          $this->limit          = $limit;
196
+        if (strlen(trim($this->address)) == 0) {
197
+            return array();
198
+        }
199
+        if (isset($default_domain)) {
200
+            $this->default_domain = $default_domain;
201
+        }
202
+        if (isset($nest_groups)) {
203
+            $this->nestGroups     = $nest_groups;
204
+        }
205
+        if (isset($validate)) {
206
+            $this->validate       = $validate;
207
+        }
208
+        if (isset($limit)) {
209
+            $this->limit          = $limit;
210
+        }
189 211
 
190 212
         $this->structure  = array();
191 213
         $this->addresses  = array();
@@ -424,10 +446,12 @@  discard block
 block discarded – undo
424 446
     {
425 447
         $parts = explode($char, $string);
426 448
         for ($i = 0; $i < count($parts); $i++){
427
-            if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i]))
428
-                $num--;
429
-            if (isset($parts[$i + 1]))
430
-                $parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];
449
+            if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i])) {
450
+                            $num--;
451
+            }
452
+            if (isset($parts[$i + 1])) {
453
+                            $parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];
454
+            }
431 455
         }
432 456
 
433 457
         return $num;
@@ -531,8 +555,9 @@  discard block
 block discarded – undo
531 555
         $phrase_parts = array();
532 556
         while (count($parts) > 0){
533 557
             $phrase_parts[] = $this->_splitCheck($parts, ' ');
534
-            for ($i = 0; $i < $this->index + 1; $i++)
535
-                array_shift($parts);
558
+            for ($i = 0; $i < $this->index + 1; $i++) {
559
+                            array_shift($parts);
560
+            }
536 561
         }
537 562
 
538 563
         foreach ($phrase_parts as $part) {
@@ -545,7 +570,9 @@  discard block
 block discarded – undo
545 570
             }
546 571
 
547 572
             // Otherwise it's an atom:
548
-            if (!$this->_validateAtom($part)) return false;
573
+            if (!$this->_validateAtom($part)) {
574
+                return false;
575
+            }
549 576
         }
550 577
 
551 578
         return true;
@@ -761,7 +788,9 @@  discard block
 block discarded – undo
761 788
 
762 789
         foreach ($domains as $domain) {
763 790
             $domain = str_replace('@', '', trim($domain));
764
-            if (!$this->_validateDomain($domain)) return false;
791
+            if (!$this->_validateDomain($domain)) {
792
+                return false;
793
+            }
765 794
         }
766 795
 
767 796
         return $route;
@@ -783,13 +812,15 @@  discard block
 block discarded – undo
783 812
 
784 813
         while (count($subdomains) > 0) {
785 814
             $sub_domains[] = $this->_splitCheck($subdomains, '.');
786
-            for ($i = 0; $i < $this->index + 1; $i++)
787
-                array_shift($subdomains);
815
+            for ($i = 0; $i < $this->index + 1; $i++) {
816
+                            array_shift($subdomains);
817
+            }
788 818
         }
789 819
 
790 820
         foreach ($sub_domains as $sub_domain) {
791
-            if (!$this->_validateSubdomain(trim($sub_domain)))
792
-                return false;
821
+            if (!$this->_validateSubdomain(trim($sub_domain))) {
822
+                            return false;
823
+            }
793 824
         }
794 825
 
795 826
         // Managed to get here, so return input.
@@ -806,9 +837,13 @@  discard block
 block discarded – undo
806 837
     protected function _validateSubdomain($subdomain)
807 838
     {
808 839
         if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){
809
-            if (!$this->_validateDliteral($arr[1])) return false;
840
+            if (!$this->_validateDliteral($arr[1])) {
841
+                return false;
842
+            }
810 843
         } else {
811
-            if (!$this->_validateAtom($subdomain)) return false;
844
+            if (!$this->_validateAtom($subdomain)) {
845
+                return false;
846
+            }
812 847
         }
813 848
 
814 849
         // Got here, so return successful.
@@ -851,8 +886,12 @@  discard block
 block discarded – undo
851 886
             $domain     = $this->default_domain;
852 887
         }
853 888
 
854
-        if (($local_part = $this->_validateLocalPart($local_part)) === false) return false;
855
-        if (($domain     = $this->_validateDomain($domain)) === false) return false;
889
+        if (($local_part = $this->_validateLocalPart($local_part)) === false) {
890
+            return false;
891
+        }
892
+        if (($domain     = $this->_validateDomain($domain)) === false) {
893
+            return false;
894
+        }
856 895
 
857 896
         // Got here so return successful.
858 897
         return array('local_part' => $local_part, 'domain' => $domain);
@@ -890,7 +929,9 @@  discard block
 block discarded – undo
890 929
                 return false;
891 930
             }
892 931
 
893
-            if ($this->_validatePhrase(trim($word)) === false) return false;
932
+            if ($this->_validatePhrase(trim($word)) === false) {
933
+                return false;
934
+            }
894 935
         }
895 936
 
896 937
         // Managed to get here, so return the input.
Please login to merge, or discard this patch.
lib/utils/compat.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,9 +16,10 @@
 block discarded – undo
16 16
       */
17 17
     function apache_request_headers() {
18 18
         $headers = array();
19
-        foreach ($_SERVER as $key => $value)
20
-            if (substr($key, 0, 5) == 'HTTP_')
19
+        foreach ($_SERVER as $key => $value) {
20
+                    if (substr($key, 0, 5) == 'HTTP_')
21 21
                 $headers[strtr(substr($key, 5), '_', '-')] = $value;
22
+        }
22 23
 
23 24
         return $headers;
24 25
     }
Please login to merge, or discard this patch.