This repository has been archived by the owner on Aug 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,468 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* JBZoo TeamCity | ||
* | ||
* This file is part of the JBZoo CCK package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package TeamCity | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @link https://github.com/JBZoo/TeamCity". | ||
*/ | ||
|
||
namespace JBZoo\TeamCity; | ||
|
||
use JBZoo\Console\Command as ConsoleCommand; | ||
use JBZoo\Utils\Cli; | ||
|
||
/** | ||
* Class Clover | ||
* @package JBZoo\TeamCity | ||
*/ | ||
abstract class Command extends ConsoleCommand | ||
{ | ||
protected $_prefix = ''; | ||
protected $_exclude = []; | ||
protected $_colmap = []; | ||
|
||
/** | ||
* @param array $fields | ||
* @param bool $translate | ||
* @throws Exception | ||
*/ | ||
protected function _printFields(array $fields, $translate = true) | ||
{ | ||
foreach ($fields as $key => $value) { | ||
|
||
if (in_array($key, $this->_exclude, true)) { | ||
continue; | ||
} | ||
|
||
if (!$translate) { | ||
$this->_tcEcho($key, $value); | ||
|
||
} elseif (isset($this->_colmap[$key]) && $this->_colmap[$key]) { | ||
$this->_tcEcho($this->_colmap[$key], $value); | ||
|
||
} else { | ||
throw new Exception("{$key}=>{$value} not found in column map"); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param $key | ||
* @param $value | ||
*/ | ||
protected function _tcEcho($key, $value) | ||
{ | ||
$key = str_replace("'", "\\'", $key); | ||
$key = $this->_prefix ? $this->_prefix . ': ' . $key : $key; | ||
|
||
if (strpos($value, '.') || is_float($value)) { | ||
$value = round($value, 6); | ||
} else { | ||
$value = str_replace("'", "\\'", $value); | ||
} | ||
|
||
Cli::out("##teamcity[buildStatisticValue key='{$key}' value='{$value}']"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
/** | ||
* JBZoo TeamCity | ||
* | ||
* This file is part of the JBZoo CCK package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package TeamCity | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @link https://github.com/JBZoo/TeamCity". | ||
*/ | ||
|
||
namespace JBZoo\Console\Command; | ||
|
||
use JBZoo\TeamCity\Command as TeamCityCommand; | ||
use JBZoo\Console\Exception; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class Clover | ||
* @package JBZoo\Console | ||
*/ | ||
class Clover extends TeamCityCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() // @codingStandardsIgnoreLine | ||
{ | ||
$this | ||
->setName('teamcity:clover') | ||
->setDescription('Parse phpunit clover.xml file and send it to TeamCity report!') | ||
->addArgument('xml', InputOption::VALUE_REQUIRED, 'Path to phploc xml file') | ||
->addOption('crap-threshold', null, InputOption::VALUE_OPTIONAL, 'Path to phploc xml file', 30); | ||
} | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
* @throws Exception | ||
* | ||
* @SuppressWarnings(PHPMD.NPathComplexity) | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) // @codingStandardsIgnoreLine | ||
{ | ||
$this->_executePrepare($input, $output); | ||
|
||
$crapThreshold = $this->_getOpt('crap-threshold'); | ||
$xmlPath = $input->getArgument('xml'); | ||
if (!file_exists($xmlPath)) { | ||
throw new Exception('XML file not found: ' . $xmlPath); | ||
} | ||
|
||
$cloverXml = new \SimpleXMLElement($xmlPath, null, true); | ||
$info = $cloverXml->project->metrics; | ||
|
||
$coveredClasses = 0; | ||
foreach ($cloverXml->xpath('//class') as $class) { | ||
if ((int)$class->metrics['coveredmethods'] === (int)$class->metrics['methods']) { | ||
$coveredClasses++; | ||
} | ||
} | ||
|
||
$data = array( | ||
'CodeCoverageAbsLTotal' => (int)$info['elements'], | ||
'CodeCoverageAbsLCovered' => (int)$info['coveredelements'], | ||
'CodeCoverageAbsBTotal' => (int)$info['statements'], | ||
'CodeCoverageAbsBCovered' => (int)$info['coveredstatements'], | ||
'CodeCoverageAbsMTotal' => (int)$info['methods'], | ||
'CodeCoverageAbsMCovered' => (int)$info['coveredmethods'], | ||
'CodeCoverageAbsCTotal' => (int)$info['classes'], | ||
'CodeCoverageAbsCCovered' => $coveredClasses, | ||
'CodeCoverageL' => $info['elements'] ? $info['coveredelements'] / $info['elements'] * 100 : 0, | ||
'CodeCoverageM' => $info['methods'] ? $info['coveredmethods'] / $info['methods'] * 100 : 0, | ||
'CodeCoverageC' => $info['classes'] ? $coveredClasses / $info['classes'] * 100 : 0, | ||
'Files' => (int)$info['files'], | ||
'LinesOfCode' => (int)$info['loc'], | ||
'NonCommentLinesOfCode' => (int)$info['ncloc'], | ||
); | ||
|
||
$data['CodeCoverageB'] = $info['statements'] ? $info['coveredstatements'] / $info['statements'] * 100 : 0; | ||
|
||
if ($crapThreshold) { | ||
$crapValues = array(); | ||
$crapAmount = 0; | ||
|
||
foreach ($cloverXml->xpath('//@crap') as $crap) { | ||
$crap = (float)$crap; | ||
$crapValues[] = $crap; | ||
if ($crap >= $crapThreshold) { | ||
$crapAmount++; | ||
} | ||
} | ||
|
||
$crapValuesCount = count($crapValues); | ||
$crapTotal = array_sum($crapValues); | ||
|
||
$data['CRAPAmount'] = $crapAmount; | ||
$data['CRAPPercent'] = $crapValuesCount ? $crapAmount / $crapValuesCount * 100 : 0; | ||
$data['CRAPTotal'] = $crapTotal; | ||
$data['CRAPAverage'] = $crapValuesCount ? $crapTotal / $crapValuesCount : 0; | ||
$data['CRAPMaximum'] = max($crapValues); | ||
} | ||
|
||
$this->_printFields($data, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* JBZoo TeamCity | ||
* | ||
* This file is part of the JBZoo CCK package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package TeamCity | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @link https://github.com/JBZoo/TeamCity". | ||
*/ | ||
|
||
namespace JBZoo\Console\Command; | ||
|
||
use JBZoo\TeamCity\Command as TeamCityCommand; | ||
use JBZoo\Console\Exception; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class Pdepend | ||
* @package JBZoo\Console | ||
*/ | ||
class Pdepend extends TeamCityCommand | ||
{ | ||
protected $_prefix = 'PHP Depend'; | ||
|
||
protected $_exclude = [ | ||
'generated', | ||
'pdepend', | ||
]; | ||
|
||
protected $_colmap = [ | ||
'ahh' => 'Average Hierarchy Height', | ||
'andc' => 'Average Number of Derived Classes', | ||
'ca' => 'Afferent Coupling', | ||
'calls' => 'Number of Method or Function Calls', | ||
'cbo' => 'Coupling Between Objects', | ||
'ccn' => 'Cyclomatic Complexity Number', | ||
'ccn2' => 'Extended Cyclomatic Complexity Number', | ||
'ce' => 'Efferent Coupling', | ||
'cis' => 'Class Interface Size', | ||
'cloc' => 'Comment Lines fo Code', | ||
'clsa' => 'Number of Abstract Classes', | ||
'clsc' => 'Number of Concrete Classes', | ||
'cr' => 'Code Rank', | ||
'csz' => 'Class Size', | ||
'dit' => 'Depth of Inheritance Tree', | ||
'eloc' => 'Executable Lines of Code', | ||
'fanout' => 'Number of Fanouts', | ||
'leafs' => 'Number of Leaf Classes', | ||
'lloc' => 'Logical Lines Of Code', | ||
'loc' => 'Lines Of Code', | ||
'maxDIT' => 'Max Depth of Inheritance Tree', | ||
'noam' => 'Number Of Added Methods', | ||
'nocc' => 'Number Of Child Classes', | ||
'noom' => 'Number Of Overwritten Methods', | ||
'ncloc' => 'Non Comment Lines Of Code', | ||
'noc' => 'Number Of Classes', | ||
'nof' => 'Number Of Functions', | ||
'noi' => 'Number Of Interfaces', | ||
'nom' => 'Number Of Methods', | ||
'npm' => 'Number of Public Methods', | ||
'npath' => 'NPath Complexity', | ||
'nop' => 'Number of Packages', | ||
'rcr' => 'Reverse Code Rank', | ||
'roots' => 'Number of Root Classes', | ||
'vars' => 'Properties', | ||
'varsi' => 'Inherited Properties', | ||
'varsnp' => 'Non Private Properties', | ||
'wmc' => 'Weighted Method Count', | ||
'wmci' => 'Inherited Weighted Method Count', | ||
'wmcnp' => 'Non Private Weighted Method Count', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() // @codingStandardsIgnoreLine | ||
{ | ||
$this | ||
->setName('teamcity:pdepend') | ||
->setDescription('Parse pdepend summary.xml and send it to TeamCity report!') | ||
->addArgument('xml', InputOption::VALUE_REQUIRED, 'Path to phploc xml file'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @throws Exception | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) // @codingStandardsIgnoreLine | ||
{ | ||
$this->_executePrepare($input, $output); | ||
|
||
$xmlPath = $input->getArgument('xml'); | ||
|
||
if (!file_exists($xmlPath)) { | ||
throw new Exception('XML file not found: ' . $xmlPath); | ||
} | ||
|
||
$cloverXml = new \SimpleXMLElement($xmlPath, null, true); | ||
$fields = current($cloverXml->attributes()); | ||
|
||
$this->_printFields($fields); | ||
} | ||
} |
Oops, something went wrong.