Skip to content

Commit

Permalink
Merge pull request #26 from bearsunday/qa
Browse files Browse the repository at this point in the history
Psalm errorLevel 1 (max)
  • Loading branch information
koriym authored May 27, 2020
2 parents 1999aa4 + 3ffd5a7 commit 0184258
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 66 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
language: php
sudo: false

php:
- 7.2
- 7.3
- 7.4snapshot
- 7.4

cache:
directories:
- vendor
- $HOME/.composer/cache

matrix:
fast_finish: true

before_install:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;
Expand All @@ -26,13 +22,14 @@ script:
- ./vendor/bin/phpunit;

jobs:
fast_finish: true
include:
- stage: Test
name: Lowest dependencies
php: 7.2
install: composer update --prefer-dist --prefer-lowest

- stage: Test
- stage: Code Quality
name: Code coverage
php: 7.2
before_script:
Expand All @@ -46,10 +43,13 @@ jobs:
- stage: Code Quality
name: Static analysis
php: 7.2
install: composer global require --dev phpstan/phpstan ^0.11 vimeo/psalm ^3.7;
install:
- composer update
- composer global require --dev phpstan/phpstan ^0.12 vimeo/psalm ^3.11 phpmetrics/phpmetrics ^2.6;
script:
- ~/.composer/vendor/bin/phpstan analyse -l max -c phpstan.neon src tests --no-progress --no-interaction;
- ~/.composer/vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction;
- ~/.composer/vendor/bin/psalm --show-info=false
- ~/.composer/vendor/bin/phpmetrics --exclude=Exception src

- stage: Code Quality
name: Coding standards
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"require": {
"php": ">=7.2.0",
"koriym/psr4list": "^1.0"
"koriym/psr4list": "^1.0.2"
},
"autoload":{
"psr-4":{
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: max
paths:
- src
- tests
excludes_analyse:
- */tests/*/tmp/*
- */tests/Fake/*
44 changes: 2 additions & 42 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,55 +1,15 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
xsi:schemaLocation="https://getpsalm.org/schema/config https://psalm.dev/schema/config"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->

<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedClass errorLevel="info" />
<DeprecatedConstant errorLevel="info" />
<DeprecatedFunction errorLevel="info" />
<DeprecatedInterface errorLevel="info" />
<DeprecatedTrait errorLevel="info" />

<InternalMethod errorLevel="info" />
<InternalProperty errorLevel="info" />
<InternalClass errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<MissingClosureParamType errorLevel="info" />
<MissingParamType errorLevel="info" />

<RedundantCondition errorLevel="info" />

<DocblockTypeContradiction errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />

<UnresolvableInclude errorLevel="info" />

<RawObjectIteration errorLevel="info" />

<InvalidStringClass errorLevel="info" />
</issueHandlers>
</psalm>
8 changes: 7 additions & 1 deletion src/AbstractAppMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ abstract class AbstractAppMeta
*/
public $logDir;

/**
* @return \Generator<array{0: string, 1: string}>
*/
public function getResourceListGenerator() : \Generator
{
$list = new Psr4List;
Expand All @@ -39,15 +42,18 @@ public function getResourceListGenerator() : \Generator

/**
* @param string $scheme 'app' | 'page' | '*'
*
* @return \Generator<ResMeta>
*/
public function getGenerator(string $scheme = '*') : \Generator
{
foreach ($this->getResourceListGenerator() as list($class, $file)) {
$paths = explode('\\', $class);
/** @var array<string> $paths */
$path = array_slice($paths, 3);
array_walk($path, [$this, 'camel2kebab']);
if ($scheme === '*') {
$uri = sprintf('%s://self/%s', $path[0], implode('/', array_slice($path, 1)));
$uri = sprintf('%s://self/%s', (string) $path[0], implode('/', array_slice($path, 1)));

yield new ResMeta($uri, $class, $file);
}
Expand Down
16 changes: 8 additions & 8 deletions tests/AppMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ protected function tearDown() : void
chmod(__DIR__ . '/Fake/fake-not-writable/var', 0777);
}

public function testNew()
public function testNew() : void
{
$actual = $this->appMeta;
$this->assertInstanceOf('\BEAR\AppMeta\Meta', $actual);
$this->assertFileExists($this->appMeta->tmpDir);
}

public function testAppReflectorResourceList()
public function testAppReflectorResourceList() : void
{
$appMeta = new Meta('FakeVendor\HelloWorld');
$classes = $files = [];
Expand All @@ -64,32 +64,32 @@ public function testAppReflectorResourceList()
$this->assertSame($expect, $files);
}

public function testInvalidName()
public function testInvalidName() : void
{
$this->expectException(AppNameException::class);
new Meta('Invalid\Invalid');
}

public function testNotWritable()
public function testNotWritable() : void
{
$this->expectException(NotWritableException::class);
new Meta('FakeVendor\NotWritable');
}

public function testVarTmpFolderCreation()
public function testVarTmpFolderCreation() : void
{
new Meta('FakeVendor\HelloWorld', 'stage-app');
$this->assertFileExists(__DIR__ . '/Fake/fake-app/var/log/stage-app');
$this->assertFileExists(__DIR__ . '/Fake/fake-app/var/tmp/stage-app');
}

public function testDoNotClear()
public function testDoNotClear() : void
{
new Meta('FakeVendor\HelloWorld', 'test-app');
$this->assertFileExists(__DIR__ . '/Fake/fake-app/var/tmp/test-app/not-cleared.txt');
}

public function testGetGeneratorApp()
public function testGetGeneratorApp() : void
{
$appMeta = new Meta('FakeVendor\HelloWorld');
$uris = [];
Expand All @@ -102,7 +102,7 @@ public function testGetGeneratorApp()
$this->assertContains('tests/Fake/fake-app/src/Resource/App/One.php', $uris[0]->filePath);
}

public function testGetGeneratorAll()
public function testGetGeneratorAll() : void
{
$appMeta = new Meta('FakeVendor\HelloWorld');
$uris = [];
Expand Down
12 changes: 6 additions & 6 deletions tests/MetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ protected function tearDown() : void
chmod(__DIR__ . '/Fake/fake-not-writable/var', 0777);
}

public function testNew()
public function testNew() : void
{
$actual = $this->meta;
$this->assertInstanceOf(Meta::class, $actual);
$this->assertFileExists($this->meta->tmpDir);
}

public function testAppReflectorResourceList()
public function testAppReflectorResourceList() : void
{
$Meta = new Meta('FakeVendor\HelloWorld');
$classes = $files = [];
Expand All @@ -63,26 +63,26 @@ public function testAppReflectorResourceList()
$this->assertSame($expect, $files);
}

public function testInvalidName()
public function testInvalidName() : void
{
$this->expectException(AppNameException::class);
new Meta('Invalid\Invalid');
}

public function testNotWritable()
public function testNotWritable() : void
{
$this->expectException(NotWritableException::class);
new Meta('FakeVendor\NotWritable');
}

public function testVarTmpFolderCreation()
public function testVarTmpFolderCreation() : void
{
new Meta('FakeVendor\HelloWorld', 'stage-app');
$this->assertFileExists(__DIR__ . '/Fake/fake-app/var/log/stage-app');
$this->assertFileExists(__DIR__ . '/Fake/fake-app/var/tmp/stage-app');
}

public function testDoNotClear()
public function testDoNotClear() : void
{
new Meta('FakeVendor\HelloWorld', 'test-app');
$this->assertFileExists(__DIR__ . '/Fake/fake-app/var/tmp/test-app/not-cleared.txt');
Expand Down

0 comments on commit 0184258

Please sign in to comment.