Skip to content

Commit 63949c3

Browse files
committed
Adding type annotations all over the place
1 parent a03831b commit 63949c3

23 files changed

+104
-105
lines changed

src/ApplicationFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainer;
77
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainerInterface;
88
use Symfony\Component\Console\Application;
9+
use Symfony\Component\Console\Command\Command;
910

1011
/**
1112
* The default implementation of the ApplicationFactoryInterface.
@@ -30,7 +31,7 @@ public function __construct(DriverContainerInterface $driverContainer = null)
3031
/**
3132
* {@inheritdoc}
3233
*/
33-
public function createApplication($kernel, $commandName = null, $commandDescription = null)
34+
public function createApplication($kernel, string $commandName = null, string $commandDescription = null): Application
3435
{
3536
$command = $this->createCommand($kernel, $commandName, $commandDescription);
3637

@@ -43,7 +44,7 @@ public function createApplication($kernel, $commandName = null, $commandDescript
4344
/**
4445
* {@inheritdoc}
4546
*/
46-
public function createCommand($kernel, $commandName = null, $commandDescription = null)
47+
public function createCommand($kernel, string $commandName = null, string $commandDescription = null): Command
4748
{
4849
$kernelObject = $this->getKernelObject($kernel);
4950

@@ -60,7 +61,7 @@ public function createCommand($kernel, $commandName = null, $commandDescription
6061
*
6162
* @return KernelInterface The kernel as an object implementing the KernelInterface
6263
*/
63-
private function getKernelObject($kernel)
64+
private function getKernelObject($kernel): KernelInterface
6465
{
6566
if ($kernel instanceof KernelInterface) {
6667
return $kernel;

src/ApplicationFactoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface ApplicationFactoryInterface
2020
*
2121
* @return Application The Symfony console application
2222
*/
23-
public function createApplication($kernel, $commandName = null, $commandDescription = null);
23+
public function createApplication($kernel, string $commandName = null, string $commandDescription = null): Application;
2424

2525
/**
2626
* Create a Symfony console command.
@@ -31,5 +31,5 @@ public function createApplication($kernel, $commandName = null, $commandDescript
3131
*
3232
* @return Command The Symfony console command
3333
*/
34-
public function createCommand($kernel, $commandName = null, $commandDescription = null);
34+
public function createCommand($kernel, string $commandName = null, string $commandDescription = null): Command;
3535
}

src/CallbackKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class CallbackKernel implements KernelInterface
2222
*
2323
* @throws \InvalidArgumentException When not given callable callback
2424
*/
25-
public function __construct($handler)
25+
public function __construct(callable $handler)
2626
{
2727
if (!is_callable($handler)) {
2828
throw new \InvalidArgumentException('Handler callback is not callable');

src/Command/DaemonRunCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPFastCGI\FastCGIDaemon\DaemonInterface;
66
use PHPFastCGI\FastCGIDaemon\DaemonOptions;
7+
use PHPFastCGI\FastCGIDaemon\DaemonOptionsInterface;
78
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainerInterface;
89
use PHPFastCGI\FastCGIDaemon\KernelInterface;
910
use Symfony\Component\Console\Command\Command;
@@ -70,9 +71,9 @@ public function __construct(KernelInterface $kernel, DriverContainerInterface $d
7071
* @param InputInterface $input The Symfony command input
7172
* @param OutputInterface $output The Symfony command output
7273
*
73-
* @return DaemonOptions The daemon configuration
74+
* @return DaemonOptionsInterface The daemon configuration
7475
*/
75-
private function getDaemonOptions(InputInterface $input, OutputInterface $output)
76+
private function getDaemonOptions(InputInterface $input, OutputInterface $output): DaemonOptionsInterface
7677
{
7778
$logger = new ConsoleLogger($output);
7879

src/DaemonFactoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface DaemonFactoryInterface
1818
*
1919
* @return DaemonInterface The FastCGI daemon
2020
*/
21-
public function createDaemon(KernelInterface $kernel, DaemonOptions $options, $fd = DaemonInterface::FCGI_LISTENSOCK_FILENO);
21+
public function createDaemon(KernelInterface $kernel, DaemonOptions $options, int $fd = DaemonInterface::FCGI_LISTENSOCK_FILENO): DaemonInterface;
2222

2323
/**
2424
* Create a FastCGI daemon listening on a given address. The default host is
@@ -31,5 +31,5 @@ public function createDaemon(KernelInterface $kernel, DaemonOptions $options, $f
3131
*
3232
* @return DaemonInterface The FastCGI daemon
3333
*/
34-
public function createTcpDaemon(KernelInterface $kernel, DaemonOptions $options, $host, $port);
34+
public function createTcpDaemon(KernelInterface $kernel, DaemonOptions $options, string $host, int $port): DaemonInterface;
3535
}

src/DaemonInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ interface DaemonInterface
4646
*
4747
* @throws \Exception On fatal error
4848
*/
49-
public function run();
49+
public function run(): void;
5050

5151
/**
5252
* Flag the daemon for shutting down. This will stop it from accepting
5353
* requests.
54-
*
54+
*
5555
* @param string|null Optional message.
5656
*/
57-
public function flagShutdown($message = null);
57+
public function flagShutdown(string $message = null): void;
5858
}

src/DaemonOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ final class DaemonOptions implements DaemonOptionsInterface
1919
* Constructor.
2020
*
2121
* The value of the LOGGER option must implement the PSR-3 LoggerInterface.
22-
*
22+
*
2323
* For the REQUEST_LIMIT, MEMORY_LIMIT and TIME_LIMIT options, NO_LIMIT can
2424
* be used to specify that these metrics should not cause the daemon to
2525
* shutdown.
2626
*
2727
* @param array $options The options to configure the daemon with
28-
*
28+
*
2929
* @throws \InvalidArgumentException On unrecognised option
3030
*/
3131
public function __construct(array $options = [])
@@ -52,7 +52,7 @@ public function __construct(array $options = [])
5252
}
5353
}
5454

55-
public function getOption($option)
55+
public function getOption(string $option)
5656
{
5757
if (!isset($this->options[$option])) {
5858
throw new \InvalidArgumentException('Unknown option: '.$option);

src/DaemonOptionsInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ interface DaemonOptionsInterface
2222
*
2323
* @throws \InvalidArgumentException On unrecognised option
2424
*/
25-
public function getOption($option);
25+
public function getOption(string $option);
2626
}

src/DaemonTrait.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ trait DaemonTrait
3838

3939
/**
4040
* Flags the daemon for shutting down.
41-
*
41+
*
4242
* @param string $message Optional shutdown message
4343
*/
44-
public function flagShutdown($message = null)
44+
public function flagShutdown(string $message = null): void
4545
{
4646
$this->isShutdown = true;
4747
$this->shutdownMessage = (null === $message ? 'Daemon flagged for shutdown' : $message);
@@ -51,9 +51,9 @@ public function flagShutdown($message = null)
5151
* Loads to configuration from the daemon options and installs signal
5252
* handlers.
5353
*
54-
* @param DaemonOptions $daemonOptions
54+
* @param DaemonOptionsInterface $daemonOptions
5555
*/
56-
private function setupDaemon(DaemonOptions $daemonOptions)
56+
private function setupDaemon(DaemonOptionsInterface $daemonOptions): void
5757
{
5858
$this->requestCount = 0;
5959
$this->requestLimit = $daemonOptions->getOption(DaemonOptions::REQUEST_LIMIT);
@@ -74,7 +74,7 @@ private function setupDaemon(DaemonOptions $daemonOptions)
7474
*
7575
* @param int[] $statusCodes The status codes of sent responses
7676
*/
77-
private function considerStatusCodes($statusCodes)
77+
private function considerStatusCodes(array $statusCodes): void
7878
{
7979
$this->requestCount += count($statusCodes);
8080

@@ -94,7 +94,7 @@ private function considerStatusCodes($statusCodes)
9494
*
9595
* @throws ShutdownException On receiving a SIGINT or SIGALRM
9696
*/
97-
private function installSignalHandlers()
97+
private function installSignalHandlers(): void
9898
{
9999
declare (ticks = 1);
100100

@@ -114,7 +114,7 @@ private function installSignalHandlers()
114114
*
115115
* @throws ShutdownException When limits in the daemon options are exceeded
116116
*/
117-
private function checkDaemonLimits()
117+
private function checkDaemonLimits(): void
118118
{
119119
if ($this->isShutdown) {
120120
throw new ShutdownException($this->shutdownMessage);

src/Driver/DriverContainer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PHPFastCGI\FastCGIDaemon\Driver;
44

5+
use PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface;
6+
57
final class DriverContainer implements DriverContainerInterface
68
{
79
/**
@@ -25,7 +27,7 @@ public function __construct()
2527
/**
2628
* {@inheritdoc}
2729
*/
28-
public function getFactory($driver)
30+
public function getFactory(string $driver): DaemonFactoryInterface
2931
{
3032
if (!isset($this->drivers[$driver])) {
3133
throw new \InvalidArgumentException('Unknown driver: '.$driver);

0 commit comments

Comments
 (0)