Seb35 has uploaded a new change for review. https://gerrit.wikimedia.org/r/299382
Change subject: Decrease cyclomatic complexity of readFile from 648 to 90 ; better management of empty files ...................................................................... Decrease cyclomatic complexity of readFile from 648 to 90 ; better management of empty files --- M src/MediaWikiFarm.php 1 file changed, 15 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm refs/changes/82/299382/1 diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php index 9ee7e19..b661fa9 100644 --- a/src/MediaWikiFarm.php +++ b/src/MediaWikiFarm.php @@ -424,17 +424,13 @@ # Note the regex must be greedy to correctly select double extensions $format = preg_replace( '/^.*\.([a-z]+)$/', '$1', $filename ); - if( $format == 'php' ) { + # Format PHP + if( $format == 'php' ) $array = @include $filename; - - if( !is_array( $array ) ) - return false; - - return $array; - } - if( $format == 'yml' || $format == 'yaml' ) { + # Format YAML + elseif( $format == 'yml' || $format == 'yaml' ) { if( !class_exists( 'Symfony\Component\Yaml\Yaml' ) ) return false; @@ -442,10 +438,6 @@ try { $array = Symfony\Component\Yaml\Yaml::parse( @file_get_contents( $filename ) ); - if( !is_array( $array ) ) - return false; - - return $array; } catch( Symfony\Component\Yaml\Exception\ParseException $e ) { @@ -453,16 +445,13 @@ } } - if( $format == 'json' ) { + # Format JSON + elseif( $format == 'json' ) $array = json_decode( @file_get_contents( $filename ), true ); - if( !is_array( $array ) ) - return false; - - return $array; - } - if( $format == 'dblist' ) { + # Format dblist (simple list of strings separated by newlines) + elseif( $format == 'dblist' ) { $content = @file_get_contents( $filename ); @@ -471,6 +460,13 @@ return explode( "\n", $content ); } + else return false; + + if( is_null( $array ) ) + return array(); + + elseif( is_array( $array ) ) + return $array; return false; } -- To view, visit https://gerrit.wikimedia.org/r/299382 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1ca2a2fa6a5d5741d19a8d65b48545e58d595f8f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MediaWikiFarm Gerrit-Branch: master Gerrit-Owner: Seb35 <seb35wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits