[MediaWiki-commits] [Gerrit] integration/docroot[master]: Move CoveragePage into shared/ for reuse
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/401670 ) Change subject: Move CoveragePage into shared/ for reuse .. Move CoveragePage into shared/ for reuse Change-Id: I3af0bbb51d1e8771fdf7748cde106953bbc1af85 --- M org/wikimedia/doc/cover/index.php A shared/CoveragePage.php R shared/cover.css 3 files changed, 158 insertions(+), 130 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/org/wikimedia/doc/cover/index.php b/org/wikimedia/doc/cover/index.php index 7e52ca3..7c59499 100644 --- a/org/wikimedia/doc/cover/index.php +++ b/org/wikimedia/doc/cover/index.php @@ -1,6 +1,6 @@ + * Copyright (C) 2017-2018 Kunal Mehta* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,138 +18,11 @@ * */ -require_once __DIR__ . '/../../../../shared/DocPage.php'; - -/** - * Show a dashboard of code coverage results on the main index page - */ -class CoveragePage extends DocPage { - - /** -* Defaults from phpunit/src/Util/Configuration.php -*/ - const COVERAGE_LOW = 50; - const COVERAGE_HIGH = 90; - - /** -* Lists directory similar to dir index, but -* includes a progress bar -*/ - public function handleCoverageIndex() { - // Get list of directories with clover.xml - $results = glob( __DIR__ . '/*/clover.xml' ); - $this->embedCSS( file_get_contents( __DIR__ . '/cover.css' ) ); - $this->addHtmlContent( '' ); - $html = ''; - foreach ( $results as $clover ) { - $info = $this->parseClover( $clover ); - $dirName = htmlspecialchars( basename( dirname( $clover ) ) ); - $percent = (string)round( $info['percent'] ); - $color = $this->getLevelColor( $info['percent'] ); - $minWidth = $percent >= 10 ? '3em' : '2em'; - $html .= << - - $dirName - - - $percent% - - - - -HTML; - } - $this->addHtmlContent( "$html" ); - } - - /** -* Get data out of the clover.xml file -* -* @param string $fname -* @return array|bool false on failure -*/ - protected function parseClover( $fname ) { - $contents = file_get_contents( $fname ); - if ( !$contents ) { - // Race condition? - return false; - } - - $xml = new SimpleXMLElement( $contents ); - $metrics = $xml->project->metrics; - $total = (int)$metrics['methods'] + - (int)$metrics['conditionals'] + - (int)$metrics['statements'] + - (int)$metrics['elements']; - if ( $total === 0 ) { - // Avoid division by 0 warnings, and treat 0/0 as 100% - // to match the PHPUnit behavior - $percent = 1; - } else { - $percent = ( - (int)$metrics['coveredmethods'] + - (int)$metrics['coveredconditionals'] + - (int)$metrics['coveredstatements'] + - (int)$metrics['coveredelements'] - ) / $total; - } - // TODO: Figure out how to get a more friendly name - return [ - 'percent' => $percent * 100, - ]; - } - - /** -* Get the CSS class for the progress bar, -* based on code in PHP_CodeCoverage -* -* @param float $percent -* @return string -*/ - protected function getLevelColor( $percent ) { - if ( $percent <= self::COVERAGE_LOW ) { - return 'danger'; - } elseif ( $percent >= self::COVERAGE_HIGH ) { - return 'success'; - } else { - // In the middle - return 'warning'; - } - } - - /** -* Exclude directories that already have been listed -* -* @return string[] -*/ - protected function getDirIndexDirectories() { - $dirs = parent::getDirIndexDirectories(); - $noClover = []; - foreach ( $dirs as $dir ) { - if ( !file_exists( "$dir/clover.xml" ) ) { -
[MediaWiki-commits] [Gerrit] integration/docroot[master]: Move CoveragePage into shared/ for reuse
Legoktm has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401670 ) Change subject: Move CoveragePage into shared/ for reuse .. Move CoveragePage into shared/ for reuse Change-Id: I3af0bbb51d1e8771fdf7748cde106953bbc1af85 --- M org/wikimedia/doc/cover/index.php A shared/CoveragePage.php R shared/cover.css 3 files changed, 158 insertions(+), 130 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/integration/docroot refs/changes/70/401670/1 diff --git a/org/wikimedia/doc/cover/index.php b/org/wikimedia/doc/cover/index.php index 7e52ca3..7c59499 100644 --- a/org/wikimedia/doc/cover/index.php +++ b/org/wikimedia/doc/cover/index.php @@ -1,6 +1,6 @@ + * Copyright (C) 2017-2018 Kunal Mehta* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,138 +18,11 @@ * */ -require_once __DIR__ . '/../../../../shared/DocPage.php'; - -/** - * Show a dashboard of code coverage results on the main index page - */ -class CoveragePage extends DocPage { - - /** -* Defaults from phpunit/src/Util/Configuration.php -*/ - const COVERAGE_LOW = 50; - const COVERAGE_HIGH = 90; - - /** -* Lists directory similar to dir index, but -* includes a progress bar -*/ - public function handleCoverageIndex() { - // Get list of directories with clover.xml - $results = glob( __DIR__ . '/*/clover.xml' ); - $this->embedCSS( file_get_contents( __DIR__ . '/cover.css' ) ); - $this->addHtmlContent( '' ); - $html = ''; - foreach ( $results as $clover ) { - $info = $this->parseClover( $clover ); - $dirName = htmlspecialchars( basename( dirname( $clover ) ) ); - $percent = (string)round( $info['percent'] ); - $color = $this->getLevelColor( $info['percent'] ); - $minWidth = $percent >= 10 ? '3em' : '2em'; - $html .= << - - $dirName - - - $percent% - - - - -HTML; - } - $this->addHtmlContent( "$html" ); - } - - /** -* Get data out of the clover.xml file -* -* @param string $fname -* @return array|bool false on failure -*/ - protected function parseClover( $fname ) { - $contents = file_get_contents( $fname ); - if ( !$contents ) { - // Race condition? - return false; - } - - $xml = new SimpleXMLElement( $contents ); - $metrics = $xml->project->metrics; - $total = (int)$metrics['methods'] + - (int)$metrics['conditionals'] + - (int)$metrics['statements'] + - (int)$metrics['elements']; - if ( $total === 0 ) { - // Avoid division by 0 warnings, and treat 0/0 as 100% - // to match the PHPUnit behavior - $percent = 1; - } else { - $percent = ( - (int)$metrics['coveredmethods'] + - (int)$metrics['coveredconditionals'] + - (int)$metrics['coveredstatements'] + - (int)$metrics['coveredelements'] - ) / $total; - } - // TODO: Figure out how to get a more friendly name - return [ - 'percent' => $percent * 100, - ]; - } - - /** -* Get the CSS class for the progress bar, -* based on code in PHP_CodeCoverage -* -* @param float $percent -* @return string -*/ - protected function getLevelColor( $percent ) { - if ( $percent <= self::COVERAGE_LOW ) { - return 'danger'; - } elseif ( $percent >= self::COVERAGE_HIGH ) { - return 'success'; - } else { - // In the middle - return 'warning'; - } - } - - /** -* Exclude directories that already have been listed -* -* @return string[] -*/ - protected function getDirIndexDirectories() { - $dirs = parent::getDirIndexDirectories(); - $noClover = []; - foreach ( $dirs as $dir ) { - if ( !file_exists( "$dir/clover.xml" ) ) { -