Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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/includes/mock-fs.php

    r41289 r42343  
    1111
    1212    public $verbose = false; // Enable to debug WP_Filesystem_Base::find_folder() / etc.
    13     public $errors = array();
    14     public $method = 'MockFS';
     13    public $errors  = array();
     14    public $method  = 'MockFS';
    1515
    1616    function __construct() {}
     
    2222    // Copy of core's function, but accepts a path.
    2323    function abspath( $path = false ) {
    24         if ( ! $path )
     24        if ( ! $path ) {
    2525            $path = ABSPATH;
     26        }
    2627        $folder = $this->find_folder( $path );
    2728
    2829        // Perhaps the FTP folder is rooted at the WordPress installation, Check for wp-includes folder in root, Could have some false positives, but rare.
    29         if ( ! $folder && $this->is_dir('/wp-includes') )
     30        if ( ! $folder && $this->is_dir( '/wp-includes' ) ) {
    3031            $folder = '/';
     32        }
    3133        return $folder;
    3234    }
     
    3941     */
    4042    function init( $paths = '', $home_dir = '/' ) {
    41         $this->fs = new MockFS_Directory_Node( '/' );
     43        $this->fs     = new MockFS_Directory_Node( '/' );
    4244        $this->fs_map = array(
    4345            '/' => $this->fs,
    4446        );
    45         $this->cache = array(); // Used by find_folder() and friends
    46         $this->cwd = isset( $this->fs_map[ $home_dir ] ) ? $this->fs_map[ $home_dir ] : '/';
     47        $this->cache  = array(); // Used by find_folder() and friends
     48        $this->cwd    = isset( $this->fs_map[ $home_dir ] ) ? $this->fs_map[ $home_dir ] : '/';
    4749        $this->setfs( $paths );
    4850    }
     
    5254     */
    5355    function setfs( $paths ) {
    54         if ( ! is_array($paths) )
     56        if ( ! is_array( $paths ) ) {
    5557            $paths = explode( "\n", $paths );
     58        }
    5659
    5760        $paths = array_filter( array_map( 'trim', $paths ) );
     
    5962        foreach ( $paths as $path ) {
    6063            // Allow for comments
    61             if ( '#' == $path[0] )
    62                 continue;
     64            if ( '#' == $path[0] ) {
     65                continue;
     66            }
    6367
    6468            // Directories
    65             if ( '/' == $path[ strlen($path) -1 ] )
     69            if ( '/' == $path[ strlen( $path ) - 1 ] ) {
    6670                $this->mkdir( $path );
    67             else // Files (with dummy content for now)
     71            } else { // Files (with dummy content for now)
    6872                $this->put_contents( $path, 'This is a test file' );
     73            }
    6974        }
    7075
     
    96101            $this->mkdir( $dirname );
    97102            $parent_node = $this->locate_parent_node( $path );
    98             if ( ! $parent_node )
     103            if ( ! $parent_node ) {
    99104                return false;
     105            }
    100106        }
    101107
     
    103109
    104110        $parent_node->children[ $node->name ] = $node;
    105         $this->fs_map[ $path ] = $node;
     111        $this->fs_map[ $path ]                = $node;
    106112
    107113        return true;
     
    109115
    110116    function put_contents( $path, $contents = '', $mode = null ) {
    111         if ( ! $this->is_dir( dirname( $path ) ) )
     117        if ( ! $this->is_dir( dirname( $path ) ) ) {
    112118            $this->mkdir( dirname( $path ) );
    113 
    114         $parent = $this->locate_parent_node( $path );
     119        }
     120
     121        $parent   = $this->locate_parent_node( $path );
    115122        $new_file = new MockFS_File_Node( $path, $contents );
    116123
    117124        $parent->children[ $new_file->name ] = $new_file;
    118         $this->fs_map[ $path ] = $new_file;
     125        $this->fs_map[ $path ]               = $new_file;
    119126    }
    120127
    121128    function get_contents( $file ) {
    122         if ( ! $this->is_file( $file ) )
     129        if ( ! $this->is_file( $file ) ) {
    123130            return false;
     131        }
    124132        return $this->fs_map[ $file ]->contents;
    125133    }
     
    130138
    131139    function chdir( $path ) {
    132         if ( ! isset( $this->fs_map[ $path ] ) )
     140        if ( ! isset( $this->fs_map[ $path ] ) ) {
    133141            return false;
     142        }
    134143
    135144        $this->cwd = $this->fs_map[ $path ];
     
    153162    function dirlist( $path = '.', $include_hidden = true, $recursive = false ) {
    154163
    155         if ( empty( $path ) || '.' == $path )
     164        if ( empty( $path ) || '.' == $path ) {
    156165            $path = $this->cwd();
    157 
    158         if ( ! $this->exists( $path ) )
     166        }
     167
     168        if ( ! $this->exists( $path ) ) {
    159169            return false;
     170        }
    160171
    161172        $limit_file = false;
    162173        if ( $this->is_file( $path ) ) {
    163174            $limit_file = $this->locate_node( $path )->name;
    164             $path = dirname( $path ) . '/';
     175            $path       = dirname( $path ) . '/';
    165176        }
    166177
    167178        $ret = array();
    168179        foreach ( $this->fs_map[ $path ]->children as $entry ) {
    169             if ( '.' == $entry->name || '..' == $entry->name )
    170                 continue;
    171 
    172             if ( ! $include_hidden && '.' == $entry->name )
    173                 continue;
    174 
    175             if ( $limit_file && $entry->name != $limit_file )
    176                 continue;
    177 
    178             $struc = array();
     180            if ( '.' == $entry->name || '..' == $entry->name ) {
     181                continue;
     182            }
     183
     184            if ( ! $include_hidden && '.' == $entry->name ) {
     185                continue;
     186            }
     187
     188            if ( $limit_file && $entry->name != $limit_file ) {
     189                continue;
     190            }
     191
     192            $struc         = array();
    179193            $struc['name'] = $entry->name;
    180194            $struc['type'] = $entry->type;
    181195
    182196            if ( 'd' == $struc['type'] ) {
    183                 if ( $recursive )
     197                if ( $recursive ) {
    184198                    $struc['files'] = $this->dirlist( trailingslashit( $path ) . trailingslashit( $struc['name'] ), $include_hidden, $recursive );
    185                 else
     199                } else {
    186200                    $struc['files'] = array();
     201                }
    187202            }
    188203
     
    214229
    215230class MockFS_Directory_Node extends MockFS_Node {
    216     public $type = 'd';
     231    public $type     = 'd';
    217232    public $children = array(); // The child nodes of this directory
    218233}
    219234
    220235class MockFS_File_Node extends MockFS_Node {
    221     public $type = 'f';
     236    public $type     = 'f';
    222237    public $contents = ''; // The contents of the file
    223238
Note: See TracChangeset for help on using the changeset viewer.