-
Notifications
You must be signed in to change notification settings - Fork 56
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
11 changed files
with
188 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: "Phar construction" | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- '**.md' | ||
- 'img/**' | ||
pull_request: | ||
paths-ignore: | ||
- '**.md' | ||
- 'img/**' | ||
|
||
jobs: | ||
build: | ||
name: "Build Phar" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v2" | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "none" | ||
php-version: "7.2" | ||
tools: composer:v2 | ||
|
||
- name: "Install dependencies" | ||
run: | | ||
composer config platform.php 7.1.3 | ||
composer update --no-dev --no-interaction --no-progress --prefer-dist | ||
composer config --unset platform.php | ||
- name: "Download Box" | ||
run: | | ||
curl -sL https://github.com/box-project/box/releases/download/3.8.5/box.phar -o box.phar | ||
chmod +x box.phar | ||
- name: "Compile" | ||
run: ./box.phar compile | ||
|
||
- name: "Test Version" | ||
run: diff <(bin/churn -V) <(./churn.phar -V) | ||
|
||
- name: "Test Phar" | ||
run: diff <(bin/churn run src) <(./churn.phar run src) | ||
|
||
- name: "Save Phar" | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: churn.phar | ||
path: ./churn.phar | ||
if-no-files-found: error |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: "Continuous Integration" | ||
|
||
on: | ||
on: | ||
push: | ||
paths-ignore: | ||
- '**.md' | ||
|
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ composer.lock | |
docs | ||
vendor | ||
coverage.xml | ||
.idea | ||
*.phar | ||
.idea |
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,16 @@ | ||
{ | ||
"dump-autoload": false, | ||
"finder": [ | ||
{ | ||
"in": "bin" | ||
}, | ||
{ | ||
"in": "src" | ||
}, | ||
{ | ||
"name": "*.php", | ||
"in": "vendor" | ||
} | ||
], | ||
"output": "churn.phar" | ||
} |
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,37 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Churn\Command; | ||
|
||
use Churn\Assessors\CyclomaticComplexity\CyclomaticComplexityAssessor; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class AssessComplexityCommand extends Command | ||
{ | ||
/** | ||
* Configure the command | ||
* @return void | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this->setName('assess-complexity') | ||
->addArgument('file', InputArgument::REQUIRED, 'Path to file to analyze.') | ||
->setDescription('Calculate the Cyclomatic Complexity'); | ||
} | ||
|
||
/** | ||
* Execute the command | ||
* @param InputInterface $input Input. | ||
* @param OutputInterface $output Output. | ||
* @return integer | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$file = $input->getArgument('file'); | ||
$assessor = new CyclomaticComplexityAssessor(); | ||
$output->writeln($assessor->assess($file)); | ||
return 0; | ||
} | ||
} |
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,42 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Churn\Tests\Integration\Command; | ||
|
||
use Churn\Command\AssessComplexityCommand; | ||
use Churn\Tests\BaseTestCase; | ||
use function ctype_digit; | ||
use DI\ContainerBuilder; | ||
use function rtrim; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class AssessComplexityCommandTest extends BaseTestCase | ||
{ | ||
/** @var CommandTester */ | ||
private $commandTester; | ||
|
||
protected function setUp() | ||
{ | ||
$container = ContainerBuilder::buildDevContainer(); | ||
$application = new Application('churn-php', 'test'); | ||
$application->add($container->get(AssessComplexityCommand::class)); | ||
$command = $application->find('assess-complexity'); | ||
$this->commandTester = new CommandTester($command); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->commandTester = null; | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_the_cyclomatic_complexity() | ||
{ | ||
$exitCode = $this->commandTester->execute(['file' => __FILE__]); | ||
$result = rtrim($this->commandTester->getDisplay()); | ||
|
||
$this->assertEquals(0, $exitCode); | ||
$this->assertTrue(ctype_digit($result), 'The result of the command must be an integer'); | ||
$this->assertGreaterThan(0, (int) $result); | ||
} | ||
} |