Skip to content

Commit

Permalink
Merge pull request bearsunday#112 from koriym/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
koriym committed Mar 14, 2018
2 parents b732d0b + 3f14240 commit 2743386
Show file tree
Hide file tree
Showing 60 changed files with 241 additions and 156 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cache.properties
composer.phar
composer.lock
.DS_Store
.php_cs.cache
5 changes: 2 additions & 3 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ return \PhpCsFixer\Config::create()
'combine_consecutive_unsets' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => true,
'declare_strict_types' => false,
'declare_strict_types' => true,
'dir_constant' => true,
'ereg_to_preg' => true,
'function_typehint_space' => true,
Expand Down Expand Up @@ -127,5 +127,4 @@ return \PhpCsFixer\Config::create()
->exclude('tests/Fake')
->exclude('doc')
->in(__DIR__)
)->setLineEnding("\n")
->setUsingCache(false);
)->setLineEnding("\n");
18 changes: 11 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: php
sudo: required
dist: trusty
sudo: false
php:
- 7.0
- 7
- 7.1
- 7.2
cache:
Expand All @@ -16,9 +15,14 @@ env:
before_script:
- composer self-update
- composer update $DEPENDENCIES
- composer update --working-dir=demo
- if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then COVERAGE="--coverage-clover=coverage.clover"; else phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then composer require --dev phpstan/phpstan-shim friendsofphp/php-cs-fixer; fi
script:
- ./vendor/bin/phpunit --coverage-clover=coverage.clover;
- if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.4.0/php-cs-fixer.phar && php php-cs-fixer.phar fix --config=.php_cs -v --dry-run --using-cache=no --path-mode=intersection `git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE`; fi

- ./vendor/bin/phpunit $COVERAGE;
- if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; 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' ]]; then ./vendor/bin/phpstan analyse -l max -c phpstan.neon src tests --no-progress --no-interaction; fi
- php demo/bin/index.php
- ./demo/vendor/bin/phpunit --configuration demo/phpunit.xml.dist
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
- 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
97 changes: 44 additions & 53 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,50 @@
{
"name": "bear/sunday",
"description": "A resource-oriented application framework",
"keywords": [
"framework",
"DI",
"AOP",
"REST",
"Hypermedia"
],
"license": "MIT",
"authors": [
{
"name": "Akihito Koriyama",
"email": "akihito.koriyama@gmail.com",
"homepage": "https://github.com/koriym"
},
{
"name": "BEAR.Sunday Contributors",
"homepage": "http://bearsunday.github.io/contributors.html"
}
],
"require": {
"php": ">=7.0.0",
"bear/resource": "^1.6",
"psr/log": "^1.0.2"
},
"name": "bear/sunday",
"description": "A resource-oriented application framework",
"keywords": [
"framework",
"DI",
"AOP",
"REST",
"Hypermedia"
],
"license": "MIT",
"authors": [
{
"name": "Akihito Koriyama",
"email": "akihito.koriyama@gmail.com",
"homepage": "http://koriym.github.io/about/"
},
{
"name": "BEAR.Sunday Contributors",
"homepage": "http://bearsunday.github.io/contributors.html"
}
],
"require": {
"php": ">=7.0.0",
"bear/resource": "^1.9.2",
"psr/log": "^1.0.2"
},
"require-dev": {
"phpunit/phpunit": "^6.2"
"phpunit/phpunit": "^6.2"
},
"autoload": {
"psr-4": {
"psr-4": {
"BEAR\\Sunday\\": "src/"
},
"exclude-from-classmap": ["/example/", "/tests/"]
},
"autoload-dev": {
"files": ["tests/functions.php"]
},
"scripts" :{
"test": [
"phpmd src text ./phpmd.xml",
"phpcs src tests",
"phpunit"
],
"cs-fix": [
"php-cs-fixer fix --config-file=./.php_cs",
"phpcbf src"
],
"build": [
"rm -rf ./build; mkdir -p ./build/logs ./build/pdepend ./build/api",
"pdepend --jdepend-xml=./build/logs/jdepend.xml --jdepend-chart=./build/pdepend/dependencies.svg --overview-pyramid=./build/pdepend/overview-pyramid.svg src",
"phploc --log-csv ./build/logs/phploc.csv src",
"phpcs --report=checkstyle --report-file=./build/logs/checkstyle.xml --standard=phpcs.xml src",
"apigen generate -s src -d build/api",
"@test"
]
}
}
},
"autoload-dev": {
"psr-4": {
"BEAR\\Sunday\\": ["tests/", "tests/Fake/"],
"FakeVendor\\HelloWorld\\": "tests/Fake/Apps/FakeVendor/HelloWorld/",
"FakeVendor\\HelloWorldX\\": "tests/Fake/Apps/FakeVendor/HelloWorldX/"
},
"files": ["tests/functions.php"]
},
"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"]
}
}
File renamed without changes.
7 changes: 3 additions & 4 deletions example/bin/index.php → demo/bin/index.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
use BEAR\Sunday\Extension\Application\AppInterface;
use Doctrine\Common\Annotations\AnnotationRegistry;
use MyVendor\HelloWorld\AppModule;
use Ray\Di\Injector;

require dirname(__DIR__) . '/vendor/autoload.php';
AnnotationRegistry::registerLoader('class_exists');

$app = (new Injector(new AppModule))->getInstance(AppInterface::class);
try {
$page = $app
->resource
$page = $app->resource
->get
->uri('page://self/index')(['name' => 'BEAR.Sunday'])
->transfer($app->responder, $_SERVER);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion example/phpunit.xml.dist → demo/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<phpunit bootstrap="tests/bootstrap.php">
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite>
<directory suffix="Test.php">tests</directory>
Expand Down
70 changes: 70 additions & 0 deletions demo/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
use BEAR\Resource\Exception\BadRequestException;
use BEAR\Resource\Exception\ResourceNotFoundException;
use BEAR\Sunday\Extension\Application\AbstractApp;
use BEAR\Sunday\Extension\Application\AppInterface;
use MyVendor\HelloWorld\AppModule;
use Ray\Di\Injector;

require dirname(__DIR__) . '/vendor/autoload.php';

$app = (new Injector(new AppModule))->getInstance(AppInterface::class);
/* @var $app AbstractApp */
$request = $app->router->match($GLOBALS, $_SERVER);
try {
$page = $app
->resource
->{$request->method}
->uri($request->path)($request->query)
->transfer($app->responder, $_SERVER);
} catch (ResourceNotFoundException $e) {
http_response_code(404);
echo 'Not found' . PHP_EOL;
} catch (BadRequestException $e) {
http_response_code(400);
echo 'Bad request' . PHP_EOL;
} catch (\Exception $e) {
http_response_code(500);
echo 'Server error' . PHP_EOL;
error_log($e);
exit(1);
}

// php -S 127.0.0.1:8088 index.php

//$ curl -i -X DELETE http://127.0.0.1:8088/
//HTTP/1.1 400 Bad Request
//Host: 127.0.0.1:8088
//Date: Wed, 14 Mar 2018 01:10:39 +0100
//Connection: close
//X-Powered-By: PHP/7.1.10
//Content-type: text/html; charset=UTF-8
//
//Bad request

//$ curl -i -X GET http://127.0.0.1:8088/abc
//HTTP/1.1 404 Not Found
//Host: 127.0.0.1:8088
//Date: Wed, 14 Mar 2018 01:09:00 +0100
//Connection: close
//Content-type: text/html; charset=UTF-8
//
//Not found

//$ curl -i -X GET http://127.0.0.1:8088/
//HTTP/1.1 200 OK
//Host: 127.0.0.1:8088
//Date: Wed, 14 Mar 2018 01:10:01 +0100
//Connection: close
//content-type: application/json
//
//{
// "greeting": "Hello World"
//}
2 changes: 2 additions & 0 deletions example/src/App.php → demo/src/App.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
2 changes: 2 additions & 0 deletions example/src/AppModule.php → demo/src/AppModule.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
28 changes: 0 additions & 28 deletions example/public/index.php

This file was deleted.

10 changes: 0 additions & 10 deletions example/tests/bootstrap.php

This file was deleted.

Empty file added phpstan.neon
Empty file.
15 changes: 4 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
<phpunit bootstrap="tests/bootstrap.php">
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite>
<directory suffix="Test.php">tests</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>

<logging>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 2 additions & 0 deletions src/Annotation/DefaultSchemeHost.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/LogicException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Extension/Application/AbstractApp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Extension/Application/AppInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Extension/Error/ErrorInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the BEAR.Sunday package.
*
Expand Down
Loading

0 comments on commit 2743386

Please sign in to comment.