Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
refactor(phpstan): Enable "inferPrivatePropertyTypeFromConstructor" p…
Browse files Browse the repository at this point in the history
…arameter

- Fix issues found by phpstan after enabling "inferPrivatePropertyTypeFromConstructor" parameter
- Upgrade dependencies
  • Loading branch information
k911 committed Oct 27, 2019
1 parent 0ee8918 commit 3436fd9
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 44 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"php tests/Fixtures/Symfony/app/console --ansi"
],
"static-analyse-src": [
"phpstan analyze src -l 7 --ansi"
"phpstan analyze src -l 7 -c phpstan.neon.dist --ansi"
],
"static-analyse-tests": [
"phpstan analyze tests -l 4 -c phpstan.tests.neon --ansi"
Expand All @@ -84,9 +84,7 @@
],
"analyse": [
"@static-analyse-src",
"",
"@static-analyse-tests",
"",
"@cs-analyse"
],
"test": [
Expand Down
58 changes: 32 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
inferPrivatePropertyTypeFromConstructor: true
excludes_analyse:
- src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
ignoreErrors:
# Put false positives here
- '#Parameter \#2 \$callback of method Swoole\\Server::on\(\) expects callable\(\): mixed, array\(mixed, .{1}handle.{1}\) given#'
1 change: 1 addition & 0 deletions phpstan.tests.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
inferPrivatePropertyTypeFromConstructor: true
excludes_analyse:
- tests/Fixtures/Symfony/app/var
- tests/Fixtures/Symfony/app/TestAppKernel
Expand Down
6 changes: 5 additions & 1 deletion src/Bridge/Symfony/Bundle/Command/ServerReloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace K911\Swoole\Bridge\Symfony\Bundle\Command;

use Assert\Assertion;
use K911\Swoole\Server\HttpServer;
use K911\Swoole\Server\HttpServerConfiguration;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -51,7 +52,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$this->serverConfiguration->daemonize($input->getOption('pid-file'));
$pidFile = $input->getOption('pid-file');
Assertion::nullOrString($pidFile);

$this->serverConfiguration->daemonize($pidFile);

try {
$this->server->reload();
Expand Down
6 changes: 5 additions & 1 deletion src/Bridge/Symfony/Bundle/Command/ServerStopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace K911\Swoole\Bridge\Symfony\Bundle\Command;

use Assert\Assertion;
use K911\Swoole\Server\HttpServer;
use K911\Swoole\Server\HttpServerConfiguration;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -51,7 +52,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$this->serverConfiguration->daemonize($input->getOption('pid-file'));
$pidFile = $input->getOption('pid-file');
Assertion::nullOrString($pidFile);

$this->serverConfiguration->daemonize($pidFile);

try {
$this->server->shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ public function __construct(TreeBuilder $builder)
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$rootNode = \method_exists($this->builder, 'getRootNode') ?
$this->builder->getRootNode() :
$this->builder->root(self::CONFIG_NAME);

$rootNode
$this->builder->getRootNode()
->children()
->arrayNode('http_server')
->addDefaultsIfNotSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function make(SwooleRequest $request): HttpFoundationRequest
{
$httpFoundationRequest = $this->decorated->make($request);
if ($httpFoundationRequest->headers->has('cloudfront_forwarded_proto')) {
$httpFoundationRequest->headers->set('x_forwarded_proto', $httpFoundationRequest->headers->get('cloudfront_forwarded_proto'));
/** @var string|string[] $cloudFrontForwardedProto */
$cloudFrontForwardedProto = $httpFoundationRequest->headers->get('cloudfront_forwarded_proto');
$httpFoundationRequest->headers->set('x_forwarded_proto', $cloudFrontForwardedProto);
}

return $httpFoundationRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Swoole\Http\Response;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Stopwatch\Stopwatch;

final class DebugHttpKernelRequestHandler implements RequestHandlerInterface
{
Expand Down Expand Up @@ -37,10 +39,13 @@ public function handle(Request $request, Response $response): void

if ($this->kernel->isDebug()) {
if ($this->container->has('debug.stopwatch')) {
$this->container->get('debug.stopwatch')->reset();
/** @var Stopwatch $stopwatch */
$stopwatch = $this->container->get('debug.stopwatch');
$stopwatch->reset();
}

if ($this->container->has('profiler')) {
/** @var Profiler $profiler */
$profiler = $this->container->get('profiler');
$profiler->reset();
$profiler->enable();
Expand Down
8 changes: 4 additions & 4 deletions src/Server/HttpServerConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function servingStaticContent(): bool

public function hasPublicDir(): bool
{
return isset($this->settings[self::SWOOLE_HTTP_SERVER_CONFIG_PUBLIC_DIR]);
return !empty($this->settings[self::SWOOLE_HTTP_SERVER_CONFIG_PUBLIC_DIR]);
}

/**
Expand Down Expand Up @@ -203,11 +203,11 @@ public function getServerSocket(): Socket
/**
* @throws \Assert\AssertionFailedException
*
* @return null|string
* @return string
*/
public function getPublicDir(): ?string
public function getPublicDir(): string
{
Assertion::keyIsset($this->settings, self::SWOOLE_HTTP_SERVER_CONFIG_PUBLIC_DIR, 'Setting "%s" is not set.');
Assertion::true($this->hasPublicDir(), \sprintf('Setting "%s" is not set or empty.', self::SWOOLE_HTTP_SERVER_CONFIG_PUBLIC_DIR));

return $this->settings[self::SWOOLE_HTTP_SERVER_CONFIG_PUBLIC_DIR];
}
Expand Down
6 changes: 5 additions & 1 deletion src/Server/RequestHandler/AdvancedStaticFilesServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ final class AdvancedStaticFilesServer implements RequestHandlerInterface, Bootab
];

private $decorated;
private $cachedMimeTypes;
private $configuration;

/**
* @var array<string,string>
*/
private $cachedMimeTypes;

/**
* @var string
*/
Expand Down

0 comments on commit 3436fd9

Please sign in to comment.