Skip to content

Commit

Permalink
Merge pull request #24 from bearsunday/cleanup
Browse files Browse the repository at this point in the history
Cleanup for the release
  • Loading branch information
koriym authored Jun 9, 2019
2 parents d6f2bd6 + 6f377cf commit 17417a1
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ return \PhpCsFixer\Config::create()
'semicolon_after_instruction' => true, // @Symfony
'set_type_to_cast' => true, // @Symfony:risky
'short_scalar_cast' => true, // @Symfony:risky
// 'simplified_null_return' => true,
'simplified_null_return' => true,
'single_blank_line_before_namespace' => true, // @Symfony
// 'single_line_comment_style' => true, // @Symfony
'single_line_after_imports' => true,
Expand Down
60 changes: 46 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
language: php
sudo: false

php:
- 7
- 7.1
- 7.2
- 7.3

cache:
directories:
- vendor
- $HOME/.composer/cache
env:
matrix:
- DEPENDENCIES=''
- DEPENDENCIES='--prefer-lowest --prefer-stable'
before_script:

matrix:
fast_finish: true

before_install:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
- composer self-update
- composer update $DEPENDENCIES
- if [[ $TRAVIS_PHP_VERSION = '7.1' && DEPENDENCIES = '' ]]; then COVERAGE="--coverage-clover=coverage.clover"; else phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION = '7.1' && DEPENDENCIES = '' ]]; then composer require --dev phpstan/phpstan-shim friendsofphp/php-cs-fixer; fi

install:
- composer update

script:
- ./vendor/bin/phpunit $COVERAGE;
- if [[ $TRAVIS_PHP_VERSION = '7.1' && DEPENDENCIES = '' ]]; then IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS && ./vendor/bin/php-cs-fixer fix --config=.php_cs -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}";fi
- if [[ $TRAVIS_PHP_VERSION = '7.1' && DEPENDENCIES = '' ]]; then ./vendor/bin/phpstan analyse -l max -c phpstan.neon src tests --no-progress --no-interaction; fi
after_script:
- if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- ./vendor/bin/phpunit;

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

- stage: Test
name: Code coverage
php: 7.2
before_script:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
script:
- ./vendor/bin/phpunit -v --coverage-clover ./build/logs/clover.xml
after_script:
- wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover;

- stage: Code Quality
name: Static analysis
php: 7.2
install: composer require --dev phpstan/phpstan-shim ^0.11;
script:
- ./vendor/bin/phpstan analyse -l max -c phpstan.neon src tests --no-progress --no-interaction;

- stage: Code Quality
name: Coding standards
php: 7.2
install: composer require --dev friendsofphp/php-cs-fixer ^2.0;
script:
- ./vendor/bin/php-cs-fixer --dry-run -v fix;
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Application meta data value object

* AppMeta object keep the application path such as `$tmpDir`, `$logDir` and `$appDir` in public property by given app name and context.

* `getResourceListGenerator()` return `\Generator` to get resource class name and paths.
* `getGenerator()` return `\Generator` to get resource meta data.


```php
Expand All @@ -23,10 +23,17 @@ $appMeta = new AppMeta('MyVendor\HelloWorld');
// $appMeta->logDir; // MyVendor\HelloWorld/var/log
// $appMeta->tmpDir; // MyVendor\HelloWorld/var/tmp

// resource class / list generator
// resource meta generator

foreach ($appMeta->getResourceListGenerator() as list($class, $file)) {
var_dump($class); // FakeVendor\HelloWorld\Resource\App\Greeting
var_dump($file); // path/to/Greeting.php
foreach ($appMeta->getGenerator('*') as $resourceMeta) {
var_dump($resourceMeta->uriPath); // app://self/one
var_dump($resourceMeta->class); // FakeVendor\HelloWorld\Resource\App\One
var_dump($resourceMeta->file); // /path/to/src/Resource/App/One.php
}

foreach ($appMeta->getGenerator('app') as $resourceMeta) {
var_dump($resourceMeta->uriPath); // /one
var_dump($resourceMeta->class); // FakeVendor\HelloWorld\Resource\App\One
var_dump($resourceMeta->file); // /path/to/src/Resource/App/One.php
}
```
27 changes: 21 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],
"license": "MIT",
"require": {
"php": ">=7.0.0",
"php": ">=7.1.0",
"koriym/psr4list": "^1.0"
},
"autoload":{
Expand All @@ -25,10 +25,25 @@
"bear/resource": "^1.0",
"phpunit/phpunit": "^6.0"
},
"scripts" :{
"test": ["@cs", "phpunit", "phpstan analyse -l max src tests -c phpstan.neon --no-progress"],
"coverage": ["php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"cs": ["php-cs-fixer fix -v --dry-run", "phpcs --standard=./phpcs.xml src"],
"cs-fix": ["php-cs-fixer fix -v", "phpcbf src"]
"scripts" : {
"test": [
"phpunit"
],
"tests": [
"@cs",
"phpstan analyse -l max src tests -c phpstan.neon --no-progress",
"@test"
],
"coverage": [
"php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"
],
"cs": [
"php-cs-fixer fix -v --dry-run",
"phpcs --standard=./phpcs.xml src"
],
"cs-fix": [
"php-cs-fixer fix -v",
"phpcbf src"
]
}
}
9 changes: 4 additions & 5 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0"?>
<ruleset>
<!-- 2. General -->
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="PHP_CodeSniffer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<!-- Include the whole PSR-2 standard -->
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength"/>
</rule>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="PEAR.Commenting.FunctionComment">
<exclude name="PEAR.Commenting.FunctionComment.MissingReturn"/>
<exclude name="PEAR.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="PEAR.Commenting.FunctionComment.SpacingBeforeTags"/>
<exclude name="PEAR.Commenting.FunctionComment.MissingParamTag"/>
<exclude name="PEAR.Commenting.FunctionComment.Missing"/>
<exclude name="PEAR.Commenting.FunctionComment.ParameterCommentsNotAligned"/>
<exclude name="PEAR.Commenting.FunctionComment.ParamNameNoMatch"/>
</rule>
</ruleset>
57 changes: 28 additions & 29 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
<ruleset xmlns="http://pmd.sf.net/ruleset/1.0.0"
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<!--codesize-->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity" />
<rule ref="rulesets/codesize.xml/NPathComplexity" />
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity" />
<rule ref="rulesets/codesize.xml/ExcessiveClassLength" />
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength" />
<rule ref="rulesets/codesize.xml/ExcessiveParameterList" />
<rule ref="rulesets/codesize.xml/ExcessivePublicCount" />
<rule ref="rulesets/codesize.xml/TooManyFields" />
<rule ref="rulesets/codesize.xml/TooManyMethods" />
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/codesize.xml/NPathComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
<rule ref="rulesets/codesize.xml/TooManyFields"/>
<rule ref="rulesets/codesize.xml/TooManyMethods"/>
<!--design-->
<rule ref="rulesets/design.xml/EvalExpression" />
<rule ref="rulesets/design.xml/ExitExpression" />
<rule ref="rulesets/design.xml/EvalExpression"/>
<rule ref="rulesets/design.xml/ExitExpression"/>
<rule ref="rulesets/design.xml/GotoStatement" />
<rule ref="rulesets/design.xml/NumberOfChildren" />
<rule ref="rulesets/design.xml/DepthOfInheritance" />
<rule ref="rulesets/design.xml/CouplingBetweenObjects" />
<rule ref="rulesets/design.xml/NumberOfChildren"/>
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
<!-- <rule ref="rulesets/design.xml/CouplingBetweenObjects" /> -->
<!--naming-->
<rule ref="rulesets/naming.xml/ConstantNamingConventions" />
<rule ref="rulesets/naming.xml/BooleanGetMethodName" />
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
<!--unusedcode-->
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter" />
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable" />
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField" />
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod" />
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
<!--controversial-->
<rule ref="rulesets/controversial.xml/Superglobals" />
<rule ref="rulesets/controversial.xml/CamelCaseClassName" />
<rule ref="rulesets/controversial.xml/CamelCasePropertyName" />
<rule ref="rulesets/controversial.xml/CamelCaseMethodName" />
<rule ref="rulesets/controversial.xml/CamelCaseParameterName" />
<rule ref="rulesets/controversial.xml/CamelCaseVariableName" />
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
<!--cleancode-->
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag" />
<rule ref="rulesets/cleancode.xml/ElseExpression" />
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
<rule ref="rulesets/cleancode.xml/ElseExpression" />
</ruleset>
14 changes: 10 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<phpunit bootstrap="vendor/autoload.php">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite>
<directory>./tests</directory>
<testsuite name="all">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="-1" />
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
1 change: 0 additions & 1 deletion src-deprecated/AppMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);


namespace BEAR\AppMeta;

use BEAR\AppMeta\Exception\AppNameException;
Expand Down
1 change: 0 additions & 1 deletion src/Exception/AppNameException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);


namespace BEAR\AppMeta\Exception;

class AppNameException extends \LogicException
Expand Down
1 change: 0 additions & 1 deletion src/Exception/NotWritableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);


namespace BEAR\AppMeta\Exception;

class NotWritableException extends \LogicException
Expand Down
1 change: 0 additions & 1 deletion src/ResMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);


namespace BEAR\AppMeta;

final class ResMeta
Expand Down
35 changes: 24 additions & 11 deletions tests/AppMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@
class AppMetaTest extends TestCase
{
/**
* @var AppMeta
* @var Meta
*/
protected $appMeta;

protected function setUp()
protected function setUp() : void
{
parent::setUp();
$app = dirname(__DIR__) . '/tests/Fake/fake-app/var/tmp';
file_put_contents($app . '/app/cache', '1');
chmod(__DIR__ . '/Fake/fake-not-writable/var', 0644);
$this->appMeta = new AppMeta('FakeVendor\HelloWorld', 'prod-app');
$this->appMeta = new Meta('FakeVendor\HelloWorld', 'prod-app');
}

protected function tearDown()
protected function tearDown() : void
{
chmod(__DIR__ . '/Fake/fake-not-writable/var', 0777);
}

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

public function testAppReflectorResourceList()
{
$appMeta = new AppMeta('FakeVendor\HelloWorld');
$appMeta = new Meta('FakeVendor\HelloWorld');
$classes = $files = [];
foreach ($appMeta->getResourceListGenerator() as list($class, $file)) {
$classes[] = $class;
Expand Down Expand Up @@ -67,29 +67,29 @@ public function testAppReflectorResourceList()
public function testInvalidName()
{
$this->expectException(AppNameException::class);
new AppMeta('Invalid\Invalid');
new Meta('Invalid\Invalid');
}

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

public function testVarTmpFolderCreation()
{
new AppMeta('FakeVendor\HelloWorld', 'stage-app');
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()
{
new AppMeta('FakeVendor\HelloWorld', 'test-app');
new Meta('FakeVendor\HelloWorld', 'test-app');
$this->assertFileExists(__DIR__ . '/Fake/fake-app/var/tmp/test-app/not-cleared.txt');
}

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

public function testGetGeneratorAll()
{
$appMeta = new Meta('FakeVendor\HelloWorld');
$uris = [];
foreach ($appMeta->getGenerator('*') as $uri) {
$uris[] = $uri;
}
$this->assertCount(6, $uris);
$this->assertSame('app://self/one', $uris[0]->uriPath);
$this->assertSame(One::class, $uris[0]->class);
$this->assertContains('tests/Fake/fake-app/src/Resource/App/One.php', $uris[0]->filePath);
}
}
Loading

0 comments on commit 17417a1

Please sign in to comment.