Skip to content

Commit

Permalink
Merge pull request #145 from bearsunday/update-cs
Browse files Browse the repository at this point in the history
Update CS
  • Loading branch information
koriym authored Jul 11, 2020
2 parents 13cbef1 + 0df262a commit 57a78e5
Show file tree
Hide file tree
Showing 50 changed files with 244 additions and 271 deletions.
1 change: 1 addition & 0 deletions .phpcs-cache

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jobs:
name: Static analysis
php: 7.2
install:
- composer global require --dev phpstan/phpstan ^0.12 vimeo/psalm ^3.11 phpmetrics/phpmetrics ^2.6;
- 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
script:
- ~/.composer/vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction;
- ~/.composer/vendor/bin/psalm --show-info=false
Expand All @@ -52,6 +53,6 @@ jobs:
- stage: Code Quality
name: Coding standards
php: 7.2
install: composer global require --dev friendsofphp/php-cs-fixer ^2.0;
install: composer global require --dev squizlabs/php_codesniffer ^3.5 doctrine/coding-standard ^8.1
script:
- ~/.composer/vendor/bin/php-cs-fixer --dry-run -v fix;
- ~/.composer/vendor/bin/phpcs
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@
"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"
"phpcs"
],
"cs-fix": [
"php-cs-fixer fix -v",
"phpcbf src"
"phpcbf"
],
"metrics": [
"phpmetrics --report-html=build/metrics/ --extensions=php src,composer.json,composer.lock"
Expand Down
68 changes: 52 additions & 16 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
<?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"/>
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength"/>
<?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>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>

<!-- Directories to be checked -->
<file>src</file>
<file>tests</file>
<exclude-pattern>*/tests/tmp/*</exclude-pattern>

<!-- PSR12 Coding Standard -->
<rule ref="PSR12"/>

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

<!-- Inapplicable for this project -->
<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.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 -->
<exclude-pattern>*/tests/Fake/*</exclude-pattern>
</rule>
<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"/>

<!-- Require specific order of phpDoc annotations with empty newline between specific groups -->
<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>
</ruleset>
4 changes: 1 addition & 3 deletions src/Annotation/DefaultSchemeHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
final class DefaultSchemeHost
{
/**
* @var string
*/
/** @var string */
public $value;
}
20 changes: 5 additions & 15 deletions src/Extension/Application/AbstractApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,19 @@

class AbstractApp implements AppInterface
{
/**
* @var HttpCacheInterface
*/
/** @var HttpCacheInterface */
public $httpCache;

/**
* @var RouterInterface
*/
/** @var RouterInterface */
public $router;

/**
* @var TransferInterface
*/
/** @var TransferInterface */
public $responder;

/**
* @var ResourceInterface
*/
/** @var ResourceInterface */
public $resource;

/**
* @var ErrorInterface
*/
/** @var ErrorInterface */
public $error;

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Extension/Error/NullError.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public function handle(Exception $e, Request $request)
return $this;
}

/**
* {@inheritdoc}
*/
public function transfer() : void
public function transfer(): void
{
}
}
4 changes: 2 additions & 2 deletions src/Extension/Error/ThrowableHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ interface ThrowableHandlerInterface
/**
* Handle Throwable
*/
public function handle(Throwable $e, Request $request) : self;
public function handle(Throwable $e, Request $request): self;

/**
* Transfer error page
*/
public function transfer() : void;
public function transfer(): void;
}
2 changes: 1 addition & 1 deletion src/Extension/Router/RouterMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RouterMatch
*/
public $query = [];

public function __toString()
public function __toString(): string
{
$querySymbol = $this->query ? '?' : '';

Expand Down
6 changes: 3 additions & 3 deletions src/Extension/Transfer/HttpCacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ interface HttpCacheInterface
* Indicates that a conditional GET or HEAD request has been received and would have resulted in a 200
* (OK) response if it were not for the fact that the condition evaluated to false.
*
* @https://tools.ietf.org/html/rfc7232#section-4.1
*
* @param array{HTTP_IF_NONE_MATCH?: string} $server
*
* @https://tools.ietf.org/html/rfc7232#section-4.1
*/
public function isNotModified(array $server) : bool;
public function isNotModified(array $server): bool;

/**
* Transfer status code 304 to the client
Expand Down
7 changes: 2 additions & 5 deletions src/Extension/Transfer/NullHttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ final class NullHttpCache implements HttpCacheInterface
/**
* {@inheritdoc}
*/
public function isNotModified(array $server) : bool
public function isNotModified(array $server): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function transfer() : void
public function transfer(): void
{
}
}
2 changes: 1 addition & 1 deletion src/Extension/Transfer/NullTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class NullTransfer implements TransferInterface
/**
* {@inheritdoc}
*/
public function __invoke(ResourceObject $ro, array $server) : void
public function __invoke(ResourceObject $ro, array $server): void
{
}
}
4 changes: 1 addition & 3 deletions src/Inject/PsrLoggerInject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

trait PsrLoggerInject
{
/**
* @var LoggerInterface
*/
/** @var LoggerInterface */
private $logger;

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Inject/ResourceInject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

trait ResourceInject
{
/**
* @var ResourceInterface
*/
/** @var ResourceInterface */
protected $resource;

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Module/Annotation/DoctrineAnnotationModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

class DoctrineAnnotationModule extends AbstractModule
{
/**
* {@inheritdoc}
*/
protected function configure() : void
protected function configure(): void
{
$this->bind(Cache::class)->annotatedWith('annotation_cache')->to(ArrayCache::class)->in(Scope::SINGLETON);
$this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class)->in(Scope::SINGLETON);
Expand Down
5 changes: 1 addition & 4 deletions src/Module/Cache/DoctrineCacheModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

class DoctrineCacheModule extends AbstractModule
{
/**
* {@inheritdoc}
*/
protected function configure() : void
protected function configure(): void
{
$this->bind(Cache::class)->to(ArrayCache::class)->in(Scope::SINGLETON);
}
Expand Down
9 changes: 2 additions & 7 deletions src/Module/Constant/NamedModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class NamedModule extends AbstractModule
{
/**
* @var array<string, string>
*/
/** @var array<string, string> */
private $names;

/**
Expand All @@ -22,10 +20,7 @@ public function __construct(array $names)
parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure() : void
protected function configure(): void
{
foreach ($this->names as $annotatedWith => $instance) {
$this->bind()->annotatedWith($annotatedWith)->toInstance($instance);
Expand Down
19 changes: 8 additions & 11 deletions src/Module/SundayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@

class SundayModule extends AbstractModule
{
/**
* {@inheritdoc}
*/
protected function configure() : void
protected function configure(): void
{
$this->install(new AppModule);
$this->install(new HttpCacheModule);
$this->install(new DoctrineCacheModule);
$this->install(new DoctrineAnnotationModule);
$this->install(new AppModule());
$this->install(new HttpCacheModule());
$this->install(new DoctrineCacheModule());
$this->install(new DoctrineAnnotationModule());
$this->install(new ResourceModule('BEAR\Sunday'));
$this->install(new RouterModule);
$this->install(new HttpResponderModule);
$this->install(new ErrorModule);
$this->install(new RouterModule());
$this->install(new HttpResponderModule());
$this->install(new ErrorModule());
}
}
5 changes: 1 addition & 4 deletions src/Provide/Application/AppModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

class AppModule extends AbstractModule
{
/**
* {@inheritdoc}
*/
protected function configure() : void
protected function configure(): void
{
$this->bind(AppInterface::class)->to(App::class);
$this->bind()->annotatedWith(AppName::class)->toInstance('BEAR\Sunday');
Expand Down
5 changes: 1 addition & 4 deletions src/Provide/Error/ErrorModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

class ErrorModule extends AbstractModule
{
/**
* {@inheritdoc}
*/
protected function configure() : void
protected function configure(): void
{
$this->bind(ErrorInterface::class)->to(VndError::class);
$this->bind(ThrowableHandlerInterface::class)->to(ThrowableHandler::class);
Expand Down
13 changes: 7 additions & 6 deletions src/Provide/Error/ThrowableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@
use BEAR\Sunday\Extension\Error\ErrorInterface;
use BEAR\Sunday\Extension\Error\ThrowableHandlerInterface;
use BEAR\Sunday\Extension\Router\RouterMatch as Request;
use const E_ERROR;
use Error;
use ErrorException;
use Exception;
use Throwable;

use function assert;

use const E_ERROR;

final class ThrowableHandler implements ThrowableHandlerInterface
{
/**
* @var ErrorInterface
*/
/** @var ErrorInterface */
private $error;

public function __construct(ErrorInterface $error)
{
$this->error = $error;
}

public function handle(Throwable $e, Request $request) : ThrowableHandlerInterface
public function handle(Throwable $e, Request $request): ThrowableHandlerInterface
{
$e = $e instanceof Error ? new ErrorException($e->getMessage(), (int) $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()) : $e;
assert($e instanceof Exception);
Expand All @@ -34,7 +35,7 @@ public function handle(Throwable $e, Request $request) : ThrowableHandlerInterfa
return $this;
}

public function transfer() : void
public function transfer(): void
{
$this->error->transfer();
}
Expand Down
Loading

0 comments on commit 57a78e5

Please sign in to comment.