Siebrand has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/77686


Change subject: Fix CodeSniffer errors and warnings
......................................................................

Fix CodeSniffer errors and warnings

Also formatted code to MediaWiki formatting conventions.

Change-Id: Id0b6014b76ad14fe0309058edef271258c870c29
---
M includes/profiler/Profiler.php
M includes/profiler/ProfilerSimple.php
M includes/profiler/ProfilerSimpleText.php
M includes/profiler/ProfilerSimpleTrace.php
M includes/profiler/ProfilerSimpleUDP.php
M includes/profiler/ProfilerStub.php
6 files changed, 115 insertions(+), 47 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/86/77686/1

diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php
index 0ef12ec..411651c 100644
--- a/includes/profiler/Profiler.php
+++ b/includes/profiler/Profiler.php
@@ -34,6 +34,7 @@
        if ( Profiler::$__instance === null ) { // use this directly to reduce 
overhead
                Profiler::instance();
        }
+
        if ( Profiler::$__instance && !( Profiler::$__instance instanceof 
ProfilerStub ) ) {
                Profiler::instance()->profileIn( $functionname );
        }
@@ -140,6 +141,7 @@
                                self::$__instance = new ProfilerStub( 
$wgProfiler );
                        }
                }
+
                return self::$__instance;
        }
 
@@ -203,11 +205,18 @@
         */
        public function profileIn( $functionname ) {
                global $wgDebugFunctionEntry;
+
                if ( $wgDebugFunctionEntry ) {
-                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) ) . 'Entering ' . $functionname . "\n" );
+                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) ) .
+                               'Entering ' . $functionname . "\n" );
                }
 
-               $this->mWorkStack[] = array( $functionname, count( 
$this->mWorkStack ), $this->getTime(), memory_get_usage() );
+               $this->mWorkStack[] = array(
+                       $functionname,
+                       count( $this->mWorkStack ),
+                       $this->getTime(),
+                       memory_get_usage()
+               );
        }
 
        /**
@@ -217,11 +226,13 @@
         */
        public function profileOut( $functionname ) {
                global $wgDebugFunctionEntry;
+
                $memory = memory_get_usage();
                $time = $this->getTime();
 
                if ( $wgDebugFunctionEntry ) {
-                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) - 1 ) . 'Exiting ' . $functionname . "\n" );
+                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) - 1 ) .
+                               'Exiting ' . $functionname . "\n" );
                }
 
                $bit = array_pop( $this->mWorkStack );
@@ -281,10 +292,10 @@
        protected function updateTrxProfiling( $method, $realtime ) {
                if ( !$this->mDBTrxHoldingLocks ) {
                        return; // short-circuit
-               // @TODO: hardcoded check is a tad janky (what about FOR 
UPDATE?)
+                       // @TODO: hardcoded check is a tad janky (what about 
FOR UPDATE?)
                } elseif ( !preg_match( '/^query-m: (?!SELECT)/', $method )
-                       && $realtime < $this->mDBLockThreshold )
-               {
+                       && $realtime < $this->mDBLockThreshold
+               ) {
                        return; // not a DB master query nor slow enough
                }
                $now = microtime( true );
@@ -324,7 +335,7 @@
                                        list( $method, $realtime ) = $info;
                                        $msg .= sprintf( "%d\t%.6f\t%s\n", $i, 
$realtime, $method );
                                }
-                               wfDebugLog( 'DBPerfomance', $msg );
+                               wfDebugLog( 'DBPerformance', $msg );
                        }
                        unset( $this->mDBTrxHoldingLocks[$name] );
                        unset( $this->mDBTrxMethodTimes[$name] );
@@ -365,7 +376,13 @@
         * @return string
         */
        function getCallTree() {
-               return implode( '', array_map( array( &$this, 'getCallTreeLine' 
), $this->remapCallTree( $this->mStack ) ) );
+               return implode(
+                       '',
+                       array_map(
+                               array( &$this, 'getCallTreeLine' ),
+                               $this->remapCallTree( $this->mStack )
+                       )
+               );
        }
 
        /**
@@ -383,7 +400,7 @@
                        /* Find all items under this entry */
                        $level = $stack[$max][1];
                        $working = array();
-                       for ( $i = $max -1; $i >= 0; $i-- ) {
+                       for ( $i = $max - 1; $i >= 0; $i-- ) {
                                if ( $stack[$i][1] > $level ) {
                                        $working[] = $stack[$i];
                                } else {
@@ -406,6 +423,7 @@
                                $final[] = $item;
                        }
                }
+
                return $final;
        }
 
@@ -417,6 +435,7 @@
                list( $fname, $level, $start, /* $x */, $end ) = $entry;
                $delta = $end - $start;
                $space = str_repeat( ' ', $level );
+
                # The ugly double sprintf is to work around a PHP bug,
                # which has been fixed in recent releases.
                return sprintf( "%10s %s %s\n", trim( sprintf( "%7.3f", $delta 
* 1000.0 ) ), $space, $fname );
@@ -449,6 +468,7 @@
                                # it gives the total CPU time
                                $time += $ru['ru_stime.tv_sec'] + 
$ru['ru_stime.tv_usec'] / 1e6;
                        }
+
                        return $time;
                } else {
                        return microtime( true );
@@ -484,6 +504,7 @@
                                # it gives the total CPU time
                                $time += $wgRUstart['ru_stime.tv_sec'] + 
$wgRUstart['ru_stime.tv_usec'] / 1e6;
                        }
+
                        return $time;
                } else {
                        if ( empty( $wgRequestTime ) ) {
@@ -526,9 +547,15 @@
                                $overheadInternal[] = $elapsed;
                        }
                }
-               $overheadTotal = $overheadTotal ? array_sum( $overheadTotal ) / 
count( $overheadInternal ) : 0;
-               $overheadMemory = $overheadMemory ? array_sum( $overheadMemory 
) / count( $overheadInternal ) : 0;
-               $overheadInternal = $overheadInternal ? array_sum( 
$overheadInternal ) / count( $overheadInternal ) : 0;
+               $overheadTotal = $overheadTotal ?
+                       array_sum( $overheadTotal ) / count( $overheadInternal 
) :
+                       0;
+               $overheadMemory = $overheadMemory ?
+                       array_sum( $overheadMemory ) / count( $overheadInternal 
) :
+                       0;
+               $overheadInternal = $overheadInternal ?
+                       array_sum( $overheadInternal ) / count( 
$overheadInternal ) :
+                       0;
 
                # Collate
                foreach ( $this->mStack as $index => $entry ) {
@@ -594,8 +621,8 @@
                        $prof .= sprintf( $format,
                                substr( $fname, 0, $nameWidth ),
                                $calls,
-                               (float) ( $elapsed * 1000 ),
-                               (float) ( $elapsed * 1000 ) / $calls,
+                               (float)( $elapsed * 1000 ),
+                               (float)( $elapsed * 1000 ) / $calls,
                                $percent,
                                $memory,
                                ( $this->mMin[$fname] * 1000.0 ),
@@ -632,9 +659,10 @@
        function calltreeCount( $stack, $start ) {
                $level = $stack[$start][1];
                $count = 0;
-               for ( $i = $start -1; $i >= 0 && $stack[$i][1] > $level; $i-- ) 
{
-                       $count ++;
+               for ( $i = $start - 1; $i >= 0 && $stack[$i][1] > $level; $i-- 
) {
+                       $count++;
                }
+
                return $count;
        }
 
@@ -665,7 +693,7 @@
 
                        foreach ( $this->mCollated as $name => $elapsed ) {
                                $eventCount = $this->mCalls[$name];
-                               $timeSum = (float) ( $elapsed * 1000 );
+                               $timeSum = (float)( $elapsed * 1000 );
                                $memorySum = (float)$this->mMemory[$name];
                                $name = substr( $name, 0, 255 );
 
@@ -688,7 +716,7 @@
                                $rc = $dbw->affectedRows();
                                if ( $rc == 0 ) {
                                        $dbw->insert( 'profiling', array( 
'pf_name' => $name, 'pf_count' => $eventCount,
-                                               'pf_time' => $timeSum, 
'pf_memory' => $memorySum, 'pf_server' => $pfhost ),
+                                                       'pf_time' => $timeSum, 
'pf_memory' => $memorySum, 'pf_server' => $pfhost ),
                                                __METHOD__, array( 'IGNORE' ) );
                                }
                                // When we upgrade to mysql 4.1, the 
insert+update
@@ -697,7 +725,8 @@
                                //     "pf_count=pf_count + VALUES(pf_count), ".
                                //     "pf_time=pf_time + VALUES(pf_time)";
                        }
-               } catch ( DBError $e ) {}
+               } catch ( DBError $e ) {
+               }
        }
 
        /**
@@ -706,6 +735,7 @@
         */
        function getCurrentSection() {
                $elt = end( $this->mWorkStack );
+
                return $elt[0];
        }
 
@@ -731,6 +761,7 @@
                                return $m[1];
                        }
                }
+
                return null;
        }
 }
diff --git a/includes/profiler/ProfilerSimple.php 
b/includes/profiler/ProfilerSimple.php
index 805c60f..86bb75f 100644
--- a/includes/profiler/ProfilerSimple.php
+++ b/includes/profiler/ProfilerSimple.php
@@ -27,10 +27,17 @@
  * @ingroup Profiler
  */
 class ProfilerSimple extends Profiler {
-       var $mMinimumTime = 0;
+       protected $mMinimumTime = 0;
 
-       var $zeroEntry = array( 'cpu' => 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 
'real_sq' => 0.0, 'count' => 0 );
-       var $errorEntry;
+       protected $zeroEntry = array(
+               'cpu' => 0.0,
+               'cpu_sq' => 0.0,
+               'real' => 0.0,
+               'real_sq' => 0.0,
+               'count' => 0
+       );
+
+       protected $errorEntry;
 
        public function isPersistent() {
                /* Implement in output subclasses */
@@ -59,17 +66,26 @@
 
        function profileIn( $functionname ) {
                global $wgDebugFunctionEntry;
+
                if ( $wgDebugFunctionEntry ) {
-                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) ) . 'Entering ' . $functionname . "\n" );
+                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) ) .
+                               'Entering ' . $functionname . "\n" );
                }
-               $this->mWorkStack[] = array( $functionname, count( 
$this->mWorkStack ), $this->getTime(), $this->getTime( 'cpu' ) );
+
+               $this->mWorkStack[] = array(
+                       $functionname,
+                       count( $this->mWorkStack ),
+                       $this->getTime(),
+                       $this->getTime( 'cpu' )
+               );
        }
 
        function profileOut( $functionname ) {
                global $wgDebugFunctionEntry;
 
                if ( $wgDebugFunctionEntry ) {
-                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) - 1 ) . 'Exiting ' . $functionname . "\n" );
+                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) - 1 ) .
+                               'Exiting ' . $functionname . "\n" );
                }
 
                list( $ofname, /* $ocount */, $ortime, $octime ) = array_pop( 
$this->mWorkStack );
@@ -82,8 +98,7 @@
                                $functionname = $ofname;
                                $this->debug( "$message\n" );
                                $this->mCollated[$message] = $this->errorEntry;
-                       }
-                       elseif ( $ofname != $functionname ) {
+                       } elseif ( $ofname != $functionname ) {
                                $message = "Profiling error: in({$ofname}), 
out($functionname)";
                                $this->debug( "$message\n" );
                                $this->mCollated[$message] = $this->errorEntry;
diff --git a/includes/profiler/ProfilerSimpleText.php 
b/includes/profiler/ProfilerSimpleText.php
index 1d57ea8..eea849a 100644
--- a/includes/profiler/ProfilerSimpleText.php
+++ b/includes/profiler/ProfilerSimpleText.php
@@ -45,9 +45,9 @@
        public function logData() {
                if ( $this->mTemplated ) {
                        $this->close();
-                       $totalReal = isset( $this->mCollated['-total'] )
-                               ? $this->mCollated['-total']['real']
-                               : 0; // profiling mismatch error?
+                       $totalReal = isset( $this->mCollated['-total'] ) ?
+                               $this->mCollated['-total']['real'] :
+                               0; // profiling mismatch error?
                        uasort( $this->mCollated, array( 'self', 'sort' ) );
                        array_walk( $this->mCollated, array( 'self', 'format' 
), $totalReal );
                        if ( PHP_SAPI === 'cli' ) {
diff --git a/includes/profiler/ProfilerSimpleTrace.php 
b/includes/profiler/ProfilerSimpleTrace.php
index 5588d1e..5a63b60 100644
--- a/includes/profiler/ProfilerSimpleTrace.php
+++ b/includes/profiler/ProfilerSimpleTrace.php
@@ -27,20 +27,21 @@
  * @ingroup Profiler
  */
 class ProfilerSimpleTrace extends ProfilerSimple {
-       var $trace = "Beginning trace: \n";
-       var $memory = 0;
+       protected $trace = "Beginning trace: \n";
+       protected $memory = 0;
 
        function profileIn( $functionname ) {
                parent::profileIn( $functionname );
                $this->trace .= "         " . sprintf( "%6.1f", 
$this->memoryDiff() ) .
-                               str_repeat( " ", count( $this->mWorkStack ) ) . 
" > " . $functionname . "\n";
+                       str_repeat( " ", count( $this->mWorkStack ) ) . " > " . 
$functionname . "\n";
        }
 
        function profileOut( $functionname ) {
                global $wgDebugFunctionEntry;
 
                if ( $wgDebugFunctionEntry ) {
-                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) - 1 ) . 'Exiting ' . $functionname . "\n" );
+                       $this->debug( str_repeat( ' ', count( $this->mWorkStack 
) - 1 ) .
+                               'Exiting ' . $functionname . "\n" );
                }
 
                list( $ofname, /* $ocount */, $ortime ) = array_pop( 
$this->mWorkStack );
@@ -52,13 +53,12 @@
                                $message = "Profile section ended by close(): 
{$ofname}";
                                $functionname = $ofname;
                                $this->trace .= $message . "\n";
-                       }
-                       elseif ( $ofname != $functionname ) {
+                       } elseif ( $ofname != $functionname ) {
                                $this->trace .= "Profiling error: 
in({$ofname}), out($functionname)";
                        }
                        $elapsedreal = $this->getTime() - $ortime;
                        $this->trace .= sprintf( "%03.6f %6.1f", $elapsedreal, 
$this->memoryDiff() ) .
-                                       str_repeat( " ", count( 
$this->mWorkStack ) + 1 ) . " < " . $functionname . "\n";
+                               str_repeat( " ", count( $this->mWorkStack ) + 1 
) . " < " . $functionname . "\n";
 
                        $this->updateTrxProfiling( $functionname, $elapsedreal 
);
                }
@@ -67,6 +67,7 @@
        function memoryDiff() {
                $diff = memory_get_usage() - $this->memory;
                $this->memory = memory_get_usage();
+
                return $diff / 1024;
        }
 
diff --git a/includes/profiler/ProfilerSimpleUDP.php 
b/includes/profiler/ProfilerSimpleUDP.php
index 9204763..a49269f 100644
--- a/includes/profiler/ProfilerSimpleUDP.php
+++ b/includes/profiler/ProfilerSimpleUDP.php
@@ -36,7 +36,9 @@
 
                $this->close();
 
-               if ( isset( $this->mCollated['-total'] ) && 
$this->mCollated['-total']['real'] < $this->mMinimumTime ) {
+               if ( isset( $this->mCollated['-total'] ) &&
+                       $this->mCollated['-total']['real'] < $this->mMinimumTime
+               ) {
                        # Less than minimum, ignore
                        return;
                }
@@ -54,7 +56,8 @@
                                || !isset( $pfdata['cpu'] )
                                || !isset( $pfdata['cpu_sq'] )
                                || !isset( $pfdata['real'] )
-                               || !isset( $pfdata['real_sq'] ) ) {
+                               || !isset( $pfdata['real_sq'] )
+                       ) {
                                continue;
                        }
                        $pfline = sprintf( "%s %s %d %f %f %f %f %s\n", 
$this->getProfileID(), "-", $pfdata['count'],
diff --git a/includes/profiler/ProfilerStub.php 
b/includes/profiler/ProfilerStub.php
index 3697f35..c752493 100644
--- a/includes/profiler/ProfilerStub.php
+++ b/includes/profiler/ProfilerStub.php
@@ -30,15 +30,33 @@
        public function isStub() {
                return true;
        }
+
        public function isPersistent() {
                return false;
        }
-       public function profileIn( $fn ) {}
-       public function profileOut( $fn ) {}
-       public function getOutput() {}
-       public function close() {}
-       public function logData() {}
-       public function getCurrentSection() { return ''; }
-       public function transactionWritingIn( $server, $db ) {}
-       public function transactionWritingOut( $server, $db ) {}
+
+       public function profileIn( $fn ) {
+       }
+
+       public function profileOut( $fn ) {
+       }
+
+       public function getOutput() {
+       }
+
+       public function close() {
+       }
+
+       public function logData() {
+       }
+
+       public function getCurrentSection() {
+               return '';
+       }
+
+       public function transactionWritingIn( $server, $db ) {
+       }
+
+       public function transactionWritingOut( $server, $db ) {
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/77686
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id0b6014b76ad14fe0309058edef271258c870c29
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to