Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
CRAP
75.00% covered (warning)
75.00%
3 / 4
MediaWikiVersionFetcher
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2.06
75.00% covered (warning)
75.00%
3 / 4
 fetchVersion
0.00% covered (danger)
0.00%
0 / 1
2.06
75.00% covered (warning)
75.00%
3 / 4
<?php
/**
 * Provides access to MediaWiki's version without requiring MediaWiki (or anything else)
 * being loaded first.
 *
 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 */
class MediaWikiVersionFetcher {
    /**
     * Get the MediaWiki version, extracted from the PHP source file where it is defined.
     *
     * @return string
     * @throws RuntimeException
     */
    public function fetchVersion() {
        $code = file_get_contents( __DIR__ . '/Defines.php' );
        if ( !preg_match( "/define\( 'MW_VERSION', '([^']+)'/", $code, $matches ) ) {
            throw new RuntimeException( 'Could not extract the MediaWiki version from Defines.php' );
        }
        return $matches[1];
    }
}