Completed
Pull Request — master (#312)
by
unknown
26:01 queued 18:06
created
htdocs/okapi/controller.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
 
18 18
 $GLOBALS['rootpath'] = '../'; # this is for OC-code compatibility
19 19
 
20
-require_once($GLOBALS['rootpath'].'okapi/core.php');
20
+require_once($GLOBALS['rootpath'] . 'okapi/core.php');
21 21
 OkapiErrorHandler::$treat_notices_as_errors = true;
22
-require_once($GLOBALS['rootpath'].'okapi/urls.php');
22
+require_once($GLOBALS['rootpath'] . 'okapi/urls.php');
23 23
 
24 24
 if (ob_list_handlers() == array('default output handler'))
25 25
 {
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
                     # Pattern matched! Moving on to the proper View...
73 73
 
74 74
                     array_shift($matches);
75
-                    require_once($GLOBALS['rootpath']."okapi/views/$namespace.php");
76
-                    $response = call_user_func_array(array('\\okapi\\views\\'.
77
-                        str_replace('/', '\\', $namespace).'\\View', 'call'), $matches);
75
+                    require_once($GLOBALS['rootpath'] . "okapi/views/$namespace.php");
76
+                    $response = call_user_func_array(array('\\okapi\\views\\' .
77
+                        str_replace('/', '\\', $namespace) . '\\View', 'call'), $matches);
78 78
                     if ($response)
79 79
                         $response->display();
80 80
                     return;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 
89 89
         # None of the patterns matched OR method threw the Http404 exception.
90 90
 
91
-        require_once($GLOBALS['rootpath']."okapi/views/http404.php");
91
+        require_once($GLOBALS['rootpath'] . "okapi/views/http404.php");
92 92
         $response = \okapi\views\http404\View::call();
93 93
         $response->display();
94 94
     }
Please login to merge, or discard this patch.
htdocs/okapi/views/update.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 use okapi\cronjobs\CronJobController;
20 20
 use okapi\services\replicate\ReplicateCommon;
21 21
 
22
-require_once($GLOBALS['rootpath']."okapi/cronjobs.php");
22
+require_once($GLOBALS['rootpath'] . "okapi/cronjobs.php");
23 23
 
24 24
 class View
25 25
 {
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         self::out("Current OKAPI database version: $current_ver\n");
94 94
         if ($current_ver == 0 && ((!isset($_GET['install'])) || ($_GET['install'] != 'true')))
95 95
         {
96
-            self::out("Current OKAPI settings are:\n\n".Settings::describe_settings()."\n\n".
96
+            self::out("Current OKAPI settings are:\n\n" . Settings::describe_settings() . "\n\n" .
97 97
                 "Make sure they are correct, then append '?install=true' to your query.");
98 98
             try
99 99
             {
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
             catch (Exception $e)
103 103
             {
104 104
                 self::out(
105
-                    "\n\n".
106
-                    "IMPORTANT: If you're trying to install OKAPI on an empty database then\n".
107
-                    "you will fail. OKAPI is not a standalone application, it is a plugin\n".
108
-                    "for Opencaching sites. Please read this:\n\n".
105
+                    "\n\n" .
106
+                    "IMPORTANT: If you're trying to install OKAPI on an empty database then\n" .
107
+                    "you will fail. OKAPI is not a standalone application, it is a plugin\n" .
108
+                    "for Opencaching sites. Please read this:\n\n" .
109 109
                     "https://github.com/opencaching/okapi/issues/299"
110 110
                 );
111 111
             }
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
                 $version_to_apply = $current_ver + 1;
127 127
                 self::out("Applying mutation #$version_to_apply...");
128 128
                 try {
129
-                    call_user_func(array(__CLASS__, "ver".$version_to_apply));
129
+                    call_user_func(array(__CLASS__, "ver" . $version_to_apply));
130 130
                     self::out(" OK!\n");
131 131
                     Okapi::set_var('db_version', $version_to_apply);
132 132
                     $current_ver += 1;
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
                 okapi_stats_hourly sh
161 161
             where
162 162
                 sh.consumer_key = c.`key`
163
-                and sh.service_name in ('".implode("','", array_map('\okapi\Db::escape_string', $service_names))."')
164
-                ".(($days != null) ? "and sh.period_start > date_add(now(), interval '".Db::escape_string(-$days)."' day)" : "")."
163
+                and sh.service_name in ('".implode("','", array_map('\okapi\Db::escape_string', $service_names)) . "')
164
+                ".(($days != null) ? "and sh.period_start > date_add(now(), interval '" . Db::escape_string(-$days) . "' day)" : "") . "
165 165
         ");
166 166
     }
167 167
 
@@ -363,12 +363,12 @@  discard block
 block discarded – undo
363 363
         # Inform the admin about the new cronjobs.
364 364
         Okapi::mail_admins(
365 365
             "Additional setup needed: cronjobs support",
366
-            "Hello there, you've just updated OKAPI on your server. Thanks!\n\n".
367
-            "We need you to do one more thing. This version of OKAPI requires\n".
368
-            "additional crontab entry. Please add the following line to your crontab:\n\n".
369
-            "*/5 * * * * wget -O - -q -t 1 ".Settings::get('SITE_URL')."okapi/cron5\n\n".
370
-            "This is required for OKAPI to function properly from now on.\n\n".
371
-            "-- \n".
366
+            "Hello there, you've just updated OKAPI on your server. Thanks!\n\n" .
367
+            "We need you to do one more thing. This version of OKAPI requires\n" .
368
+            "additional crontab entry. Please add the following line to your crontab:\n\n" .
369
+            "*/5 * * * * wget -O - -q -t 1 " . Settings::get('SITE_URL') . "okapi/cron5\n\n" .
370
+            "This is required for OKAPI to function properly from now on.\n\n" .
371
+            "-- \n" .
372 372
             "Thanks, OKAPI developers."
373 373
         );
374 374
     }
@@ -609,9 +609,9 @@  discard block
 block discarded – undo
609 609
     {
610 610
         # Remove unused locks (these might have been created in previous versions of OKAPI).
611 611
 
612
-        for ($z=0; $z<=2; $z++)
613
-            for ($x=0; $x<(1<<$z); $x++)
614
-                for ($y=0; $y<(1<<$z); $y++)
612
+        for ($z = 0; $z <= 2; $z++)
613
+            for ($x = 0; $x < (1 << $z); $x++)
614
+                for ($y = 0; $y < (1 << $z); $y++)
615 615
                 {
616 616
                     $lockname = "tile-computation-$z-$x-$y";
617 617
                     if (OkapiLock::exists($lockname))
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
     {
624 624
         # Once again, remove unused locks.
625 625
 
626
-        for ($z=0; $z<=21; $z++)
626
+        for ($z = 0; $z <= 21; $z++)
627 627
         {
628 628
             foreach (array("", "-0", "-1") as $suffix)
629 629
             {
@@ -698,10 +698,10 @@  discard block
 block discarded – undo
698 698
         # Ignore newly added replicate fields. This way we will avoid generating
699 699
         # changelog entries for these fields.
700 700
 
701
-        require_once($GLOBALS['rootpath']."okapi/services/replicate/replicate_common.inc.php");
701
+        require_once($GLOBALS['rootpath'] . "okapi/services/replicate/replicate_common.inc.php");
702 702
         $new_geocache_fields = array(
703 703
             'attr_acodes', 'willattends', 'country', 'state', 'preview_image',
704
-            'trip_time', 'trip_distance', 'gc_code',  'hints2', 'protection_areas'
704
+            'trip_time', 'trip_distance', 'gc_code', 'hints2', 'protection_areas'
705 705
         );
706 706
         ReplicateCommon::verify_clog_consistency(true, $new_geocache_fields);
707 707
     }
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
             ) ENGINE=MyISAM DEFAULT CHARSET=utf8
743 743
             (
744 744
                 SELECT
745
-                    ".Okapi::OBJECT_TYPE_CACHE_LOG." object_type,
745
+                    ".Okapi::OBJECT_TYPE_CACHE_LOG . " object_type,
746 746
                     log_id object_id,
747 747
                     consumer_key
748 748
                 FROM okapi_cache_logs
Please login to merge, or discard this patch.
htdocs/okapi/views/changelog_helper.inc.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
                     throw new ErrorException();
44 44
                 }
45 45
                 Cache::set($cache_key, $changes_xml, 3600);
46
-                Cache::set($cache_backup_key, $changes_xml, 3600*24*30);
46
+                Cache::set($cache_backup_key, $changes_xml, 3600 * 24 * 30);
47 47
             }
48 48
             catch (Exception $e)
49 49
             {
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
                 $changes_xml = Cache::get($cache_backup_key);
53 53
                 if ($changes_xml) {
54
-                    Cache::set($cache_key, $changes_xml, 3600*12);
54
+                    Cache::set($cache_key, $changes_xml, 3600 * 12);
55 55
                 }
56 56
             }
57 57
         }
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/cronreport.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
         $response->content_type = "text/plain; charset=utf-8";
27 27
         ob_start();
28 28
 
29
-        require_once($GLOBALS['rootpath']."okapi/cronjobs.php");
29
+        require_once($GLOBALS['rootpath'] . "okapi/cronjobs.php");
30 30
         $schedule = Cache::get("cron_schedule");
31 31
         if ($schedule == null)
32 32
             $schedule = array();
33 33
         print "Nearest event: ";
34 34
         if (Okapi::get_var('cron_nearest_event'))
35
-            print "in ".(Okapi::get_var('cron_nearest_event') - time())." seconds.\n\n";
35
+            print "in " . (Okapi::get_var('cron_nearest_event') - time()) . " seconds.\n\n";
36 36
         else
37 37
             print "NOT SET\n\n";
38 38
         $cronjobs = CronJobController::get_enabled_cronjobs();
@@ -43,27 +43,27 @@  discard block
 block discarded – undo
43 43
                 return $by_type;
44 44
             return $cmp($a->get_name(), $b->get_name());
45 45
         });
46
-        print str_pad("TYPE", 11)."  ".str_pad("NAME", 40)."  SCHEDULE\n";
47
-        print str_pad("----", 11)."  ".str_pad("----", 40)."  --------\n";
46
+        print str_pad("TYPE", 11) . "  " . str_pad("NAME", 40) . "  SCHEDULE\n";
47
+        print str_pad("----", 11) . "  " . str_pad("----", 40) . "  --------\n";
48 48
         foreach ($cronjobs as $cronjob)
49 49
         {
50 50
             $type = $cronjob->get_type();
51 51
             $name = $cronjob->get_name();
52
-            print str_pad($type, 11)."  ".str_pad($name, 40)."  ";
52
+            print str_pad($type, 11) . "  " . str_pad($name, 40) . "  ";
53 53
             if (!isset($schedule[$name]))
54 54
                 print "NOT YET SCHEDULED\n";
55 55
             elseif ($schedule[$name] <= time())
56
-                print "DELAYED: should be run ".(time() - $schedule[$name])." seconds ago\n";
56
+                print "DELAYED: should be run " . (time() - $schedule[$name]) . " seconds ago\n";
57 57
             else
58
-                print "scheduled to run in ".str_pad($schedule[$name] - time(), 6, " ", STR_PAD_LEFT)." seconds\n";
58
+                print "scheduled to run in " . str_pad($schedule[$name] - time(), 6, " ", STR_PAD_LEFT) . " seconds\n";
59 59
         }
60 60
         print "\n";
61 61
         print "Crontab last ping: ";
62 62
         if (Cache::get('crontab_last_ping'))
63
-            print (time() - Cache::get('crontab_last_ping'))." seconds ago";
63
+            print (time() - Cache::get('crontab_last_ping')) . " seconds ago";
64 64
         else
65 65
             print "NEVER";
66
-        print " (crontab_check_counter: ".Cache::get('crontab_check_counter').").\n";
66
+        print " (crontab_check_counter: " . Cache::get('crontab_check_counter') . ").\n";
67 67
         print "clog_revisions_daily: ";
68 68
         if (Cache::get('clog_revisions_daily'))
69 69
         {
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/tilereport.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     {
22 22
         # Flush the stats, so the page is fresh upon every request.
23 23
 
24
-        require_once($GLOBALS['rootpath']."okapi/cronjobs.php");
24
+        require_once($GLOBALS['rootpath'] . "okapi/cronjobs.php");
25 25
         CronJobController::force_run("StatsWriterCronJob");
26 26
 
27 27
         # When services/caches/map/tile method is called, it writes some extra
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         ob_start();
34 34
 
35 35
         $start = isset($_GET['start']) ? $_GET['start'] : date(
36
-            "Y-m-d 00:00:00", time() - 7*86400);
36
+            "Y-m-d 00:00:00", time() - 7 * 86400);
37 37
         $end = isset($_GET['end']) ? $_GET['end'] : date("Y-m-d 23:59:59");
38 38
 
39 39
         print "From: $start\n";
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
                 sum(total_runtime)
47 47
             from okapi_stats_hourly
48 48
             where
49
-                period_start >= '".Db::escape_string($start)."'
50
-                and period_start < '".Db::escape_string($end)."'
49
+                period_start >= '".Db::escape_string($start) . "'
50
+                and period_start < '".Db::escape_string($end) . "'
51 51
                 and service_name like '%caches/map/tile%'
52 52
             group by service_name
53 53
         ");
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         }
73 73
         if ($total_calls != $calls['A'])
74 74
         {
75
-            print "Partial results. Only ".$calls['A']." out of $total_calls are covered.\n";
75
+            print "Partial results. Only " . $calls['A'] . " out of $total_calls are covered.\n";
76 76
             print "All other will count as \"unaccounted for\".\n\n";
77 77
             $total_calls = $calls['A'];
78 78
         }
@@ -80,37 +80,37 @@  discard block
 block discarded – undo
80 80
         $calls_left = $total_calls;
81 81
         $runtime_left = $total_runtime;
82 82
 
83
-        $perc = function($a, $b) { return ($b > 0) ? sprintf("%.1f", 100 * $a / $b)."%" : "(?)"; };
84
-        $avg = function($a, $b) { return ($b > 0) ? sprintf("%.4f", $a / $b)."s" : "(?)"; };
83
+        $perc = function($a, $b) { return ($b > 0) ? sprintf("%.1f", 100 * $a / $b) . "%" : "(?)"; };
84
+        $avg = function($a, $b) { return ($b > 0) ? sprintf("%.4f", $a / $b) . "s" : "(?)"; };
85 85
         $get_stats = function() use (&$calls_left, &$runtime_left, &$total_calls, &$total_runtime, &$perc)
86 86
         {
87 87
             return (
88
-                str_pad($perc($calls_left, $total_calls), 6, " ", STR_PAD_LEFT).
88
+                str_pad($perc($calls_left, $total_calls), 6, " ", STR_PAD_LEFT) .
89 89
                 str_pad($perc($runtime_left, $total_runtime), 7, " ", STR_PAD_LEFT)
90 90
             );
91 91
         };
92 92
 
93 93
         print "%CALLS  %TIME  Description\n";
94 94
         print "====== ======  ======================================================================\n";
95
-        print $get_stats()."  $total_calls responses served. Total runtime: ".sprintf("%.2f", $total_runtime)."s\n";
95
+        print $get_stats() . "  $total_calls responses served. Total runtime: " . sprintf("%.2f", $total_runtime) . "s\n";
96 96
         print "\n";
97 97
         print "               All of these requests needed a TileTree build/lookup. The average runtime of\n";
98
-        print "               these lookups was ".$avg($runtime['A'], $total_calls).". ".$perc($runtime['A'], $total_runtime)." of total runtime was spent here.\n";
98
+        print "               these lookups was " . $avg($runtime['A'], $total_calls) . ". " . $perc($runtime['A'], $total_runtime) . " of total runtime was spent here.\n";
99 99
         print "\n";
100 100
 
101 101
         $runtime_left -= $runtime['A'];
102 102
 
103
-        print $get_stats()."  All calls passed here after ~".$avg($runtime['A'], $total_calls)."\n";
103
+        print $get_stats() . "  All calls passed here after ~" . $avg($runtime['A'], $total_calls) . "\n";
104 104
 
105 105
         print "\n";
106 106
         print "               Lookup result was then processed and \"image description\" was created. It was\n";
107 107
         print "               passed on to the TileRenderer to compute the ETag hash string. The average runtime\n";
108
-        print "               of this part was ".$avg($runtime['B'], $total_calls).". ".$perc($runtime['B'], $total_runtime)." of total runtime was spent here.\n";
108
+        print "               of this part was " . $avg($runtime['B'], $total_calls) . ". " . $perc($runtime['B'], $total_runtime) . " of total runtime was spent here.\n";
109 109
         print "\n";
110 110
 
111 111
         $runtime_left -= $runtime['B'];
112 112
 
113
-        print $get_stats()."  All calls passed here after ~".$avg($runtime['A'] + $runtime['B'], $total_calls)."\n";
113
+        print $get_stats() . "  All calls passed here after ~" . $avg($runtime['A'] + $runtime['B'], $total_calls) . "\n";
114 114
 
115 115
         $etag_hits = $calls['B'] - $calls['C'];
116 116
 
@@ -120,29 +120,29 @@  discard block
 block discarded – undo
120 120
 
121 121
         $calls_left = $calls['C'];
122 122
 
123
-        print $get_stats()."  $calls_left calls passed here after ~".$avg($runtime['A'] + $runtime['B'], $total_calls)."\n";
123
+        print $get_stats() . "  $calls_left calls passed here after ~" . $avg($runtime['A'] + $runtime['B'], $total_calls) . "\n";
124 124
 
125 125
         $imagecache_hits = $calls['C'] - $calls['D'];
126 126
 
127 127
         print "\n";
128 128
         print "               $imagecache_hits of these calls hit the server image cache.\n";
129
-        print "               ".$perc($runtime['C'], $total_runtime)." of total runtime was spent to find these.\n";
129
+        print "               " . $perc($runtime['C'], $total_runtime) . " of total runtime was spent to find these.\n";
130 130
         print "\n";
131 131
 
132 132
         $calls_left = $calls['D'];
133 133
         $runtime_left -= $runtime['C'];
134 134
 
135
-        print $get_stats()."  $calls_left calls passed here after ~".$avg($runtime['A'] + $runtime['B'] + $runtime['C'], $total_calls)."\n";
135
+        print $get_stats() . "  $calls_left calls passed here after ~" . $avg($runtime['A'] + $runtime['B'] + $runtime['C'], $total_calls) . "\n";
136 136
         print "\n";
137 137
         print "               These calls required the tile to be rendered. On average, it took\n";
138
-        print "               ".$avg($runtime['D'], $calls['D'])." to *render* a tile.\n";
139
-        print "               ".$perc($runtime['D'], $total_runtime)." of total runtime was spent here.\n";
138
+        print "               " . $avg($runtime['D'], $calls['D']) . " to *render* a tile.\n";
139
+        print "               " . $perc($runtime['D'], $total_runtime) . " of total runtime was spent here.\n";
140 140
         print "\n";
141 141
 
142 142
         $runtime_left -= $runtime['D'];
143 143
 
144
-        print $perc($runtime_left, $total_runtime)." of runtime was unaccounted for (other processing).\n";
145
-        print "Average response time was ".$avg($total_runtime, $total_calls).".\n\n";
144
+        print $perc($runtime_left, $total_runtime) . " of runtime was unaccounted for (other processing).\n";
145
+        print "Average response time was " . $avg($total_runtime, $total_calls) . ".\n\n";
146 146
 
147 147
         print "Current okapi_cache score distribution:\n";
148 148
         $rs = Db::query("
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
         ");
154 154
         while (list($log2, $count, $size) = Db::fetch_row($rs))
155 155
         {
156
-            print $count." elements ($size bytes) with score between ".pow(2, $log2)." and ".pow(2, $log2 + 1).".\n";
156
+            print $count . " elements ($size bytes) with score between " . pow(2, $log2) . " and " . pow(2, $log2 + 1) . ".\n";
157 157
         }
158 158
 
159 159
         $response->body = ob_get_clean();
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/attrlist.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
             print "$id: $name\n";
35 35
 
36 36
         print "\nAttributes:\n\n";
37
-        require_once($GLOBALS['rootpath'].'okapi/services/attrs/attr_helper.inc.php');
37
+        require_once($GLOBALS['rootpath'] . 'okapi/services/attrs/attr_helper.inc.php');
38 38
         $internal2acode = AttrHelper::get_internal_id_to_acode_mapping();
39 39
         $dict = self::get_all_attribute_names();
40 40
         foreach ($dict as $internal_id => $langs)
41 41
         {
42
-            print $internal_id.": ";
42
+            print $internal_id . ": ";
43 43
             $langkeys = array_keys($langs);
44 44
             sort($langkeys);
45 45
             if (in_array('en', $langkeys))
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
             else
48 48
                 print ">>>> ENGLISH NAME UNSET! <<<<";
49 49
             if (isset($internal2acode[$internal_id]))
50
-                print " - ".$internal2acode[$internal_id];
50
+                print " - " . $internal2acode[$internal_id];
51 51
             else
52 52
                 print " - >>>> MISSING A-CODE MAPPING <<<<";
53 53
             print "\n";
54 54
             foreach ($langkeys as $langkey)
55
-                print "        $langkey: ".$langs[$langkey]."\n";
55
+                print "        $langkey: " . $langs[$langkey] . "\n";
56 56
         }
57 57
 
58 58
         print "\nAttribute notices:\n\n";
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         {
65 65
             if (!isset($internal2acode[$internal_id]))
66 66
             {
67
-                print "(!) Attribute ".$internal_id." is not mapped to any A-code.\n";
67
+                print "(!) Attribute " . $internal_id . " is not mapped to any A-code.\n";
68 68
                 continue;
69 69
             }
70 70
             $acode = $internal2acode[$internal_id];
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                 {
87 87
                     print "( ) Attribute $acode has a different name in the '$lang' language\n";
88 88
                     print "    Local name: $value\n";
89
-                    print "    OKAPI name: ".$attr['names'][$lang]."\n";
89
+                    print "    OKAPI name: " . $attr['names'][$lang] . "\n";
90 90
                 }
91 91
             }
92 92
         }
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/dbstruct.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 
40 40
         ini_set('memory_limit', '16M');
41 41
         $shell_arguments = "mysqldump --no-data -h$dbserver -u$user -p$password $dbname";
42
-        if (!strpos($shell_arguments,"--no-data"))
42
+        if (!strpos($shell_arguments, "--no-data"))
43 43
             throw new Exception("wrong database dump arguments");
44 44
         $struct = shell_exec($shell_arguments);
45 45
         if (strlen($struct) > 1000000)
46 46
             throw new Exception("something went terribly wrong while dumping table structures");
47
-        if (stripos($struct,"dumping data") !== FALSE)
47
+        if (stripos($struct, "dumping data") !== FALSE)
48 48
             throw new Exception("something went terribly wrong while dumping table structures");
49 49
 
50 50
         # Remove the "AUTO_INCREMENT=..." values. They break the diffs.
@@ -74,30 +74,30 @@  discard block
 block discarded – undo
74 74
                 try {
75 75
                     $alternate_struct = @file_get_contents($_GET['compare_to']);
76 76
                 } catch (Exception $e) {
77
-                    throw new BadRequest("Failed to load ".$_GET['compare_to']);
77
+                    throw new BadRequest("Failed to load " . $_GET['compare_to']);
78 78
                 }
79 79
                 $response->body =
80
-                    "-- Automatically generated database diff. Use with caution!\n".
81
-                    "-- Differences obtained with help of cool library by Kirill Gerasimenko.\n\n".
82
-                    "-- Note: The following script has some limitations. It will render database\n".
83
-                    "-- structure compatible, but not necessarilly EXACTLY the same. It might be\n".
80
+                    "-- Automatically generated database diff. Use with caution!\n" .
81
+                    "-- Differences obtained with help of cool library by Kirill Gerasimenko.\n\n" .
82
+                    "-- Note: The following script has some limitations. It will render database\n" .
83
+                    "-- structure compatible, but not necessarilly EXACTLY the same. It might be\n" .
84 84
                     "-- better to use manual diff instead.\n\n";
85 85
                 require_once("comparator.inc.php");
86 86
                 $updater = new \dbStructUpdater();
87 87
                 if (isset($_GET['reverse']) && ($_GET['reverse'] == 'true'))
88 88
                 {
89 89
                     $response->body .=
90
-                        "-- REVERSE MODE. The following will alter [2], so that it has the structure of [1].\n".
91
-                        "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n".
92
-                        "-- 2. ".$_GET['compare_to']." (".md5($alternate_struct).")\n\n";
90
+                        "-- REVERSE MODE. The following will alter [2], so that it has the structure of [1].\n" .
91
+                        "-- 1. " . Settings::get('SITE_URL') . "okapi/devel/dbstruct (" . md5($struct) . ")\n" .
92
+                        "-- 2. " . $_GET['compare_to'] . " (" . md5($alternate_struct) . ")\n\n";
93 93
                     $alters = $updater->getUpdates($alternate_struct, $struct);
94 94
                 }
95 95
                 else
96 96
                 {
97 97
                     $response->body .=
98
-                        "-- The following will alter [1], so that it has the structure of [2].\n".
99
-                        "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n".
100
-                        "-- 2. ".$_GET['compare_to']." (".md5($alternate_struct).")\n\n";
98
+                        "-- The following will alter [1], so that it has the structure of [2].\n" .
99
+                        "-- 1. " . Settings::get('SITE_URL') . "okapi/devel/dbstruct (" . md5($struct) . ")\n" .
100
+                        "-- 2. " . $_GET['compare_to'] . " (" . md5($alternate_struct) . ")\n\n";
101 101
                     $alters = $updater->getUpdates($struct, $alternate_struct);
102 102
                 }
103 103
                 # Add semicolons
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
                     if (strpos($alter_ref, "okapi_") !== false)
111 111
                     {
112 112
                         $lines = explode("\n", $alter_ref);
113
-                        $alter_ref = "-- Probably you should NOT execute this one. Use okapi/update instead.\n-- {{{\n--   ".
114
-                            implode("\n--   ", $lines)."\n-- }}}";
113
+                        $alter_ref = "-- Probably you should NOT execute this one. Use okapi/update instead.\n-- {{{\n--   " .
114
+                            implode("\n--   ", $lines) . "\n-- }}}";
115 115
                     }
116 116
                 }
117 117
                 if (count($alters) > 0)
118
-                    $response->body .= implode("\n", $alters)."\n";
118
+                    $response->body .= implode("\n", $alters) . "\n";
119 119
                 else
120 120
                     $response->body .= "-- No differences found\n";
121 121
             }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     private static function requireSafe($url)
138 138
     {
139
-        require_once($GLOBALS['rootpath'].'okapi/service_runner.php');
139
+        require_once($GLOBALS['rootpath'] . 'okapi/service_runner.php');
140 140
         $installations = OkapiServiceRunner::call(
141 141
             "services/apisrv/installations",
142 142
             new OkapiInternalRequest(
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
         );
146 146
         $allowed = array();
147 147
         foreach ($installations as $i) {
148
-            $allowed_url = $i['okapi_base_url']."devel/dbstruct";
148
+            $allowed_url = $i['okapi_base_url'] . "devel/dbstruct";
149 149
             $allowed[] = $allowed_url;
150 150
             if ($url == $allowed_url) {
151 151
                 return;
152 152
             }
153 153
         }
154 154
         throw new BadRequest(
155
-            "The following URL is not on our whitelist: \"".$url."\".\n\n".
156
-            "Please use one of the following:\n".
157
-            "\"".implode("\",\n\"", $allowed)."\"."
155
+            "The following URL is not on our whitelist: \"" . $url . "\".\n\n" .
156
+            "Please use one of the following:\n" .
157
+            "\"" . implode("\",\n\"", $allowed) . "\"."
158 158
         );
159 159
     }
160 160
 }
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/clogentry.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
         $tmp = Db::select_value("
26 26
             select data
27 27
             from okapi_clog
28
-            where id='".Db::escape_string($_GET['id'])."'
28
+            where id='".Db::escape_string($_GET['id']) . "'
29 29
         ");
30 30
         $data = unserialize(gzinflate($tmp));
31 31
 
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/comparator.inc.php 1 patch
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
 */
53 53
 class dbStructUpdater
54 54
 {
55
-    var $sourceStruct = '';//structure dump of the reference database
56
-    var $destStruct = '';//structure dump of database to update
57
-    var $config = array();//updater configuration
55
+    var $sourceStruct = ''; //structure dump of the reference database
56
+    var $destStruct = ''; //structure dump of database to update
57
+    var $config = array(); //updater configuration
58 58
 
59 59
     /**
60 60
     * Constructor
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     * merges current updater config with the given one
86 86
     * @param assoc_array $config new configuration values
87 87
     */
88
-    function setConfig($config=array())
88
+    function setConfig($config = array())
89 89
     {
90 90
         if (is_array($config))
91 91
         {
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
     * @param bool $asString if true - result will be a string, otherwise - array
102 102
     * @return array|string update sql statements - in array or string (separated with ';')
103 103
     */
104
-    function getUpdates($source, $dest, $asString=false)
104
+    function getUpdates($source, $dest, $asString = false)
105 105
     {
106
-        $result = $asString?'':array();
106
+        $result = $asString ? '' : array();
107 107
         $compRes = $this->compare($source, $dest);
108 108
         if (empty($compRes))
109 109
         {
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         $result = $this->getDiffSql($compRes);
118 118
         if ($asString)
119 119
         {
120
-            $result = implode(";\r\n", $result).';';
120
+            $result = implode(";\r\n", $result) . ';';
121 121
         }
122 122
         return $result;
123 123
     }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
         }
139 139
         $allowedActions = array('create', 'drop', 'add', 'remove', 'modify');
140 140
         $updateActions = array_intersect($updateActions, $allowedActions);
141
-        foreach($compRes as $table=>$info)
141
+        foreach ($compRes as $table=>$info)
142 142
         {
143 143
             if ($info['sourceOrphan'])
144 144
             {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                     $result[$table] = $info;
155 155
                 }
156 156
             }
157
-            elseif($info['differs'])
157
+            elseif ($info['differs'])
158 158
             {
159 159
                 $resultInfo = $info;
160 160
                 unset($resultInfo['differs']);
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
                     {
169 169
                         $resultInfo['differs'][] = $diff;
170 170
                     }
171
-                    elseif(in_array('modify', $updateActions))
171
+                    elseif (in_array('modify', $updateActions))
172 172
                     {
173 173
                         $resultInfo['differs'][] = $diff;
174 174
                     }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
             return false;
194 194
         }
195 195
         $result = array('sourceOrphans'=>array(), 'destOrphans'=>array(), 'different'=>array());
196
-        foreach($compRes as $table=>$info)
196
+        foreach ($compRes as $table=>$info)
197 197
         {
198 198
             if ($info['sourceOrphan'])
199 199
             {
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         foreach ($all as $tab)
243 243
         {
244 244
             $info = array('destOrphan'=>false, 'sourceOrphan'=>false, 'differs'=>false);
245
-            if(in_array($tab, $destOrphans))
245
+            if (in_array($tab, $destOrphans))
246 246
             {
247 247
                 $info['destOrphan'] = true;
248 248
             }
@@ -255,16 +255,16 @@  discard block
 block discarded – undo
255 255
                 $destSql = $this->getTabSql($this->destStruct, $tab, true);
256 256
                 $sourceSql = $this->getTabSql($this->sourceStruct, $tab, true);
257 257
                 $diffs = $this->compareSql($sourceSql, $destSql);
258
-                if ($diffs===false)
258
+                if ($diffs === false)
259 259
                 {
260
-                    trigger_error('[WARNING] error parsing definition of table "'.$tab.'" - skipped');
260
+                    trigger_error('[WARNING] error parsing definition of table "' . $tab . '" - skipped');
261 261
                     continue;
262 262
                 }
263 263
                 elseif (!empty($diffs))//not empty array
264 264
                 {
265 265
                     $info['differs'] = $diffs;
266 266
                 }
267
-                else continue;//empty array
267
+                else continue; //empty array
268 268
             }
269 269
             $result[$tab] = $info;
270 270
         }
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
         $result = array();
282 282
         if (preg_match_all('/CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?(?:`?(\w+)`?\.)?`?(\w+)`?/i', $struct, $m))
283 283
         {
284
-            foreach($m[2] as $match)//m[1] is a database name if any
284
+            foreach ($m[2] as $match)//m[1] is a database name if any
285 285
             {
286 286
                 $result[] = $match;
287 287
             }
@@ -297,17 +297,17 @@  discard block
 block discarded – undo
297 297
     * @param bool $removeDatabase - either to remove database name in "CREATE TABLE database.tab"-like declarations
298 298
     * @return string table structure definition
299 299
     */
300
-    function getTabSql($struct, $tab, $removeDatabase=true)
300
+    function getTabSql($struct, $tab, $removeDatabase = true)
301 301
     {
302 302
         $result = '';
303 303
         /* create table should be single line in this case*/
304 304
         //1 - part before database, 2-database name, 3 - part after database
305
-        if (preg_match('/(CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?)(?:`?(\w+)`?\.)?(`?('.$tab.')`?(\W|$))/i', $struct, $m, PREG_OFFSET_CAPTURE))
305
+        if (preg_match('/(CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?)(?:`?(\w+)`?\.)?(`?(' . $tab . ')`?(\W|$))/i', $struct, $m, PREG_OFFSET_CAPTURE))
306 306
         {
307 307
             $tableDef = $m[0][0];
308 308
             $start = $m[0][1];
309 309
             $database = $m[2][0];
310
-            $offset = $start+strlen($m[0][0]);
310
+            $offset = $start + strlen($m[0][0]);
311 311
             $end = $this->getDelimPos($struct, $offset);
312 312
             if ($end === false)
313 313
             {
@@ -315,13 +315,13 @@  discard block
 block discarded – undo
315 315
             }
316 316
             else
317 317
             {
318
-                $result = substr($struct, $start, $end-$start);//already without ';'
318
+                $result = substr($struct, $start, $end - $start); //already without ';'
319 319
             }
320 320
         }
321 321
         $result = trim($result);
322 322
         if ($database && $removeDatabase)
323 323
         {
324
-            $result = str_replace($tableDef, $m[1][0].$m[3][0], $result);
324
+            $result = str_replace($tableDef, $m[1][0] . $m[3][0], $result);
325 325
         }
326 326
         return $result;
327 327
     }
@@ -335,27 +335,27 @@  discard block
 block discarded – undo
335 335
         $result = array();
336 336
         //find opening bracket, get the prefix along with it
337 337
         $openBracketPos = $this->getDelimPos($sql, 0, '(');
338
-        if ($openBracketPos===false)
338
+        if ($openBracketPos === false)
339 339
         {
340 340
             trigger_error('[WARNING] can not find opening bracket in table definition');
341 341
             return false;
342 342
         }
343
-        $prefix = substr($sql, 0, $openBracketPos+1);//prefix can not be empty, so do not check it, just trim
343
+        $prefix = substr($sql, 0, $openBracketPos + 1); //prefix can not be empty, so do not check it, just trim
344 344
         $result[] = trim($prefix);
345
-        $body = substr($sql, strlen($prefix));//fields, indexes and part after closing bracket
345
+        $body = substr($sql, strlen($prefix)); //fields, indexes and part after closing bracket
346 346
         //split by commas, get part by part
347
-        while(($commaPos = $this->getDelimPos($body, 0, ',', true))!==false)
347
+        while (($commaPos = $this->getDelimPos($body, 0, ',', true)) !== false)
348 348
         {
349
-            $part = trim(substr($body, 0, $commaPos+1));//read another part and shorten $body
349
+            $part = trim(substr($body, 0, $commaPos + 1)); //read another part and shorten $body
350 350
             if ($part)
351 351
             {
352 352
                 $result[] = $part;
353 353
             }
354
-            $body = substr($body, $commaPos+1);
354
+            $body = substr($body, $commaPos + 1);
355 355
         }
356 356
         //here we have last field (or index) definition + part after closing bracket (ENGINE, ect)
357 357
         $closeBracketPos = $this->getDelimRpos($body, 0, ')');
358
-        if ($closeBracketPos===false)
358
+        if ($closeBracketPos === false)
359 359
         {
360 360
             trigger_error('[WARNING] can not find closing bracket in table definition');
361 361
             return false;
@@ -389,27 +389,27 @@  discard block
 block discarded – undo
389 389
     {
390 390
         $result = array();
391 391
         //split with comma delimiter, not line breaks
392
-        $sourceParts =  $this->splitTabSql($sourceSql);
393
-        if ($sourceParts===false)//error parsing sql
392
+        $sourceParts = $this->splitTabSql($sourceSql);
393
+        if ($sourceParts === false)//error parsing sql
394 394
         {
395 395
             trigger_error('[WARNING] error parsing source sql');
396 396
             return false;
397 397
         }
398 398
         $destParts = $this->splitTabSql($destSql);
399
-        if ($destParts===false)
399
+        if ($destParts === false)
400 400
         {
401 401
             trigger_error('[WARNING] error parsing destination sql');
402 402
             return false;
403 403
         }
404 404
         $sourcePartsIndexed = array();
405 405
         $destPartsIndexed = array();
406
-        foreach($sourceParts as $line)
406
+        foreach ($sourceParts as $line)
407 407
         {
408 408
             $lineInfo = $this->processLine($line);
409 409
             if (!$lineInfo) continue;
410 410
             $sourcePartsIndexed[$lineInfo['key']] = $lineInfo['line'];
411 411
         }
412
-        foreach($destParts as $line)
412
+        foreach ($destParts as $line)
413 413
         {
414 414
             $lineInfo = $this->processLine($line);
415 415
             if (!$lineInfo) continue;
@@ -418,16 +418,16 @@  discard block
 block discarded – undo
418 418
         $sourceKeys = array_keys($sourcePartsIndexed);
419 419
         $destKeys = array_keys($destPartsIndexed);
420 420
         $all = array_unique(array_merge($sourceKeys, $destKeys));
421
-        sort($all);//fields first, then indexes - because fields are prefixed with '!'
421
+        sort($all); //fields first, then indexes - because fields are prefixed with '!'
422 422
 
423 423
         foreach ($all as $key)
424 424
         {
425 425
             $info = array('source'=>'', 'dest'=>'');
426
-            $inSource= in_array($key, $sourceKeys);
427
-            $inDest= in_array($key, $destKeys);
426
+            $inSource = in_array($key, $sourceKeys);
427
+            $inDest = in_array($key, $destKeys);
428 428
             $sourceOrphan = $inSource && !$inDest;
429 429
             $destOrphan = $inDest && !$inSource;
430
-            $different =  $inSource && $inDest &&
430
+            $different = $inSource && $inDest &&
431 431
             strcasecmp($this->normalizeString($destPartsIndexed[$key]), $this->normalizeString($sourcePartsIndexed[$key]));
432 432
             if ($sourceOrphan)
433 433
             {
@@ -472,11 +472,11 @@  discard block
 block discarded – undo
472 472
         }
473 473
         elseif (preg_match('/^`?\w+`?/i', $line, $m))//field definition
474 474
         {
475
-            $key = '!'.$m[0];//to make sure fields will be synchronised before the keys
475
+            $key = '!' . $m[0]; //to make sure fields will be synchronised before the keys
476 476
         }
477 477
         else
478 478
         {
479
-            return false;//line has no valuable info (empty or comment)
479
+            return false; //line has no valuable info (empty or comment)
480 480
         }
481 481
         //$key = str_replace('`', '', $key);
482 482
         if (!empty($options['varcharDefaultIgnore']))
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
             $line = preg_replace("/ AUTO_INCREMENT=[0-9]+/i", '', $line);
493 493
         }
494 494
         $result['key'] = $this->normalizeString($key);
495
-        $result['line']= $line;
495
+        $result['line'] = $line;
496 496
         return $result;
497 497
     }
498 498
 
@@ -512,11 +512,11 @@  discard block
 block discarded – undo
512 512
         {
513 513
             return $sqls;
514 514
         }
515
-        foreach($diff as $tab=>$info)
515
+        foreach ($diff as $tab=>$info)
516 516
         {
517 517
             if ($info['sourceOrphan'])//delete it
518 518
             {
519
-                $sqls[] = 'DROP TABLE `'.$tab.'`';
519
+                $sqls[] = 'DROP TABLE `' . $tab . '`';
520 520
             }
521 521
             elseif ($info['destOrphan'])//create destination table in source
522 522
             {
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
             }
539 539
             else
540 540
             {
541
-                foreach($info['differs'] as $finfo)
541
+                foreach ($info['differs'] as $finfo)
542 542
                 {
543 543
                     $inDest = !empty($finfo['dest']);
544 544
                     $inSource = !empty($finfo['source']);
@@ -575,53 +575,53 @@  discard block
 block discarded – undo
575 575
     */
576 576
     function getActionSql($action, $tab, $sql)
577 577
     {
578
-        $result = 'ALTER TABLE `'.$tab.'` ';
578
+        $result = 'ALTER TABLE `' . $tab . '` ';
579 579
         $action = strtolower($action);
580
-        $keyField = '`?\w`?(?:\(\d+\))?';//matches `name`(10)
581
-        $keyFieldList = '(?:'.$keyField.'(?:,\s?)?)+';//matches `name`(10),`desc`(255)
582
-        if (preg_match('/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\('.$keyFieldList.'\))/i', $sql, $m))
580
+        $keyField = '`?\w`?(?:\(\d+\))?'; //matches `name`(10)
581
+        $keyFieldList = '(?:' . $keyField . '(?:,\s?)?)+'; //matches `name`(10),`desc`(255)
582
+        if (preg_match('/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\(' . $keyFieldList . '\))/i', $sql, $m))
583 583
         {   //key and index operations
584 584
             $type = strtolower(trim($m[1]));
585 585
             $name = trim($m[2]);
586 586
             $fields = trim($m[3]);
587
-            switch($action)
587
+            switch ($action)
588 588
             {
589 589
                 case 'drop':
590
-                    if ($type=='primary')
590
+                    if ($type == 'primary')
591 591
                     {
592
-                        $result.= 'DROP PRIMARY KEY';
592
+                        $result .= 'DROP PRIMARY KEY';
593 593
                     }
594 594
                     else
595 595
                     {
596
-                        $result.= 'DROP INDEX `'.$name.'`';
596
+                        $result .= 'DROP INDEX `' . $name . '`';
597 597
                     }
598 598
                 break;
599 599
                 case 'add':
600
-                    if ($type=='primary')
600
+                    if ($type == 'primary')
601 601
                     {
602
-                        $result.= 'ADD PRIMARY KEY '.$fields;
602
+                        $result .= 'ADD PRIMARY KEY ' . $fields;
603 603
                     }
604
-                    elseif ($type=='')
604
+                    elseif ($type == '')
605 605
                     {
606
-                        $result.= 'ADD INDEX `'.$name.'` '.$fields;
606
+                        $result .= 'ADD INDEX `' . $name . '` ' . $fields;
607 607
                     }
608 608
                     else
609 609
                     {
610
-                        $result .='ADD '.strtoupper($type).' `'.$name.'` '.$fields;//fulltext or unique
610
+                        $result .= 'ADD ' . strtoupper($type) . ' `' . $name . '` ' . $fields; //fulltext or unique
611 611
                     }
612 612
                 break;
613 613
                 case 'modify':
614
-                    if ($type=='primary')
614
+                    if ($type == 'primary')
615 615
                     {
616
-                        $result.='DROP PRIMARY KEY, ADD PRIMARY KEY '.$fields;
616
+                        $result .= 'DROP PRIMARY KEY, ADD PRIMARY KEY ' . $fields;
617 617
                     }
618
-                    elseif ($type=='')
618
+                    elseif ($type == '')
619 619
                     {
620
-                        $result.='DROP INDEX `'.$name.'`, ADD INDEX `'.$name.'` '.$fields;
620
+                        $result .= 'DROP INDEX `' . $name . '`, ADD INDEX `' . $name . '` ' . $fields;
621 621
                     }
622 622
                     else
623 623
                     {
624
-                        $result.='DROP INDEX `'.$name.'`, ADD '.strtoupper($type).' `'.$name.'` '.$fields;//fulltext or unique
624
+                        $result .= 'DROP INDEX `' . $name . '`, ADD ' . strtoupper($type) . ' `' . $name . '` ' . $fields; //fulltext or unique
625 625
                     }
626 626
                 break;
627 627
 
@@ -630,15 +630,15 @@  discard block
 block discarded – undo
630 630
         else //fields operations
631 631
         {
632 632
             $sql = rtrim(trim($sql), ',');
633
-            $result.= strtoupper($action);
634
-            if ($action=='drop')
633
+            $result .= strtoupper($action);
634
+            if ($action == 'drop')
635 635
             {
636 636
                 $spacePos = strpos($sql, ' ');
637
-                $result.= ' '.substr($sql, 0, $spacePos);
637
+                $result .= ' ' . substr($sql, 0, $spacePos);
638 638
             }
639 639
             else
640 640
             {
641
-                $result.= ' '.$sql;
641
+                $result .= ' ' . $sql;
642 642
             }
643 643
         }
644 644
         return $result;
@@ -651,39 +651,39 @@  discard block
 block discarded – undo
651 651
     * Handles escaped \" and \'. Also handles sql comments.
652 652
     * Actualy it is regex-based Finit State Machine (FSN)
653 653
     */
654
-    function getDelimPos($string, $offset=0, $delim=';', $skipInBrackets=false)
654
+    function getDelimPos($string, $offset = 0, $delim = ';', $skipInBrackets = false)
655 655
     {
656 656
         $stack = array();
657
-        $rbs = '\\\\';  //reg - escaped backslash
657
+        $rbs = '\\\\'; //reg - escaped backslash
658 658
         $regPrefix = "(?<!$rbs)(?:$rbs{2})*";
659
-        $reg = $regPrefix.'("|\')|(/\\*)|(\\*/)|(-- )|(\r\n|\r|\n)|';
659
+        $reg = $regPrefix . '("|\')|(/\\*)|(\\*/)|(-- )|(\r\n|\r|\n)|';
660 660
         if ($skipInBrackets)
661 661
         {
662
-            $reg.='(\(|\))|';
662
+            $reg .= '(\(|\))|';
663 663
         }
664 664
         else
665 665
         {
666
-            $reg.='()';
666
+            $reg .= '()';
667 667
         }
668
-        $reg .= '('.preg_quote($delim).')';
669
-        while (preg_match('%'.$reg.'%', $string, $m, PREG_OFFSET_CAPTURE, $offset))
668
+        $reg .= '(' . preg_quote($delim) . ')';
669
+        while (preg_match('%' . $reg . '%', $string, $m, PREG_OFFSET_CAPTURE, $offset))
670 670
         {
671
-            $offset = $m[0][1]+strlen($m[0][0]);
672
-            if (end($stack)=='/*')
671
+            $offset = $m[0][1] + strlen($m[0][0]);
672
+            if (end($stack) == '/*')
673 673
             {
674 674
                 if (!empty($m[3][0]))
675 675
                 {
676 676
                     array_pop($stack);
677 677
                 }
678
-                continue;//here we could also simplify regexp
678
+                continue; //here we could also simplify regexp
679 679
             }
680
-            if (end($stack)=='-- ')
680
+            if (end($stack) == '-- ')
681 681
             {
682 682
                 if (!empty($m[5][0]))
683 683
                 {
684 684
                     array_pop($stack);
685 685
                 }
686
-                continue;//here we could also simplify regexp
686
+                continue; //here we could also simplify regexp
687 687
             }
688 688
 
689 689
             if (!empty($m[7][0]))// ';' found
@@ -699,18 +699,18 @@  discard block
 block discarded – undo
699 699
             }
700 700
             if (!empty($m[6][0]))// '(' or ')' found
701 701
             {
702
-                if (empty($stack) && $m[6][0]=='(')
702
+                if (empty($stack) && $m[6][0] == '(')
703 703
                 {
704 704
                     array_push($stack, $m[6][0]);
705 705
                 }
706
-                elseif($m[6][0]==')' && end($stack)=='(')
706
+                elseif ($m[6][0] == ')' && end($stack) == '(')
707 707
                 {
708 708
                     array_pop($stack);
709 709
                 }
710 710
             }
711 711
             elseif (!empty($m[1][0]))// ' or " found
712 712
             {
713
-                if (end($stack)==$m[1][0])
713
+                if (end($stack) == $m[1][0])
714 714
                 {
715 715
                     array_pop($stack);
716 716
                 }
@@ -735,22 +735,22 @@  discard block
 block discarded – undo
735 735
     * works the same as getDelimPos except returns position of the first occurence of the delimiter starting from
736 736
     * the end of the string
737 737
     */
738
-    function getDelimRpos($string, $offset=0, $delim=';', $skipInBrackets=false)
738
+    function getDelimRpos($string, $offset = 0, $delim = ';', $skipInBrackets = false)
739 739
     {
740 740
         $pos = $this->getDelimPos($string, $offset, $delim, $skipInBrackets);
741
-        if ($pos===false)
741
+        if ($pos === false)
742 742
         {
743 743
             return false;
744 744
         }
745 745
         do
746 746
         {
747
-            $newPos=$this->getDelimPos($string, $pos+1, $delim, $skipInBrackets);
747
+            $newPos = $this->getDelimPos($string, $pos + 1, $delim, $skipInBrackets);
748 748
             if ($newPos !== false)
749 749
             {
750 750
                 $pos = $newPos;
751 751
             }
752 752
         }
753
-        while($newPos!==false);
753
+        while ($newPos !== false);
754 754
         return $pos;
755 755
     }
756 756
 
Please login to merge, or discard this patch.