From: Bartosz Dziewoński Date: Thu, 27 Feb 2014 13:08:48 +0000 (+0100) Subject: CSSMin: Clean up the logic in getLocalFileReferences() X-Git-Tag: 1.31.0-rc.0~16692^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/wiki/supprimer.php?a=commitdiff_plain;h=ae839a0facaaf7d0b8e8af64a8cd14b09bfb8b82;p=lhc%2Fweb%2Fwiklou.git CSSMin: Clean up the logic in getLocalFileReferences() The function used to check if the $path parameter is null on every inner loop iteration, only to effectively return an empty array if it was. Rephrased the code to say exactly that. (Not sure what the behavior is good for, though…) Change-Id: I716bfde581d3ed4c02f0d9f544beb9d0a1906261 --- diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 3b7968457d..e490e4f41d 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -61,21 +61,27 @@ class CSSMin { /** * Gets a list of local file paths which are referenced in a CSS style sheet * + * This function will always return an empty array if the second parameter is not given or null + * for backwards-compatibility. + * * @param string $source CSS data to remap * @param string $path File path where the source was read from (optional) * @return array List of local file references */ public static function getLocalFileReferences( $source, $path = null ) { + if ( $path === null ) { + return array(); + } + + $path = rtrim( $path, '/' ) . '/'; $files = array(); + $rFlags = PREG_OFFSET_CAPTURE | PREG_SET_ORDER; if ( preg_match_all( '/' . self::URL_REGEX . '/', $source, $matches, $rFlags ) ) { foreach ( $matches as $match ) { - $file = ( isset( $path ) - ? rtrim( $path, '/' ) . '/' - : '' ) . "{$match['file'][0]}"; - + $file = $path . $match['file'][0]; // Only proceed if we can access the file - if ( !is_null( $path ) && file_exists( $file ) ) { + if ( file_exists( $file ) ) { $files[] = $file; } }