Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ApplicationFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon;

use PHPFastCGI\FastCGIDaemon\Command\DaemonRunCommand;
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainer;
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;

/**
* The default implementation of the ApplicationFactoryInterface.
Expand All @@ -30,7 +33,7 @@ public function __construct(DriverContainerInterface $driverContainer = null)
/**
* {@inheritdoc}
*/
public function createApplication($kernel, $commandName = null, $commandDescription = null)
public function createApplication($kernel, string $commandName = null, string $commandDescription = null): Application
{
$command = $this->createCommand($kernel, $commandName, $commandDescription);

Expand All @@ -43,7 +46,7 @@ public function createApplication($kernel, $commandName = null, $commandDescript
/**
* {@inheritdoc}
*/
public function createCommand($kernel, $commandName = null, $commandDescription = null)
public function createCommand($kernel, string $commandName = null, string $commandDescription = null): Command
{
$kernelObject = $this->getKernelObject($kernel);

Expand All @@ -60,7 +63,7 @@ public function createCommand($kernel, $commandName = null, $commandDescription
*
* @return KernelInterface The kernel as an object implementing the KernelInterface
*/
private function getKernelObject($kernel)
private function getKernelObject($kernel): KernelInterface
{
if ($kernel instanceof KernelInterface) {
return $kernel;
Expand Down
6 changes: 4 additions & 2 deletions src/ApplicationFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon;

use Symfony\Component\Console\Application;
Expand All @@ -20,7 +22,7 @@ interface ApplicationFactoryInterface
*
* @return Application The Symfony console application
*/
public function createApplication($kernel, $commandName = null, $commandDescription = null);
public function createApplication($kernel, string $commandName = null, string $commandDescription = null): Application;

/**
* Create a Symfony console command.
Expand All @@ -31,5 +33,5 @@ public function createApplication($kernel, $commandName = null, $commandDescript
*
* @return Command The Symfony console command
*/
public function createCommand($kernel, $commandName = null, $commandDescription = null);
public function createCommand($kernel, string $commandName = null, string $commandDescription = null): Command;
}
4 changes: 3 additions & 1 deletion src/CallbackKernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon;

use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
Expand All @@ -22,7 +24,7 @@ final class CallbackKernel implements KernelInterface
*
* @throws \InvalidArgumentException When not given callable callback
*/
public function __construct($handler)
public function __construct(callable $handler)
{
if (!is_callable($handler)) {
throw new \InvalidArgumentException('Handler callback is not callable');
Expand Down
7 changes: 5 additions & 2 deletions src/Command/DaemonRunCommand.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon\Command;

use PHPFastCGI\FastCGIDaemon\DaemonInterface;
use PHPFastCGI\FastCGIDaemon\DaemonOptions;
use PHPFastCGI\FastCGIDaemon\DaemonOptionsInterface;
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainerInterface;
use PHPFastCGI\FastCGIDaemon\KernelInterface;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -70,9 +73,9 @@ public function __construct(KernelInterface $kernel, DriverContainerInterface $d
* @param InputInterface $input The Symfony command input
* @param OutputInterface $output The Symfony command output
*
* @return DaemonOptions The daemon configuration
* @return DaemonOptionsInterface The daemon configuration
*/
private function getDaemonOptions(InputInterface $input, OutputInterface $output)
private function getDaemonOptions(InputInterface $input, OutputInterface $output): DaemonOptionsInterface
{
$logger = new ConsoleLogger($output);

Expand Down
6 changes: 4 additions & 2 deletions src/DaemonFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon;

/**
Expand All @@ -18,7 +20,7 @@ interface DaemonFactoryInterface
*
* @return DaemonInterface The FastCGI daemon
*/
public function createDaemon(KernelInterface $kernel, DaemonOptions $options, $fd = DaemonInterface::FCGI_LISTENSOCK_FILENO);
public function createDaemon(KernelInterface $kernel, DaemonOptions $options, int $fd = DaemonInterface::FCGI_LISTENSOCK_FILENO): DaemonInterface;

/**
* Create a FastCGI daemon listening on a given address. The default host is
Expand All @@ -31,5 +33,5 @@ public function createDaemon(KernelInterface $kernel, DaemonOptions $options, $f
*
* @return DaemonInterface The FastCGI daemon
*/
public function createTcpDaemon(KernelInterface $kernel, DaemonOptions $options, $host, $port);
public function createTcpDaemon(KernelInterface $kernel, DaemonOptions $options, string $host, int $port): DaemonInterface;
}
8 changes: 5 additions & 3 deletions src/DaemonInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon;

/**
Expand Down Expand Up @@ -46,13 +48,13 @@ interface DaemonInterface
*
* @throws \Exception On fatal error
*/
public function run();
public function run(): void;

/**
* Flag the daemon for shutting down. This will stop it from accepting
* requests.
*
*
* @param string|null Optional message.
*/
public function flagShutdown($message = null);
public function flagShutdown(string $message = null): void;
}
8 changes: 5 additions & 3 deletions src/DaemonOptions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon;

use Psr\Log\LoggerInterface;
Expand All @@ -19,13 +21,13 @@ final class DaemonOptions implements DaemonOptionsInterface
* Constructor.
*
* The value of the LOGGER option must implement the PSR-3 LoggerInterface.
*
*
* For the REQUEST_LIMIT, MEMORY_LIMIT and TIME_LIMIT options, NO_LIMIT can
* be used to specify that these metrics should not cause the daemon to
* shutdown.
*
* @param array $options The options to configure the daemon with
*
*
* @throws \InvalidArgumentException On unrecognised option
*/
public function __construct(array $options = [])
Expand All @@ -52,7 +54,7 @@ public function __construct(array $options = [])
}
}

public function getOption($option)
public function getOption(string $option)
{
if (!isset($this->options[$option])) {
throw new \InvalidArgumentException('Unknown option: '.$option);
Expand Down
4 changes: 3 additions & 1 deletion src/DaemonOptionsInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon;

interface DaemonOptionsInterface
Expand All @@ -22,5 +24,5 @@ interface DaemonOptionsInterface
*
* @throws \InvalidArgumentException On unrecognised option
*/
public function getOption($option);
public function getOption(string $option);
}
16 changes: 9 additions & 7 deletions src/DaemonTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon;

use PHPFastCGI\FastCGIDaemon\Exception\ShutdownException;
Expand Down Expand Up @@ -38,10 +40,10 @@ trait DaemonTrait

/**
* Flags the daemon for shutting down.
*
*
* @param string $message Optional shutdown message
*/
public function flagShutdown($message = null)
public function flagShutdown(string $message = null): void
{
$this->isShutdown = true;
$this->shutdownMessage = (null === $message ? 'Daemon flagged for shutdown' : $message);
Expand All @@ -51,9 +53,9 @@ public function flagShutdown($message = null)
* Loads to configuration from the daemon options and installs signal
* handlers.
*
* @param DaemonOptions $daemonOptions
* @param DaemonOptionsInterface $daemonOptions
*/
private function setupDaemon(DaemonOptions $daemonOptions)
private function setupDaemon(DaemonOptionsInterface $daemonOptions): void
{
$this->requestCount = 0;
$this->requestLimit = $daemonOptions->getOption(DaemonOptions::REQUEST_LIMIT);
Expand All @@ -74,7 +76,7 @@ private function setupDaemon(DaemonOptions $daemonOptions)
*
* @param int[] $statusCodes The status codes of sent responses
*/
private function considerStatusCodes($statusCodes)
private function considerStatusCodes(array $statusCodes): void
{
$this->requestCount += count($statusCodes);

Expand All @@ -94,7 +96,7 @@ private function considerStatusCodes($statusCodes)
*
* @throws ShutdownException On receiving a SIGINT or SIGALRM
*/
private function installSignalHandlers()
private function installSignalHandlers(): void
{
declare (ticks = 1);

Expand All @@ -114,7 +116,7 @@ private function installSignalHandlers()
*
* @throws ShutdownException When limits in the daemon options are exceeded
*/
private function checkDaemonLimits()
private function checkDaemonLimits(): void
{
if ($this->isShutdown) {
throw new ShutdownException($this->shutdownMessage);
Expand Down
6 changes: 5 additions & 1 deletion src/Driver/DriverContainer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon\Driver;

use PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface;

final class DriverContainer implements DriverContainerInterface
{
/**
Expand All @@ -25,7 +29,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function getFactory($driver)
public function getFactory(string $driver): DaemonFactoryInterface
{
if (!isset($this->drivers[$driver])) {
throw new \InvalidArgumentException('Unknown driver: '.$driver);
Expand Down
4 changes: 3 additions & 1 deletion src/Driver/DriverContainerInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon\Driver;

use PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface;
Expand All @@ -13,5 +15,5 @@ interface DriverContainerInterface
*
* @return DaemonFactoryInterface The daemon factory for the driver
*/
public function getFactory($driver);
public function getFactory(string $driver): DaemonFactoryInterface;
}
10 changes: 6 additions & 4 deletions src/Driver/Userland/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon\Driver\Userland\Connection;

use PHPFastCGI\FastCGIDaemon\Driver\Userland\Exception\ConnectionException;
Expand All @@ -19,7 +21,7 @@ interface ConnectionInterface
*
* @throws ConnectionException On failure
*/
public function read($length);
public function read(int $length): string;

/**
* Write data to the connection.
Expand All @@ -28,17 +30,17 @@ public function read($length);
*
* @throws ConnectionException On failure
*/
public function write($buffer);
public function write(string $buffer): void;

/**
* Tests to see if the connection has been closed.
*
* @return bool True if the connection has been closed, false otherwise
*/
public function isClosed();
public function isClosed(): bool;

/**
* Closes the connection it from the pool.
*/
public function close();
public function close(): void;
}
12 changes: 7 additions & 5 deletions src/Driver/Userland/Connection/ConnectionPoolInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PHPFastCGI\FastCGIDaemon\Driver\Userland\Connection;

/**
Expand All @@ -19,25 +21,25 @@ interface ConnectionPoolInterface
* @param int $timeout Upper bound on the amount of time to wair for readable connections
*
* @return ConnectionInterface[]
*
*
* @throws \RuntimeException On encountering fatal error
*/
public function getReadableConnections($timeout);
public function getReadableConnections(int $timeout): array;

/**
* Returns the number of active connections in the pool.
*
* @return int
*/
public function count();
public function count(): int;

/**
* Stop the connection pool from accepting new connections.
*/
public function shutdown();
public function shutdown(): void;

/**
* Close the connection pool and free any associated resources.
*/
public function close();
public function close(): void;
}
Loading