Skip to content

Commit 8716cc6

Browse files
committed
Add types info
1 parent 82800fd commit 8716cc6

38 files changed

+268
-221
lines changed

example/lib/Example/LogHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct($debug = false)
2020
$this->debug = $debug;
2121
}
2222

23-
public static function getSubscribedEvents()
23+
public static function getSubscribedEvents(): array
2424
{
2525
return array(
2626
SpiderEvents::SPIDER_CRAWL_FILTER_POSTFETCH => 'logFiltered',

example/lib/Example/StatsHandler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
class StatsHandler implements EventSubscriberInterface
1515
{
1616
/** @var string */
17-
protected $spiderId;
17+
protected string $spiderId;
1818

19-
protected $persisted = array();
19+
protected array $persisted = array();
2020

21-
protected $queued = array();
21+
protected array $queued = array();
2222

23-
protected $filtered = array();
23+
protected array $filtered = array();
2424

25-
protected $failed = array();
25+
protected array $failed = array();
2626

2727
public static function getSubscribedEvents(): array
2828
{

src/Discoverer/CrawlerDiscoverer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
*/
1818
abstract class CrawlerDiscoverer extends Discoverer implements DiscovererInterface
1919
{
20-
/** @var string */
21-
protected $selector;
20+
protected string $selector;
2221

2322
/**
24-
* @param $selector
23+
* @param string $selector
2524
*/
2625
public function __construct(string $selector)
2726
{

src/Downloader/Downloader.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ class Downloader implements DownloaderInterface
1919
use DispatcherTrait;
2020

2121
/** @var PersistenceHandlerInterface */
22-
private $persistenceHandler;
22+
private PersistenceHandlerInterface $persistenceHandler;
2323

2424
/** @var RequestHandlerInterface */
25-
private $requestHandler;
25+
private RequestHandlerInterface $requestHandler;
2626

2727
/** @var int the maximum number of downloaded resources. 0 means no limit */
28-
private $downloadLimit = 0;
28+
private int $downloadLimit = 0;
2929

3030
/** @var PostFetchFilterInterface[] */
31-
private $postFetchFilters = array();
31+
private array $postFetchFilters = array();
3232

3333
/**
3434
* Downloader constructor.
@@ -72,7 +72,7 @@ public function getDownloadLimit(): int
7272
/**
7373
* @param PostFetchFilterInterface $filter
7474
*/
75-
public function addPostFetchFilter(PostFetchFilterInterface $filter)
75+
public function addPostFetchFilter(PostFetchFilterInterface $filter): void
7676
{
7777
$this->postFetchFilters[] = $filter;
7878
}
@@ -81,7 +81,7 @@ public function addPostFetchFilter(PostFetchFilterInterface $filter)
8181
* @param DiscoveredUri $uri
8282
* @return false|Resource
8383
*/
84-
public function download(DiscoveredUri $uri)
84+
public function download(DiscoveredUri $uri): Resource|false
8585
{
8686
$resource = $this->fetchResource($uri);
8787

@@ -109,7 +109,7 @@ public function isDownLoadLimitExceeded(): bool
109109
* @param GenericEvent $event
110110
* @param string $eventName
111111
*/
112-
private function dispatch(GenericEvent $event, string $eventName)
112+
private function dispatch(GenericEvent $event, string $eventName): void
113113
{
114114
$this->getDispatcher()->dispatch($event, $eventName);
115115
}
@@ -118,7 +118,7 @@ private function dispatch(GenericEvent $event, string $eventName)
118118
* @param DiscoveredUri $uri
119119
* @return Resource|false
120120
*/
121-
protected function fetchResource(DiscoveredUri $uri)
121+
protected function fetchResource(DiscoveredUri $uri): Resource|false
122122
{
123123
$resource = false;
124124

@@ -162,7 +162,7 @@ private function matchesPostfetchFilter(Resource $resource): bool
162162
/**
163163
* @param PersistenceHandlerInterface $persistenceHandler
164164
*/
165-
public function setPersistenceHandler(PersistenceHandlerInterface $persistenceHandler)
165+
public function setPersistenceHandler(PersistenceHandlerInterface $persistenceHandler): void
166166
{
167167
$this->persistenceHandler = $persistenceHandler;
168168
}
@@ -178,7 +178,7 @@ public function getPersistenceHandler(): PersistenceHandlerInterface
178178
/**
179179
* @param RequestHandlerInterface $requestHandler
180180
*/
181-
public function setRequestHandler(RequestHandlerInterface $requestHandler)
181+
public function setRequestHandler(RequestHandlerInterface $requestHandler): void
182182
{
183183
$this->requestHandler = $requestHandler;
184184
}

src/Event/DispatcherTrait.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
trait DispatcherTrait
1010
{
11-
/** @var EventDispatcherInterface */
12-
private $dispatcher;
11+
private ?EventDispatcherInterface $dispatcher = null;
1312

1413
/**
1514
* @return EventDispatcherInterface
1615
*/
1716
public function getDispatcher(): EventDispatcherInterface
1817
{
19-
if (!$this->dispatcher) {
18+
if ($this->dispatcher == null) {
2019
$this->dispatcher = new EventDispatcher();
2120
}
2221

src/EventListener/PolitenessPolicyListener.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
*/
1111
class PolitenessPolicyListener
1212
{
13-
/** @var string */
14-
private $previousHostname;
13+
private ?string $previousHostname = null;
1514

1615
/** @var int the delay in microseconds between requests to the same domain */
17-
private $requestDelay;
16+
private int $requestDelay;
1817

19-
public $totalDelay = 0;
18+
public int $totalDelay = 0;
2019

2120
/**
2221
* @param int $requestDelay the delay in milliseconds between requests to the same domain
@@ -29,7 +28,7 @@ public function __construct(int $requestDelay)
2928
/**
3029
* @param GenericEvent $event
3130
*/
32-
public function onCrawlPreRequest(GenericEvent $event)
31+
public function onCrawlPreRequest(GenericEvent $event): void
3332
{
3433
$currentHostname = $event->getArgument('uri')->getHost();
3534

src/Filter/Postfetch/MimeTypeFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
class MimeTypeFilter implements PostFetchFilterInterface
1212
{
13-
protected $allowedMimeType = '';
13+
protected string $allowedMimeType = '';
1414

1515
public function __construct($allowedMimeType)
1616
{

src/Filter/PreFetchFilterInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
interface PreFetchFilterInterface
1111
{
1212
/**
13+
* Returns true of the URI should be filtered out, i.e. NOT be crawled.
1314
* @param UriInterface $uri
1415
* @return boolean
1516
*/

src/Filter/Prefetch/AllowedHostsFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
class AllowedHostsFilter implements PreFetchFilterInterface
1212
{
1313
/** @var array The hostnames to filter links with */
14-
private $allowedHosts;
14+
private array $allowedHosts;
1515

16-
private $allowSubDomains;
16+
private bool $allowSubDomains;
1717

1818
/**
1919
* @param string[] $seeds

src/Filter/Prefetch/AllowedPortsFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AllowedPortsFilter implements PreFetchFilterInterface
1313
/**
1414
* @var array
1515
*/
16-
private $allowedPorts;
16+
private array $allowedPorts;
1717

1818
/**
1919
* The whitelist of allowed ports

0 commit comments

Comments
 (0)