Skip to content

Commit

Permalink
Add phpcpd
Browse files Browse the repository at this point in the history
  • Loading branch information
elkuku committed Apr 4, 2014
1 parent 7a26f81 commit f429433
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
68 changes: 68 additions & 0 deletions cli/Application/Command/Test/Copypaste.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Part of the Joomla! Tracker application.
*
* @copyright Copyright (C) 2012 - 2014 Open Source Matters, Inc. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
*/

namespace Application\Command\Test;

use SebastianBergmann\PHPCPD\CLI\Application as PHPCPDApplication;

use Symfony\Component\Console\Input\ArrayInput;

/**
* Class for running checkstyle tests.
*
* @since 1.0
*/
class Copypaste extends Test
{
/**
* The command "description" used for help texts.
*
* @var string
* @since 1.0
*/
protected $description = 'Run Copy/Paste Detector (CPD) for PHP code.';

/**
* Execute the command.
*
* @return string Number of errors.
*
* @since 1.0
* @throws \UnexpectedValueException
*/
public function execute()
{
$this->getApplication()->outputTitle('Run Copy/Paste Detector');

$application = new \SebastianBergmann\PHPCPD\CLI\Application;

$application->setAutoExit(false);

$cloneCount = $application->run(
new ArrayInput(
['values' => [
JPATH_ROOT . '/cli',
JPATH_ROOT . '/src'
]]
)
);

$this->out(
$cloneCount
? sprintf('<error> %d clones found. </error>', $cloneCount)
: '<ok>No CP errors</ok>'
);

if ($this->exit)
{
exit($cloneCount ? 1 : 0);
}

return $cloneCount;
}
}
9 changes: 9 additions & 0 deletions cli/Application/Command/Test/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public function execute()
->setExit(false)
->execute();

/*
* @todo enable when https://github.com/sebastianbergmann/phpcpd/pull/93 is merged
$statusCPD = (new Copypaste)
->setContainer($this->getContainer())
->setExit(false)
->execute();
*/

$status = ($statusCS || $statusUT) ? 1 : 0;

$this
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"filp/whoops": "1.0.*@stable",
"mustache/mustache": "2.1.*@stable",
"phpunit/phpunit" : "3.7.*@stable",
"squizlabs/php_codesniffer": "1.*@stable"
"squizlabs/php_codesniffer": "1.*@stable",
"sebastian/phpcpd": "*"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit f429433

Please sign in to comment.