Skip to content

Commit

Permalink
Merge pull request #146 from bearsunday/update-cs
Browse files Browse the repository at this point in the history
Update CS
  • Loading branch information
koriym authored Oct 5, 2020
2 parents 57a78e5 + 2ffa4f0 commit c612ad6
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 84 deletions.
3 changes: 0 additions & 3 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
filter:
paths: ["src/*"]
tools:
external_code_coverage: true
php_code_coverage: true
php_sim: true
php_mess_detector: true
php_pdepend: true
php_analyzer: true
php_cpd: true
Expand Down
45 changes: 27 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,67 @@
language: php

dist: bionic

php:
- 7.2
- 7.3
- 7.4

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

before_install:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
- phpenv config-rm xdebug.ini || true
- composer validate
- composer self-update

install:
- composer update

script:
- ./vendor/bin/phpunit;
- php ./demo/bin/index.php

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

- stage: Test
name: PHP 8
php: nightly
install: composer update --ignore-platform-reqs

- stage: Code Quality
name: Code coverage
php: 7.2
php: 7.4
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
- pecl install pcov
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;
- ./vendor/bin/phpunit -v --coverage-clover ./build/logs/clover.xml --coverage-text
after_success:
- bash <(curl -s https://codecov.io/bash) -cF php

- stage: Code Quality
name: Static analysis
php: 7.2
install:
- composer global require --dev phpstan/phpstan ^0.12 vimeo/psalm ^3.11 psalm/plugin-phpunit ^0.10 phpmetrics/phpmetrics ^2.6;
- ~/.composer/vendor/bin/psalm-plugin enable psalm/plugin-phpunit
php: 7.4
install: composer global require --dev phpstan/phpstan ^0.12 vimeo/psalm ^3.11 phpmetrics/phpmetrics ^2.6
script:
- ~/.composer/vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction;
- ~/.composer/vendor/bin/psalm --show-info=false
- ~/.composer/vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction
- ~/.composer/vendor/bin/psalm --show-info=true --shepherd
- ~/.composer/vendor/bin/phpmetrics --exclude=Exception src

- stage: Code Quality
name: Coding standards
php: 7.2
install: composer global require --dev squizlabs/php_codesniffer ^3.5 doctrine/coding-standard ^8.1
php: 7.4
install: composer global require --dev doctrine/coding-standard ^8.1 maglnet/composer-require-checker ^2.0
script:
- ~/.composer/vendor/bin/phpcs
- ~/.composer/vendor/bin/phpcs --standard=./phpcs.xml src tests
- ~/.composer/vendor/bin/composer-require-checker check ./composer.json
allow_failures:
- php: nightly
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
codecov:
notify:
require_ci_to_pass: yes

coverage:
status:
project:
default:
target: 95%
patch:
default:
target: 95%

comment: false
36 changes: 12 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
],
"require": {
"php": ">=7.2.0",
"php": "^7.2 || ^8.0",
"ext-json": "*",
"bear/resource": "^1.14.3",
"doctrine/annotations": "^1.10",
Expand All @@ -30,7 +30,8 @@
"ray/di": "^2.10"
},
"require-dev": {
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^8.5",
"psalm/plugin-phpunit": "^0.12.2"
},
"config": {
"sort-packages": true
Expand All @@ -54,27 +55,14 @@
"tests/Fake/Provide/Transfer/http_response_code.php"
]
},
"scripts": {
"coverage": [
"php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"
],
"cs": [
"phpcs"
],
"cs-fix": [
"phpcbf"
],
"metrics": [
"phpmetrics --report-html=build/metrics/ --extensions=php src,composer.json,composer.lock"
],
"test": [
"phpunit"
],
"tests": [
"@cs",
"phpstan analyse -c phpstan.neon",
"psalm --show-info=false",
"@test"
]
"scripts" :{
"test": ["phpunit"],
"tests": ["@cs", "@sa", "@test"],
"coverage": ["php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"pcov": ["php -d pcov.enabled=1 ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"cs": ["phpcs"],
"cs-fix": ["phpcbf"],
"sa": ["phpstan analyse -c phpstan.neon", "psalm --show-info=true"],
"metrics": ["phpmetrics --report-html=build/metrics/ --extensions=php src,composer.json,composer.lock"]
}
}
9 changes: 9 additions & 0 deletions demo/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Composer\Autoload\ClassLoader;

$autoload = require dirname(__DIR__) . '/vendor/autoload.php';
assert($autoload instanceof ClassLoader);
$autoload->addPsr4('MyVendor\HelloWorld\\', __DIR__ . '/src');
10 changes: 5 additions & 5 deletions demo/bin/index.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php

declare(strict_types=1);
use BEAR\Resource\ResourceObject;

use BEAR\Sunday\Extension\Application\AppInterface;
use MyVendor\HelloWorld\App;
use MyVendor\HelloWorld\AppModule;
use Ray\Di\Injector;

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

$app = (new Injector(new AppModule))->getInstance(AppInterface::class);
$app = (new Injector(new AppModule()))->getInstance(AppInterface::class);
assert($app instanceof App);
try {
$response = $app->resource->get('page://self/index', ['name' => 'BEAR.Sunday']);
assert($response instanceof ResourceObject);
/** @var array<string, string> $_SERVER */
$response->transfer($app->responder, $_SERVER);
} catch (\Exception $e) {
} catch (Throwable $e) {
error_log((string) $e);
exit(1);
}
13 changes: 10 additions & 3 deletions demo/public/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php

/**
* @psalm-import-type Globals from \BEAR\Sunday\Extension\Router\RouterInterface
* @psalm-import-type Server from \BEAR\Sunday\Extension\Router\RouterInterface
*/

declare(strict_types=1);

use BEAR\Resource\Exception\BadRequestException;
use BEAR\Resource\Exception\ResourceNotFoundException;
use BEAR\Resource\ResourceObject;
Expand All @@ -9,9 +15,10 @@
use MyVendor\HelloWorld\AppModule;
use Ray\Di\Injector;

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


$app = (new Injector(new AppModule))->getInstance(AppInterface::class);
$app = (new Injector(new AppModule()))->getInstance(AppInterface::class);
assert($app instanceof App);

$request = $app->router->match($GLOBALS, $_SERVER);
Expand All @@ -25,7 +32,7 @@
} catch (BadRequestException $e) {
http_response_code(400);
echo 'Bad request' . PHP_EOL;
} catch (\Exception $e) {
} catch (Throwable $e) {
http_response_code(500);
echo 'Server error' . PHP_EOL;
error_log((string) $e);
Expand Down
4 changes: 2 additions & 2 deletions demo/src/AppModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

class AppModule extends AbstractModule
{
protected function configure() : void
protected function configure(): void
{
$this->bind()->annotatedWith(AppName::class)->toInstance(__NAMESPACE__);
$this->bind(AppInterface::class)->to(App::class);
$this->install(new SundayModule);
$this->install(new SundayModule());
}
}
8 changes: 6 additions & 2 deletions demo/src/Resource/Page/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

class Index extends ResourceObject
{
public function onGet(string $name = 'World') : ResourceObject
/** @var array{greeting: string} */
public $body;

/** @return static */
public function onGet(string $name = 'World'): ResourceObject
{
$this->body = [
'greeting' => 'Hello ' . $name
'greeting' => 'Hello ' . $name,
];

return $this;
Expand Down
17 changes: 8 additions & 9 deletions demo/tests/Resource/Page/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,29 @@

class IndexTest extends TestCase
{
/**
* @var ResourceInterface
*/
/** @var ResourceInterface */
private $resource;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->resource = (new Injector(new AppModule))->getInstance(ResourceInterface::class);
/** @var ResourceInterface $this->resource */
$this->resource = (new Injector(new AppModule()))->getInstance(ResourceInterface::class);
}

public function testInstance()
public function testInstance(): void
{
$page = $this->resource->newInstance('page://self/');
$this->assertInstanceOf(Index::class, $page);
}

public function testGet()
public function testGet(): void
{
$page = $this->resource->uri('page://self/')();
$this->assertInstanceOf(Index::class, $page);
/* @var $page Index */
/** @var Index $page */
$this->assertSame(200, $page->code);
$this->assertSame('Hello World', $page->body['greeting']);
$this->assertSame('Hello World', (string) $page->body['greeting']);
$expectJson = '{
"greeting": "Hello World"
}
Expand Down
42 changes: 28 additions & 14 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0"?>
<ruleset
name ="BEAR.Sunday"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
>
<description>The BEAR.Sunday coding standard</description>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="bearcs"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>

<!-- Compatibility with PHP 7.2.0 -->
<config name="php_version" value="70200"/>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>
Expand All @@ -24,32 +24,46 @@

<!-- Doctrine Coding Standard -->
<rule ref="Doctrine">

<!-- Inapplicable for this project -->
<!-- Inapplicable for this project -->
<!-- Base -->
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSame"/>
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable"/>
<exclude name="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException"/>

<!-- Directories not to be checked -->
<!-- /Base -->
<!-- Option -->
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>
<!-- /Option -->
<!-- Exclude Fake files form Doctrine CS -->
<exclude-pattern>*/tests/Fake/*</exclude-pattern>
</rule>
<!-- Require specific order of phpDoc annotations with empty newline between specific groups -->

<!-- Additional Rules -->
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
<properties>
<property name="annotationsGroups" type="array">
<element value="@param, @psalm-param, @phpstan-param"/>
<element value="@return, @psalm-return, @phpstan-return"/>
<element value="@Inject, @Named"/>
<element value="@throws"/>
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<include-pattern>tests/*</include-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing">
<properties>
<property name="minLinesCountBeforeWithComment" value="1"/>
<property name="maxLinesCountBeforeWithComment" value="1"/>
<property name="maxLinesCountBeforeWithoutComment" value="0"/>
</properties>
</rule>
<exclude-pattern>*/Fake/*</exclude-pattern>
<exclude-pattern>*/tmp/*</exclude-pattern>
</ruleset>
Loading

0 comments on commit c612ad6

Please sign in to comment.