Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Cryer committed Oct 15, 2015
1 parent dd1d3b3 commit f33f0a4
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 139 deletions.
133 changes: 0 additions & 133 deletions PHPCI/Migrations/20151014091859_errors_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;
use PHPCI\Model\BuildMeta;
use PHPCI\Model\BuildError;

class ErrorsTable extends AbstractMigration
{
/**
* @var \PHPCI\Store\BuildMetaStore
*/
protected $metaStore;

/**
* @var \PHPCI\Store\BuildErrorStore
*/
protected $errorStore;

public function change()
{
$table = $this->table('build_error');
Expand All @@ -32,126 +20,5 @@ public function change()
$table->addForeignKey('build_id', 'build', 'id', array('delete'=> 'CASCADE', 'update' => 'CASCADE'));
$table->save();

$this->updateBuildMeta();
}

protected function updateBuildMeta()
{
$start = 0;
$limit = 100;
$count = 100;

$this->metaStore = \b8\Store\Factory::getStore('BuildMeta');
$this->errorStore = \b8\Store\Factory::getStore('BuildError');

while ($count == 100) {
$data = $this->metaStore->getErrorsForUpgrade($start, $limit);
$start += 100;
$count = count($data);

/** @var \PHPCI\Model\BuildMeta $meta */
foreach ($data as $meta) {
try {
switch ($meta->getMetaKey()) {
case 'phpmd-data':
$this->processPhpMdMeta($meta);
break;
case 'phpcs-data':
$this->processPhpCsMeta($meta);
break;
case 'phpunit-data':
$this->processPhpUnitMeta($meta);
break;
case 'phpdoccheck-data':
$this->processPhpDocCheckMeta($meta);
break;
}
} catch (\Exception $ex) {}

$this->metaStore->delete($meta);
}
}
}

protected function processPhpMdMeta(BuildMeta $meta)
{
$data = json_decode($meta->getMetaValue(), true);

if (is_array($data) && count($data)) {
foreach ($data as $error) {
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_mess_detector');
$buildError->setCreatedDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line_start']);
$buildError->setLineEnd($error['line_end']);
$buildError->setSeverity(BuildError::SEVERITY_HIGH);
$buildError->setMessage($error['message']);

$this->errorStore->save($buildError);
}
}
}

protected function processPhpCsMeta(BuildMeta $meta)
{
$data = json_decode($meta->getMetaValue(), true);

if (is_array($data) && count($data)) {
foreach ($data as $error) {
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_code_sniffer');
$buildError->setCreatedDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line']);
$buildError->setLineEnd($error['line']);
$buildError->setMessage($error['message']);

switch ($error['type']) {
case 'ERROR':
$buildError->setSeverity(BuildError::SEVERITY_HIGH);
break;

case 'WARNING':
$buildError->setSeverity(BuildError::SEVERITY_LOW);
break;
}

$this->errorStore->save($buildError);
}
}
}

protected function processPhpDocCheckMeta(BuildMeta $meta)
{
$data = json_decode($meta->getMetaValue(), true);

if (is_array($data) && count($data)) {
foreach ($data as $error) {
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_docblock_checker');
$buildError->setCreatedDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line']);
$buildError->setLineEnd($error['line']);

switch ($error['type']) {
case 'method':
$buildError->setMessage($error['class'] . '::' . $error['method'] . ' is missing a docblock.');
$buildError->setSeverity(BuildError::SEVERITY_NORMAL);
break;

case 'class':
$buildError->setMessage('Class ' . $error['class'] . ' is missing a docblock.');
$buildError->setSeverity(BuildError::SEVERITY_LOW);
break;
}

$this->errorStore->save($buildError);
}
}
}
}
183 changes: 183 additions & 0 deletions PHPCI/Migrations/20151015124825_convert_errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php

use Phinx\Migration\AbstractMigration;
use PHPCI\Model\BuildMeta;
use PHPCI\Model\BuildError;

class ConvertErrors extends AbstractMigration
{
/**
* @var \PHPCI\Store\BuildMetaStore
*/
protected $metaStore;

/**
* @var \PHPCI\Store\BuildErrorStore
*/
protected $errorStore;

public function change()
{
$count = 100;

$this->metaStore = \b8\Store\Factory::getStore('BuildMeta');
$this->errorStore = \b8\Store\Factory::getStore('BuildError');

while ($count == 100) {
$data = $this->metaStore->getErrorsForUpgrade(100);
$count = count($data);

/** @var \PHPCI\Model\BuildMeta $meta */
foreach ($data as $meta) {
try {
switch ($meta->getMetaKey()) {
case 'phpmd-data':
$this->processPhpMdMeta($meta);
break;

case 'phpcs-data':
$this->processPhpCsMeta($meta);
break;

case 'phpdoccheck-data':
$this->processPhpDocCheckMeta($meta);
break;

case 'phpcpd-data':
$this->processPhpCpdMeta($meta);
break;

case 'technicaldebt-data':
$this->processTechnicalDebtMeta($meta);
break;
}
} catch (\Exception $ex) {}

$this->metaStore->delete($meta);
}
}
}

protected function processPhpMdMeta(BuildMeta $meta)
{
$data = json_decode($meta->getMetaValue(), true);

if (is_array($data) && count($data)) {
foreach ($data as $error) {
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_mess_detector');
$buildError->setCreatedDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line_start']);
$buildError->setLineEnd($error['line_end']);
$buildError->setSeverity(BuildError::SEVERITY_HIGH);
$buildError->setMessage($error['message']);

$this->errorStore->save($buildError);
}
}
}

protected function processPhpCsMeta(BuildMeta $meta)
{
$data = json_decode($meta->getMetaValue(), true);

if (is_array($data) && count($data)) {
foreach ($data as $error) {
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_code_sniffer');
$buildError->setCreatedDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line']);
$buildError->setLineEnd($error['line']);
$buildError->setMessage($error['message']);

switch ($error['type']) {
case 'ERROR':
$buildError->setSeverity(BuildError::SEVERITY_HIGH);
break;

case 'WARNING':
$buildError->setSeverity(BuildError::SEVERITY_LOW);
break;
}

$this->errorStore->save($buildError);
}
}
}

protected function processPhpDocCheckMeta(BuildMeta $meta)
{
$data = json_decode($meta->getMetaValue(), true);

if (is_array($data) && count($data)) {
foreach ($data as $error) {
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_docblock_checker');
$buildError->setCreatedDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line']);
$buildError->setLineEnd($error['line']);

switch ($error['type']) {
case 'method':
$buildError->setMessage($error['class'] . '::' . $error['method'] . ' is missing a docblock.');
$buildError->setSeverity(BuildError::SEVERITY_NORMAL);
break;

case 'class':
$buildError->setMessage('Class ' . $error['class'] . ' is missing a docblock.');
$buildError->setSeverity(BuildError::SEVERITY_LOW);
break;
}

$this->errorStore->save($buildError);
}
}
}

protected function processPhpCpdMeta(BuildMeta $meta)
{
$data = json_decode($meta->getMetaValue(), true);

if (is_array($data) && count($data)) {
foreach ($data as $error) {
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('php_cpd');
$buildError->setCreatedDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line_start']);
$buildError->setLineEnd($error['line_end']);
$buildError->setSeverity(BuildError::SEVERITY_NORMAL);
$buildError->setMessage('Copy and paste detected.');

$this->errorStore->save($buildError);
}
}
}

protected function processTechnicalDebtMeta(BuildMeta $meta)
{
$data = json_decode($meta->getMetaValue(), true);

if (is_array($data) && count($data)) {
foreach ($data as $error) {
$buildError = new BuildError();
$buildError->setBuildId($meta->getBuildId());
$buildError->setPlugin('technical_debt');
$buildError->setCreatedDate(new \DateTime());
$buildError->setFile($error['file']);
$buildError->setLineStart($error['line']);
$buildError->setSeverity(BuildError::SEVERITY_NORMAL);
$buildError->setMessage($error['message']);

$this->errorStore->save($buildError);
}
}
}
}
2 changes: 1 addition & 1 deletion PHPCI/Model/Build/GithubBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function getFileLinkTemplate()
$link = 'https://github.com/' . $reference . '/';
$link .= 'blob/' . $branch . '/';
$link .= '{FILE}';
$link .= '#L{LINE}';
$link .= '#L{LINE}-L{LINE_END}';

return $link;
}
Expand Down
2 changes: 0 additions & 2 deletions PHPCI/Plugin/PhpCpd.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ protected function processReport($xmlString)
$file['line'],
(int) $file['line'] + (int) $duplication['lines']
);
$this->build->reportError($this->phpci, $fileName, $file['line'], $message);

}

$warnings++;
Expand Down
5 changes: 2 additions & 3 deletions PHPCI/Store/BuildMetaStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ class BuildMetaStore extends BuildMetaStoreBase
* @param $limit
* @return array
*/
public function getErrorsForUpgrade($start, $limit)
public function getErrorsForUpgrade($limit)
{
$query = 'SELECT * FROM build_meta
WHERE meta_key IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\')
ORDER BY id ASC LIMIT :start, :limit';
ORDER BY id ASC LIMIT :limit';

$stmt = Database::getConnection('read')->prepare($query);

$stmt->bindValue(':start', $start, \PDO::PARAM_INT);
$stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);

if ($stmt->execute()) {
Expand Down
1 change: 1 addition & 0 deletions PHPCI/View/Build/errors.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ foreach ($errors as $error):

$link = str_replace('{FILE}', $error->getFile(), $linkTemplate);
$link = str_replace('{LINE}', $error->getLineStart(), $link);
$link = str_replace('{LINE_END}', $error->getLineEnd(), $link);
?>

<tr class="bg-<?php print $error->getSeverityClass(); ?>">
Expand Down

0 comments on commit f33f0a4

Please sign in to comment.