Making WordPress.org


Ignore:
Timestamp:
12/19/2017 04:22:37 PM (8 years ago)
Author:
obenland
Message:

PLugins: Clean up formatting with phpcbf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php

    r6281 r6287  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Zip;
     3
    34use WordPressdotorg\Plugin_Directory\Tools\SVN;
    45use Exception;
     
    1112class Builder {
    1213
    13     const TMP_DIR = '/tmp/plugin-zip-builder';
    14     const SVN_URL = 'https://plugins.svn.wordpress.org';
     14    const TMP_DIR     = '/tmp/plugin-zip-builder';
     15    const SVN_URL     = 'https://plugins.svn.wordpress.org';
    1516    const ZIP_SVN_URL = PLUGIN_ZIP_SVN_URL;
    1617
     
    6061            $this->tmp_dir,
    6162            array(
    62                 'depth' => 'empty',
     63                'depth'    => 'empty',
    6364                'username' => PLUGIN_ZIP_SVN_USER,
    6465                'password' => PLUGIN_ZIP_SVN_PASS,
     
    7071            // Ensure the plugins folder exists within svn
    7172            $plugin_folder = "{$this->tmp_dir}/{$this->slug}/";
     73
    7274            $res = SVN::up(
    7375                $plugin_folder,
    7476                array(
    75                     'depth' => 'empty'
     77                    'depth' => 'empty',
    7678                )
    7779            );
     
    105107            // This is done within the checksum generation function due to us not knowing the checksum filename until export_plugin().
    106108            // SVN::up( $this->checksum_file );
    107 
    108109            try {
    109110
    110                 $this->tmp_build_dir  = $this->zip_file . '-files';
     111                $this->tmp_build_dir = $this->zip_file . '-files';
    111112                mkdir( $this->tmp_build_dir, 0777, true );
    112113
     
    120121                $this->cleanup_plugin_tmp();
    121122
    122             } catch( Exception $e ) {
     123            } catch ( Exception $e ) {
    123124                // In event of error, skip this file this time.
    124125                $this->cleanup_plugin_tmp();
     
    203204
    204205        $skip_bad_files = array();
    205         $checksums = array();
    206         foreach ( array( 'md5' => 'md5sum', 'sha256' => 'sha256sum' ) as $checksum_type => $checksum_bin ) {
     206        $checksums      = array();
     207        foreach ( array(
     208            'md5'    => 'md5sum',
     209            'sha256' => 'sha256sum',
     210        ) as $checksum_type => $checksum_bin ) {
    207211            $checksum_output = array();
    208212            $this->exec( sprintf(
     
    212216
    213217            if ( $return_value ) {
    214             //  throw new Exception( __METHOD__ . ': Checksum generation failed, return code: ' . $return_value, 503 );
    215             // TODO For now, just silently keep going.
     218                // throw new Exception( __METHOD__ . ': Checksum generation failed, return code: ' . $return_value, 503 );
     219                // TODO For now, just silently keep going.
    216220                continue;
    217221            }
     
    219223            foreach ( $checksum_output as $line ) {
    220224                list( $checksum, $filename ) = preg_split( '!\s+!', $line, 2 );
     225
    221226                $filename = trim( preg_replace( '!^./!', '', $filename ) );
    222227                $checksum = trim( $checksum );
     
    228233
    229234                if ( ! isset( $checksums[ $filename ] ) ) {
    230                     $checksums[ $filename ] = array( 'md5' => array(), 'sha256' => array() );
     235                    $checksums[ $filename ] = array(
     236                        'md5'    => array(),
     237                        'sha256' => array(),
     238                    );
    231239                }
    232240
     
    249257            // Sometimes plugin versions exist in multiple tags/zips, include all the SVN urls & ZIP urls
    250258            foreach ( array( 'source', 'zip' ) as $maybe_different ) {
    251                 if ( !empty( $existing_json_checksum_file->{$maybe_different} ) &&
     259                if ( ! empty( $existing_json_checksum_file->{$maybe_different} ) &&
    252260                    $existing_json_checksum_file->{$maybe_different} != $json_checksum_file->{$maybe_different}
    253261                ) {
    254262                    $json_checksum_file->{$maybe_different} = array_unique( array_merge(
    255263                        (array) $existing_json_checksum_file->{$maybe_different},
    256                         (array) $json_checksum_file->{$maybe_different}
     264                        (array) $json_checksum_file->{$maybe_different}
    257265                    ) );
    258266
     
    282290                        $json_checksum_file->files[ $file ][ $checksum_type ] = array_unique( array_merge(
    283291                            (array) $checksums->{$checksum_type}, // May already be an array
    284                             (array) $json_checksum_file->files[ $file ][ $checksum_type ]
     292                            (array) $json_checksum_file->files[ $file ][ $checksum_type ]
    285293                        ) );
     294
    286295                        // Reduce single arrays back to a string when possible.
    287296                        if ( 1 == count( $json_checksum_file->files[ $file ][ $checksum_type ] ) ) {
     
    291300                }
    292301            }
    293 
    294302        }
    295303
     
    317325        $i = 0;
    318326        do {
    319             $rand = uniqid();
     327            $rand     = uniqid();
    320328            $filename = "{$dir}/{$prefix}-{$rand}{$i}{$suffix}";
    321         } while ( false === ($fp = @fopen( $filename, 'x' ) ) && $i++ < 50 );
     329        } while ( false === ( $fp = @fopen( $filename, 'x' ) ) && $i++ < 50 );
    322330
    323331        if ( $i >= 50 ) {
     
    358366        // Handle tags which we store as 0.blah but are in /tags/.blah
    359367        if ( ! $res['result'] && '0.' == substr( $this->version, 0, 2 ) ) {
    360             $_version = substr( $this->version, 1 );
     368            $_version                     = substr( $this->version, 1 );
    361369            $this->plugin_version_svn_url = self::SVN_URL . "/{$this->slug}/tags/{$_version}/";
    362             $res = SVN::export( $this->plugin_version_svn_url, $build_dir, $svn_params );
     370            $res                          = SVN::export( $this->plugin_version_svn_url, $build_dir, $svn_params );
    363371        }
    364372        if ( ! $res['result'] ) {
     
    449457            foreach ( $plugins_downloads_load_balancer /* TODO */ as $lb ) {
    450458                $url = 'http://' . $lb . PLUGIN_ZIP_X_ACCEL_REDIRECT_LOCATION . $zip;
    451                 wp_remote_request(
    452                     $url,
    453                     array(
    454                         'method' => 'PURGE',
    455                     )
    456                 );
     459
     460                wp_remote_request( $url, array(
     461                    'method' => 'PURGE',
     462                ) );
    457463            }
    458464        }
Note: See TracChangeset for help on using the changeset viewer.