CSSMin: Clean up the logic in getLocalFileReferences()
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 27 Feb 2014 13:08:48 +0000 (14:08 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 28 Feb 2014 20:26:56 +0000 (21:26 +0100)
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

includes/libs/CSSMin.php

index 3b79684..e490e4f 100644 (file)
@@ -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;
                                }
                        }