Skip to content

Commit

Permalink
Add PHPStan build to travis, update codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Oct 27, 2017
1 parent aa9b190 commit 7c7aebb
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 64 deletions.
9 changes: 6 additions & 3 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ return PhpCsFixer\Config::create()
'blank_line_before_return' => true,
'cast_spaces' => true,
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'function_typehint_space' => true,
'linebreak_after_opening_tag' => true,
'lowercase_cast' => true,
'mb_str_functions' => true,
'method_separation' => true,
Expand Down Expand Up @@ -60,17 +60,20 @@ return PhpCsFixer\Config::create()
'phpdoc_trim' => true,
'phpdoc_types' => true,
'psr4' => true,
'return_type_declaration' => true,
'self_accessor' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'ternary_to_null_coalescing' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'void_return' => true,
'whitespace_after_comma_in_array' => true,
])
->setRiskyAllowed(true)
->setFinder($finder);
->setFinder($finder)
->setRiskyAllowed(true);
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ matrix:
include:
- php: 7.1
env: dependencies="--prefer-lowest"
- php: 7.1
env: CHECK_CODESTYLE=1
before_install:
- phpenv config-rm xdebug.ini
script:
- vendor/bin/php-cs-fixer fix --diff --dry-run -vvv
- vendor/bin/phpstan.phar analyze ./src --level 7
after_script: ~
after_success: ~

install:
- travis_retry composer self-update && composer --version
- travis_retry composer update --no-interaction $dependencies

script:
- vendor/bin/php-cs-fixer fix --diff --dry-run
- vendor/bin/phpunit --coverage-clover coverage-clover.xml

after_script:
Expand Down
2 changes: 1 addition & 1 deletion bin/ci-detector
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env php
<?php
<?php declare(strict_types=1);

namespace OndraM\Ci;

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"require-dev": {
"phpunit/phpunit": "^6.4",
"friendsofphp/php-cs-fixer": "^2.7",
"php-coveralls/php-coveralls": "^1.0.2"
"php-coveralls/php-coveralls": "^1.0.2",
"phpstan/phpstan-shim": "^0.8.5"
},
"bin": ["bin/ci-detector"],
"scripts": {
Expand Down
16 changes: 4 additions & 12 deletions src/CiMeta.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace OndraM\CiDetector;

Expand All @@ -23,18 +23,14 @@ public function __construct()
$this->methodNameFilter = new CamelCaseToDash();
}

/**
* @param string $propertyName
* @return string
*/
public function assembleMethodNameFromProperty($propertyName)
public function assembleMethodNameFromProperty(string $propertyName): string
{
$methodName = $this->propertyNameFilter->filter($propertyName);

return 'get' . $methodName;
}

public function getAvailableProperties()
public function getAvailableProperties(): array
{
$properties = [];

Expand All @@ -49,11 +45,7 @@ public function getAvailableProperties()
return $properties;
}

/**
* @param string $methodName
* @return string
*/
private function derivePropertyNameFromMethod($methodName)
private function derivePropertyNameFromMethod(string $methodName): string
{
$methodName = mb_substr($methodName, 3);

Expand Down
16 changes: 4 additions & 12 deletions src/Command/DetectCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace OndraM\CiDetector\Command;

Expand All @@ -18,19 +18,15 @@ class DetectCommand extends Command
/** @var CiDetector */
private $ciDetector;

/**
* @param CiDetector $ciDetector
* @param string $name
*/
public function __construct(CiDetector $ciDetector, $name = null)
public function __construct(CiDetector $ciDetector, string $name = null)
{
$this->ciMeta = new CiMeta();
$this->ciDetector = $ciDetector;

parent::__construct($name);
}

protected function configure()
protected function configure(): void
{
$availableProperties = $this->ciMeta->getAvailableProperties();

Expand Down Expand Up @@ -61,11 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

/**
* @param string $propertyName
* @return string
*/
private function detectProperty($propertyName)
private function detectProperty(string $propertyName): string
{
$getterMethod = $this->ciMeta->assembleMethodNameFromProperty($propertyName);
$ci = $this->ciDetector->detect();
Expand Down
10 changes: 3 additions & 7 deletions src/Command/DumpCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace OndraM\CiDetector\Command;

Expand All @@ -21,11 +21,7 @@ class DumpCommand extends Command
/** @var CiDetector */
private $ciDetector;

/**
* @param CiDetector $ciDetector
* @param string $name
*/
public function __construct(CiDetector $ciDetector, $name = null)
public function __construct(CiDetector $ciDetector, string $name = null)
{
$this->propertyNameFilter = new DashToCamelCase();
$this->ciMeta = new CiMeta();
Expand All @@ -34,7 +30,7 @@ public function __construct(CiDetector $ciDetector, $name = null)
parent::__construct($name);
}

protected function configure()
protected function configure(): void
{
$this->setName('dump')
->setDescription('Dump CI values from current environment');
Expand Down
13 changes: 6 additions & 7 deletions tests/CiMetaTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
<?php declare(strict_types=1);

namespace OndraM\CiDetector;
namespace OndraM\CiDetector\Tests;

use OndraM\CiDetector\CiMeta;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -11,10 +12,8 @@ class CiMetaTest extends TestCase
{
/**
* @dataProvider providePropertyNames
* @param string $property
* @param string $expectedMethodName
*/
public function testShouldAssembleMethodNameFromProperty($property, $expectedMethodName)
public function testShouldAssembleMethodNameFromProperty(string $property, string $expectedMethodName): void
{
$meta = new CiMeta();

Expand All @@ -24,15 +23,15 @@ public function testShouldAssembleMethodNameFromProperty($property, $expectedMet
/**
* @return array[]
*/
public function providePropertyNames()
public function providePropertyNames(): array
{
return [
['foo', 'getFoo'],
['ci-name', 'getCiName'],
];
}

public function testShouldGetPropertyNamesFromTheCiInterface()
public function testShouldGetPropertyNamesFromTheCiInterface(): void
{
$meta = new CiMeta();

Expand Down
17 changes: 6 additions & 11 deletions tests/Command/DetectCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace OndraM\CiDetector\Tests\Command;

Expand All @@ -18,7 +18,7 @@
*/
class DetectCommandTest extends TestCase
{
public function testShouldReturnNonZeroStatusCodeIfCiNotDetected()
public function testShouldReturnNonZeroStatusCodeIfCiNotDetected(): void
{
$ciDetectorMock = $this->createCiDetectorForNonCiEnvironment();
$command = $this->createCommandWithCiDetectorMock($ciDetectorMock);
Expand All @@ -30,7 +30,7 @@ public function testShouldReturnNonZeroStatusCodeIfCiNotDetected()
$this->assertSame('', $tester->getDisplay());
}

public function testShouldReturnZeroStatusCodeIfCiIsDetected()
public function testShouldReturnZeroStatusCodeIfCiIsDetected(): void
{
$ciDetectorMock = $this->createCiDetectorForCiEnvironment($this->createMock(CiInterface::class));
$command = $this->createCommandWithCiDetectorMock($ciDetectorMock);
Expand All @@ -42,7 +42,7 @@ public function testShouldReturnZeroStatusCodeIfCiIsDetected()
$this->assertSame('', $tester->getDisplay());
}

public function testShouldOutputPropertyValue()
public function testShouldOutputPropertyValue(): void
{
$ciMock = $this->createConfiguredMock(
Travis::class,
Expand All @@ -66,7 +66,7 @@ public function testShouldOutputPropertyValue()
$this->assertSame("origin/feature/foo\n", $tester->getDisplay(true));
}

public function testShouldThrowExceptionIfCiPropertyIsNotSupported()
public function testShouldThrowExceptionIfCiPropertyIsNotSupported(): void
{
$ciDetectorMock = $this->createCiDetectorForCiEnvironment($this->createMock(CiInterface::class));
$command = $this->createCommandWithCiDetectorMock($ciDetectorMock);
Expand All @@ -83,11 +83,7 @@ public function testShouldThrowExceptionIfCiPropertyIsNotSupported()
);
}

/**
* @param CiDetector $ciDetector
* @return Command
*/
private function createCommandWithCiDetectorMock(CiDetector $ciDetector)
private function createCommandWithCiDetectorMock(CiDetector $ciDetector): Command
{
$application = new Application();
$application->add(new DetectCommand($ciDetector));
Expand All @@ -96,7 +92,6 @@ private function createCommandWithCiDetectorMock(CiDetector $ciDetector)
}

/**
* @param CiInterface $ci
* @return CiDetector::class|\PHPUnit_Framework_MockObject_MockObject
*/
private function createCiDetectorForCiEnvironment(CiInterface $ci)
Expand Down
13 changes: 4 additions & 9 deletions tests/Command/DumpCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace OndraM\CiDetector\Tests\Command;

Expand All @@ -18,7 +18,7 @@
*/
class DumpCommandTest extends TestCase
{
public function testShouldThrowExceptionIfCiNotDetected()
public function testShouldThrowExceptionIfCiNotDetected(): void
{
$ciDetectorMock = $this->createCiDetectorForNonCiEnvironment();
$command = $this->createCommandWithCiDetectorMock($ciDetectorMock);
Expand All @@ -29,7 +29,7 @@ public function testShouldThrowExceptionIfCiNotDetected()
$tester->execute(['command' => $command->getName()]);
}

public function testShouldDumpDetectedCiValue()
public function testShouldDumpDetectedCiValue(): void
{
$ciMock = $this->createConfiguredMock(
Travis::class,
Expand Down Expand Up @@ -71,11 +71,7 @@ public function testShouldDumpDetectedCiValue()
$this->assertSame($expectedOutput, $tester->getDisplay(true));
}

/**
* @param CiDetector $ciDetector
* @return Command
*/
private function createCommandWithCiDetectorMock(CiDetector $ciDetector)
private function createCommandWithCiDetectorMock(CiDetector $ciDetector): Command
{
$application = new Application();
$application->add(new DumpCommand($ciDetector));
Expand All @@ -84,7 +80,6 @@ private function createCommandWithCiDetectorMock(CiDetector $ciDetector)
}

/**
* @param CiInterface $ci
* @return CiDetector::class|\PHPUnit_Framework_MockObject_MockObject
*/
private function createCiDetectorForCiEnvironment(CiInterface $ci)
Expand Down

0 comments on commit 7c7aebb

Please sign in to comment.