-
Notifications
You must be signed in to change notification settings - Fork 5
Reducing complexity of execute method in SuggestCommand #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e42dc82
4cdd1e6
9183fb2
46ce682
494ef03
88d5295
7e5eaeb
de62b48
0e425a0
c565d4e
61743aa
8d873fd
49cf635
0899176
1645081
54c5324
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,26 +9,40 @@ class ProcessedFileList | |
/** | ||
* @var int | ||
*/ | ||
private $originalAmount; | ||
private $unfilteredAmount; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $filteredAmount; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private $filtered; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private $files; | ||
private $unfiltered; | ||
|
||
/** | ||
* @var Scanner | ||
*/ | ||
private $scanner; | ||
|
||
/** | ||
* ProcessedFileList constructor. | ||
* @param int $originalAmount | ||
* @param string[] $files | ||
* @param string[] $unfiltered | ||
* @param string[] $filtered | ||
* @param Scanner $scanner | ||
*/ | ||
public function __construct($originalAmount, array &$files, Scanner &$scanner) | ||
public function __construct(array $unfiltered, array $filtered, Scanner &$scanner) | ||
{ | ||
$this->originalAmount = $originalAmount; | ||
$this->files = $files; | ||
$this->unfilteredAmount = count($unfiltered); | ||
$this->filteredAmount = count($filtered); | ||
$this->filtered = $filtered; | ||
$this->unfiltered = $unfiltered; | ||
$this->scanner = $scanner; | ||
} | ||
|
||
|
@@ -40,20 +54,35 @@ public function getScanner() | |
return $this->scanner; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getFiltered() | ||
{ | ||
return $this->filtered; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getOriginalAmount() | ||
public function getFilteredAmount() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use "count" instead of "amount" (see https://english.stackexchange.com/questions/141564/differences-between-amount-count-number-and-quantity) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very useful, thank you. |
||
{ | ||
return $this->originalAmount; | ||
return $this->filteredAmount; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
* @return int | ||
*/ | ||
public function getFiles() | ||
public function getUnfilteredAmount() | ||
{ | ||
return $this->files; | ||
return $this->unfilteredAmount; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getUnfiltered() | ||
{ | ||
return $this->unfiltered; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,12 @@ | |
|
||
namespace PHPSemVerCheckerGit\Test; | ||
|
||
use PHPSemVerChecker\SemanticVersioning\Level; | ||
use PHPSemVerCheckerGit\Console\Command\SuggestCommand; | ||
use PHPUnit\Framework\TestCase; | ||
use PHPSemVerChecker\SemanticVersioning\Level; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
use ReflectionMethod; | ||
use vierbergenlars\SemVer\version; | ||
|
||
class SuggestCommandTest extends TestCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for the added tests. |
||
|
@@ -21,6 +24,18 @@ private function getMockedVersion($major, $minor, $patch) | |
return new version("$major.$minor.$patch", true); | ||
} | ||
|
||
/** | ||
* @return ReflectionMethod | ||
* @throws ReflectionException | ||
*/ | ||
private function getNextTagMethod() | ||
{ | ||
$class = new ReflectionClass('PHPSemVerCheckerGit\Console\Command\SuggestCommand'); | ||
$method = $class->getMethod('getNextTag'); | ||
$method->setAccessible(true); | ||
return $method; | ||
} | ||
|
||
/** | ||
* Provides a few test cases | ||
* @return array | ||
|
@@ -54,18 +69,16 @@ public function provideGetNextTag() { | |
* @param $level | ||
* @param $version | ||
* @param $expected | ||
* @throws \ReflectionException | ||
* @throws ReflectionException | ||
* @test | ||
* @dataProvider provideGetNextTag | ||
*/ | ||
public function testGetNextTag($level, version $version, $expected) { | ||
public function testGetNextTag($level, version $version, $expected) | ||
{ | ||
$report = $this->getMockBuilder('PHPSemVerChecker\Report\Report')->disableOriginalConstructor()->getMock(); | ||
$report->expects($this->once())->method('getSuggestedLevel')->willReturn($level); | ||
$instance = new SuggestCommand(); | ||
$rc = new \ReflectionClass('PHPSemVerCheckerGit\Console\Command\SuggestCommand'); | ||
$method = $rc->getMethod('getNextTag'); | ||
$method->setAccessible(true); | ||
$result = $method->invoke($instance, $report, $version); | ||
|
||
$result = $this->getNextTagMethod()->invoke(new SuggestCommand(), $report, $version); | ||
$this->assertInstanceOf('vierbergenlars\SemVer\version', $result); | ||
$this->assertEquals($expected, $result->getVersion()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful, we still want the FQCN (fully qualified class name).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having FQN in PHPdoc looks inconsistent to me when they aren't also used elsewhere, Will fix those.