Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/pomo/pluralForms.php

    r41730 r42343  
    1313         * @return string the expression with parentheses added
    1414         */
    15         protected static function parenthesize_plural_expression($expression) {
     15        protected static function parenthesize_plural_expression( $expression ) {
    1616                $expression .= ';';
    17                 $res = '';
    18                 $depth = 0;
    19                 for ($i = 0; $i < strlen($expression); ++$i) {
    20                         $char = $expression[$i];
    21                         switch ($char) {
     17                $res         = '';
     18                $depth       = 0;
     19                for ( $i = 0; $i < strlen( $expression ); ++$i ) {
     20                        $char = $expression[ $i ];
     21                        switch ( $char ) {
    2222                                case '?':
    2323                                        $res .= ' ? (';
     
    2828                                        break;
    2929                                case ';':
    30                                         $res .= str_repeat(')', $depth) . ';';
    31                                         $depth= 0;
     30                                        $res  .= str_repeat( ')', $depth ) . ';';
     31                                        $depth = 0;
    3232                                        break;
    3333                                default:
     
    3535                        }
    3636                }
    37                 return rtrim($res, ';');
     37                return rtrim( $res, ';' );
    3838        }
    3939
     
    5454                                return array();
    5555                        }
    56                         require_once $filename;                 
    57                 }
    58 
    59                 $locales = GP_Locales::locales();
     56                        require_once $filename;
     57                }
     58
     59                $locales            = GP_Locales::locales();
    6060                $plural_expressions = array();
    6161                foreach ( $locales as $slug => $locale ) {
     
    8282
    8383                $parenthesized = self::parenthesize_plural_expression( $expression );
    84                 $old_style = tests_make_plural_form_function( $nplurals, $parenthesized );
    85                 $pluralForms = new Plural_Forms( $expression );
     84                $old_style     = tests_make_plural_form_function( $nplurals, $parenthesized );
     85                $pluralForms   = new Plural_Forms( $expression );
    8686
    8787                $generated_old = array();
     
    103103                                array(
    104104                                        -1 => 1,
    105                                         0 => 1,
    106                                         1 => 0,
    107                                         2 => 1,
    108                                         5 => 1,
     105                                        0  => 1,
     106                                        1  => 0,
     107                                        2  => 1,
     108                                        5  => 1,
    109109                                        10 => 1,
    110110                                ),
     
    115115                                array(
    116116                                        -1 => 1,
    117                                         0 => 2,
    118                                         1 => 1,
    119                                         2 => 1,
     117                                        0  => 2,
     118                                        1  => 1,
     119                                        2  => 1,
    120120                                ),
    121121                        ),
     
    126126                                        -2 => 2,
    127127                                        -1 => 2,
    128                                         0 => 2,
    129                                         1 => 2,
    130                                         2 => 1,
    131                                         3 => 1,
     128                                        0  => 2,
     129                                        1  => 2,
     130                                        2  => 1,
     131                                        3  => 1,
    132132                                ),
    133133                        ),
     
    137137                                        -2 => 3,
    138138                                        -1 => 3,
    139                                         0 => 3,
    140                                         1 => 3,
    141                                         2 => 2,
    142                                         3 => 1,
    143                                         4 => 1,
     139                                        0  => 3,
     140                                        1  => 3,
     141                                        2  => 2,
     142                                        3  => 1,
     143                                        4  => 1,
    144144                                ),
    145145                        ),
     
    153153        public function test_simple( $expression, $expected ) {
    154154                $pluralForms = new Plural_Forms( $expression );
    155                 $actual = array();
     155                $actual      = array();
    156156                foreach ( array_keys( $expected ) as $num ) {
    157157                        $actual[ $num ] = $pluralForms->get( $num );
     
    214214                try {
    215215                        $pluralForms = new Plural_Forms( $expression );
    216                         if( $call_get ) {
     216                        if ( $call_get ) {
    217217                                $pluralForms->get( 1 );
    218218                        }
     
    230230        public function test_cache() {
    231231                $mock = $this->getMockBuilder( 'Plural_Forms' )
    232                         ->setMethods(array('execute'))
    233                         ->setConstructorArgs(array('n != 1'))
     232                        ->setMethods( array( 'execute' ) )
     233                        ->setConstructorArgs( array( 'n != 1' ) )
    234234                        ->getMock();
    235235
    236                 $mock->expects($this->once())
    237                         ->method('execute')
    238                         ->with($this->identicalTo(2))
    239                         ->will($this->returnValue(1));
    240 
    241                 $first = $mock->get( 2 );
     236                $mock->expects( $this->once() )
     237                        ->method( 'execute' )
     238                        ->with( $this->identicalTo( 2 ) )
     239                        ->will( $this->returnValue( 1 ) );
     240
     241                $first  = $mock->get( 2 );
    242242                $second = $mock->get( 2 );
    243243                $this->assertEquals( $first, $second );
Note: See TracChangeset for help on using the changeset viewer.