Skip to content

Commit b4f36a8

Browse files
Merge pull request #59 from Nyholm/types
Added PHP7 types
2 parents b8b5e7d + 4bad328 commit b4f36a8

38 files changed

+201
-142
lines changed

src/ApplicationFactory.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon;
46

57
use PHPFastCGI\FastCGIDaemon\Command\DaemonRunCommand;
68
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainer;
79
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainerInterface;
810
use Symfony\Component\Console\Application;
11+
use Symfony\Component\Console\Command\Command;
912

1013
/**
1114
* The default implementation of the ApplicationFactoryInterface.
@@ -30,7 +33,7 @@ public function __construct(DriverContainerInterface $driverContainer = null)
3033
/**
3134
* {@inheritdoc}
3235
*/
33-
public function createApplication($kernel, $commandName = null, $commandDescription = null)
36+
public function createApplication($kernel, string $commandName = null, string $commandDescription = null): Application
3437
{
3538
$command = $this->createCommand($kernel, $commandName, $commandDescription);
3639

@@ -43,7 +46,7 @@ public function createApplication($kernel, $commandName = null, $commandDescript
4346
/**
4447
* {@inheritdoc}
4548
*/
46-
public function createCommand($kernel, $commandName = null, $commandDescription = null)
49+
public function createCommand($kernel, string $commandName = null, string $commandDescription = null): Command
4750
{
4851
$kernelObject = $this->getKernelObject($kernel);
4952

@@ -60,7 +63,7 @@ public function createCommand($kernel, $commandName = null, $commandDescription
6063
*
6164
* @return KernelInterface The kernel as an object implementing the KernelInterface
6265
*/
63-
private function getKernelObject($kernel)
66+
private function getKernelObject($kernel): KernelInterface
6467
{
6568
if ($kernel instanceof KernelInterface) {
6669
return $kernel;

src/ApplicationFactoryInterface.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon;
46

57
use Symfony\Component\Console\Application;
@@ -20,7 +22,7 @@ interface ApplicationFactoryInterface
2022
*
2123
* @return Application The Symfony console application
2224
*/
23-
public function createApplication($kernel, $commandName = null, $commandDescription = null);
25+
public function createApplication($kernel, string $commandName = null, string $commandDescription = null): Application;
2426

2527
/**
2628
* Create a Symfony console command.
@@ -31,5 +33,5 @@ public function createApplication($kernel, $commandName = null, $commandDescript
3133
*
3234
* @return Command The Symfony console command
3335
*/
34-
public function createCommand($kernel, $commandName = null, $commandDescription = null);
36+
public function createCommand($kernel, string $commandName = null, string $commandDescription = null): Command;
3537
}

src/CallbackKernel.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon;
46

57
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
@@ -22,7 +24,7 @@ final class CallbackKernel implements KernelInterface
2224
*
2325
* @throws \InvalidArgumentException When not given callable callback
2426
*/
25-
public function __construct($handler)
27+
public function __construct(callable $handler)
2628
{
2729
if (!is_callable($handler)) {
2830
throw new \InvalidArgumentException('Handler callback is not callable');

src/Command/DaemonRunCommand.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon\Command;
46

57
use PHPFastCGI\FastCGIDaemon\DaemonInterface;
68
use PHPFastCGI\FastCGIDaemon\DaemonOptions;
9+
use PHPFastCGI\FastCGIDaemon\DaemonOptionsInterface;
710
use PHPFastCGI\FastCGIDaemon\Driver\DriverContainerInterface;
811
use PHPFastCGI\FastCGIDaemon\KernelInterface;
912
use Symfony\Component\Console\Command\Command;
@@ -70,9 +73,9 @@ public function __construct(KernelInterface $kernel, DriverContainerInterface $d
7073
* @param InputInterface $input The Symfony command input
7174
* @param OutputInterface $output The Symfony command output
7275
*
73-
* @return DaemonOptions The daemon configuration
76+
* @return DaemonOptionsInterface The daemon configuration
7477
*/
75-
private function getDaemonOptions(InputInterface $input, OutputInterface $output)
78+
private function getDaemonOptions(InputInterface $input, OutputInterface $output): DaemonOptionsInterface
7679
{
7780
$logger = new ConsoleLogger($output);
7881

src/DaemonFactoryInterface.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon;
46

57
/**
@@ -18,7 +20,7 @@ interface DaemonFactoryInterface
1820
*
1921
* @return DaemonInterface The FastCGI daemon
2022
*/
21-
public function createDaemon(KernelInterface $kernel, DaemonOptions $options, $fd = DaemonInterface::FCGI_LISTENSOCK_FILENO);
23+
public function createDaemon(KernelInterface $kernel, DaemonOptions $options, int $fd = DaemonInterface::FCGI_LISTENSOCK_FILENO): DaemonInterface;
2224

2325
/**
2426
* Create a FastCGI daemon listening on a given address. The default host is
@@ -31,5 +33,5 @@ public function createDaemon(KernelInterface $kernel, DaemonOptions $options, $f
3133
*
3234
* @return DaemonInterface The FastCGI daemon
3335
*/
34-
public function createTcpDaemon(KernelInterface $kernel, DaemonOptions $options, $host, $port);
36+
public function createTcpDaemon(KernelInterface $kernel, DaemonOptions $options, string $host, int $port): DaemonInterface;
3537
}

src/DaemonInterface.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon;
46

57
/**
@@ -46,13 +48,13 @@ interface DaemonInterface
4648
*
4749
* @throws \Exception On fatal error
4850
*/
49-
public function run();
51+
public function run(): void;
5052

5153
/**
5254
* Flag the daemon for shutting down. This will stop it from accepting
5355
* requests.
54-
*
56+
*
5557
* @param string|null Optional message.
5658
*/
57-
public function flagShutdown($message = null);
59+
public function flagShutdown(string $message = null): void;
5860
}

src/DaemonOptions.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon;
46

57
use Psr\Log\LoggerInterface;
@@ -19,13 +21,13 @@ final class DaemonOptions implements DaemonOptionsInterface
1921
* Constructor.
2022
*
2123
* The value of the LOGGER option must implement the PSR-3 LoggerInterface.
22-
*
24+
*
2325
* For the REQUEST_LIMIT, MEMORY_LIMIT and TIME_LIMIT options, NO_LIMIT can
2426
* be used to specify that these metrics should not cause the daemon to
2527
* shutdown.
2628
*
2729
* @param array $options The options to configure the daemon with
28-
*
30+
*
2931
* @throws \InvalidArgumentException On unrecognised option
3032
*/
3133
public function __construct(array $options = [])
@@ -52,7 +54,7 @@ public function __construct(array $options = [])
5254
}
5355
}
5456

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

src/DaemonOptionsInterface.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon;
46

57
interface DaemonOptionsInterface
@@ -22,5 +24,5 @@ interface DaemonOptionsInterface
2224
*
2325
* @throws \InvalidArgumentException On unrecognised option
2426
*/
25-
public function getOption($option);
27+
public function getOption(string $option);
2628
}

src/DaemonTrait.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon;
46

57
use PHPFastCGI\FastCGIDaemon\Exception\ShutdownException;
@@ -38,10 +40,10 @@ trait DaemonTrait
3840

3941
/**
4042
* Flags the daemon for shutting down.
41-
*
43+
*
4244
* @param string $message Optional shutdown message
4345
*/
44-
public function flagShutdown($message = null)
46+
public function flagShutdown(string $message = null): void
4547
{
4648
$this->isShutdown = true;
4749
$this->shutdownMessage = (null === $message ? 'Daemon flagged for shutdown' : $message);
@@ -51,9 +53,9 @@ public function flagShutdown($message = null)
5153
* Loads to configuration from the daemon options and installs signal
5254
* handlers.
5355
*
54-
* @param DaemonOptions $daemonOptions
56+
* @param DaemonOptionsInterface $daemonOptions
5557
*/
56-
private function setupDaemon(DaemonOptions $daemonOptions)
58+
private function setupDaemon(DaemonOptionsInterface $daemonOptions): void
5759
{
5860
$this->requestCount = 0;
5961
$this->requestLimit = $daemonOptions->getOption(DaemonOptions::REQUEST_LIMIT);
@@ -74,7 +76,7 @@ private function setupDaemon(DaemonOptions $daemonOptions)
7476
*
7577
* @param int[] $statusCodes The status codes of sent responses
7678
*/
77-
private function considerStatusCodes($statusCodes)
79+
private function considerStatusCodes(array $statusCodes): void
7880
{
7981
$this->requestCount += count($statusCodes);
8082

@@ -94,7 +96,7 @@ private function considerStatusCodes($statusCodes)
9496
*
9597
* @throws ShutdownException On receiving a SIGINT or SIGALRM
9698
*/
97-
private function installSignalHandlers()
99+
private function installSignalHandlers(): void
98100
{
99101
declare (ticks = 1);
100102

@@ -114,7 +116,7 @@ private function installSignalHandlers()
114116
*
115117
* @throws ShutdownException When limits in the daemon options are exceeded
116118
*/
117-
private function checkDaemonLimits()
119+
private function checkDaemonLimits(): void
118120
{
119121
if ($this->isShutdown) {
120122
throw new ShutdownException($this->shutdownMessage);

src/Driver/DriverContainer.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon\Driver;
46

7+
use PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface;
8+
59
final class DriverContainer implements DriverContainerInterface
610
{
711
/**
@@ -25,7 +29,7 @@ public function __construct()
2529
/**
2630
* {@inheritdoc}
2731
*/
28-
public function getFactory($driver)
32+
public function getFactory(string $driver): DaemonFactoryInterface
2933
{
3034
if (!isset($this->drivers[$driver])) {
3135
throw new \InvalidArgumentException('Unknown driver: '.$driver);

src/Driver/DriverContainerInterface.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon\Driver;
46

57
use PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface;
@@ -13,5 +15,5 @@ interface DriverContainerInterface
1315
*
1416
* @return DaemonFactoryInterface The daemon factory for the driver
1517
*/
16-
public function getFactory($driver);
18+
public function getFactory(string $driver): DaemonFactoryInterface;
1719
}

src/Driver/Userland/Connection/ConnectionInterface.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon\Driver\Userland\Connection;
46

57
use PHPFastCGI\FastCGIDaemon\Driver\Userland\Exception\ConnectionException;
@@ -19,7 +21,7 @@ interface ConnectionInterface
1921
*
2022
* @throws ConnectionException On failure
2123
*/
22-
public function read($length);
24+
public function read(int $length): string;
2325

2426
/**
2527
* Write data to the connection.
@@ -28,17 +30,17 @@ public function read($length);
2830
*
2931
* @throws ConnectionException On failure
3032
*/
31-
public function write($buffer);
33+
public function write(string $buffer): void;
3234

3335
/**
3436
* Tests to see if the connection has been closed.
3537
*
3638
* @return bool True if the connection has been closed, false otherwise
3739
*/
38-
public function isClosed();
40+
public function isClosed(): bool;
3941

4042
/**
4143
* Closes the connection it from the pool.
4244
*/
43-
public function close();
45+
public function close(): void;
4446
}

src/Driver/Userland/Connection/ConnectionPoolInterface.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PHPFastCGI\FastCGIDaemon\Driver\Userland\Connection;
46

57
/**
@@ -19,25 +21,25 @@ interface ConnectionPoolInterface
1921
* @param int $timeout Upper bound on the amount of time to wair for readable connections
2022
*
2123
* @return ConnectionInterface[]
22-
*
24+
*
2325
* @throws \RuntimeException On encountering fatal error
2426
*/
25-
public function getReadableConnections($timeout);
27+
public function getReadableConnections(int $timeout): array;
2628

2729
/**
2830
* Returns the number of active connections in the pool.
2931
*
3032
* @return int
3133
*/
32-
public function count();
34+
public function count(): int;
3335

3436
/**
3537
* Stop the connection pool from accepting new connections.
3638
*/
37-
public function shutdown();
39+
public function shutdown(): void;
3840

3941
/**
4042
* Close the connection pool and free any associated resources.
4143
*/
42-
public function close();
44+
public function close(): void;
4345
}

0 commit comments

Comments
 (0)