Skip to content

Commit 6500d3d

Browse files
Fixed various issues detected by phpstan
1 parent 1c6d57c commit 6500d3d

21 files changed

+48
-59
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 1
2+
level: 3
33

44
paths:
55
- src

src/Browser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Browser
2727
protected $connection;
2828

2929
/**
30-
* @var Target[]
30+
* @var array<string,Target>
3131
*/
3232
protected $targets = [];
3333

@@ -178,7 +178,7 @@ public function createPage(): Page
178178
}
179179

180180
/**
181-
* @param $targetId
181+
* @param string $targetId
182182
* @return Target|null
183183
*/
184184
public function getTarget($targetId)

src/Browser/BrowserProcess.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BrowserProcess implements LoggerAwareInterface
5454
protected $connection;
5555

5656
/**
57-
* @var Browser
57+
* @var ProcessAwareBrowser
5858
*/
5959
protected $browser;
6060

@@ -86,8 +86,8 @@ public function __construct(LoggerInterface $logger = null)
8686

8787
/**
8888
* Starts the browser
89-
* @param $binary
90-
* @param $options
89+
* @param string $binary
90+
* @param array $options
9191
*/
9292
public function start($binary, $options)
9393
{
@@ -156,7 +156,7 @@ public function start($binary, $options)
156156
}
157157

158158
/**
159-
* @return Browser
159+
* @return ProcessAwareBrowser
160160
*/
161161
public function getBrowser()
162162
{

src/BrowserFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static function connectToBrowser(string $uri, array $options = []): Brows
166166

167167
/**
168168
* Create a logger instance from given options
169-
* @param $options
169+
* @param array $options
170170
* @return StreamLogger|null
171171
*/
172172
private static function createLogger($options)

src/Clip.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class Clip
2121

2222
/**
2323
* Clip constructor.
24-
* @param $x
25-
* @param $y
26-
* @param $height
27-
* @param $width
28-
* @param $scale
24+
* @param int $x
25+
* @param int $y
26+
* @param int $height
27+
* @param int $width
28+
* @param float $scale
2929
*/
30-
public function __construct($x, $y, $width, $height, $scale = 1)
30+
public function __construct($x, $y, $width, $height, $scale = 1.0)
3131
{
3232
$this->x = $x;
3333
$this->y = $y;

src/Communication/Connection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function getLogger(): LoggerInterface
115115

116116
/**
117117
* Set the delay to apply everytime before data are sent
118-
* @param $delay
118+
* @param int $delay
119119
*/
120120
public function setConnectionDelay(int $delay)
121121
{
@@ -238,7 +238,7 @@ public function sendMessageSync(Message $message, int $timeout = null): Response
238238

239239
/**
240240
* Create a session for the given target id
241-
* @param $targetId
241+
* @param string $targetId
242242
* @return Session
243243
*/
244244
public function createSession($targetId): Session
@@ -306,7 +306,6 @@ public function readLine()
306306

307307
/**
308308
* Dispatches the message and either stores the response or emits an event
309-
* @param array $response
310309
* @return bool
311310
* @throws InvalidResponse
312311
* @internal
@@ -375,7 +374,7 @@ private function dispatchMessage(string $message, Session $session = null)
375374

376375
/**
377376
* True if a response for the given id exists
378-
* @param $id
377+
* @param string $id
379378
* @return bool
380379
*/
381380
public function hasResponseForId($id)
@@ -384,7 +383,7 @@ public function hasResponseForId($id)
384383
}
385384

386385
/**
387-
* @param $id
386+
* @param string $id
388387
* @return array|null
389388
*/
390389
public function getResponseForId($id)

src/Communication/Response.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class Response implements \ArrayAccess
1919

2020
/**
2121
* Response constructor.
22-
* @param $data
2322
*/
2423
public function __construct(array $data, Message $message)
2524
{
@@ -69,7 +68,7 @@ public function getErrorCode()
6968
}
7069

7170
/**
72-
* @param $name
71+
* @param string $name
7372
* @return mixed
7473
*/
7574
public function getResultData($name)

src/Communication/Session.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Session extends EventEmitter
2929
protected $targetId;
3030

3131
/**
32-
* @var Connection
32+
* @var Connection|null
3333
*/
3434
protected $connection;
3535

@@ -62,7 +62,7 @@ public function sendMessage(Message $message): SessionResponseReader
6262
throw new TargetDestroyed('The session was destroyed.');
6363
}
6464

65-
$topResponse = $this->connection->sendMessage(new Message('Target.sendMessageToTarget', [
65+
$topResponse = $this->getConnection()->sendMessage(new Message('Target.sendMessageToTarget', [
6666
'message' => (string) $message,
6767
'sessionId' => $this->getSessionId()
6868
]));
@@ -81,7 +81,7 @@ public function sendMessageSync(Message $message, int $timeout = null): Response
8181
{
8282
$responseReader = $this->sendMessage($message);
8383

84-
$response = $responseReader->waitForResponse($timeout ?? $this->connection->getSendSyncDefaultTimeout());
84+
$response = $responseReader->waitForResponse($timeout ?? $this->getConnection()->getSendSyncDefaultTimeout());
8585

8686
if (!$response) {
8787
throw new NoResponseAvailable('No response was sent in the given timeout');

src/Communication/Socket/MockSocket.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public function receiveData(): array
8484

8585
/**
8686
* Add data to be returned with receiveData
87-
* @param $data
8887
* @param bool $forNextMessage true to set the response id automatically
8988
* for next message (can stack for multiple messages
9089
*/

src/Communication/Socket/Wrench.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function receiveData(): array
7474

7575
if ($playloads) {
7676
foreach ($playloads as $playload) {
77-
/** @var $playload Payload */
77+
/** @var Payload */
7878
$dataString = $playload->getPayload();
7979
$data[] = $dataString;
8080

src/Communication/Target.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Target
2121
protected $targetInfo;
2222

2323
/**
24-
* @var Session
24+
* @var Session|null
2525
*/
2626
protected $session;
2727

@@ -37,8 +37,6 @@ class Target
3737

3838
/**
3939
* Target constructor.
40-
* @param array $targetInfo
41-
* @param Session $session
4240
*/
4341
public function __construct(array $targetInfo, Connection $connection)
4442
{
@@ -91,8 +89,8 @@ public function isDestroyed(): bool
9189

9290
/**
9391
* Get target info value by it's name or null if it does not exist
94-
* @param $infoName
95-
* @return mixed|null
92+
* @param string $infoName
93+
* @return mixed
9694
*/
9795
public function getTargetInfo($infoName)
9896
{
@@ -101,7 +99,7 @@ public function getTargetInfo($infoName)
10199

102100
/**
103101
* To be called when Target.targetInfoChanged is triggered.
104-
* @param $targetInfo
102+
* @param array $targetInfo
105103
* @internal
106104
*/
107105
public function targetInfoChanged($targetInfo)

src/Cookies/Cookie.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Cookie implements \ArrayAccess
2020

2121
/**
2222
* Cookie constructor.
23-
* @param array $data
2423
*/
2524
public function __construct(array $data)
2625
{
@@ -32,23 +31,23 @@ public function __construct(array $data)
3231
}
3332

3433
/**
35-
* @return mixed|null
34+
* @return mixed
3635
*/
3736
public function getValue()
3837
{
3938
return $this->offsetGet('value');
4039
}
4140

4241
/**
43-
* @return mixed|null
42+
* @return mixed
4443
*/
4544
public function getName()
4645
{
4746
return $this->offsetGet('name');
4847
}
4948

5049
/**
51-
* @return mixed|null
50+
* @return mixed
5251
*/
5352
public function getDomain()
5453
{
@@ -88,9 +87,9 @@ public function offsetUnset($offset)
8887
}
8988

9089
/**
91-
* @param $name
92-
* @param $value
93-
* @param $params
90+
* @param string $name
91+
* @param string $value
92+
* @param array $params
9493
* @return Cookie
9594
*/
9695
public static function create($name, $value, array $params = [])

src/Cookies/CookiesCollection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class CookiesCollection implements \IteratorAggregate, \Countable
2020

2121
/**
2222
* CookiesCollection constructor.
23-
* @param array|null $cookies
2423
*/
2524
public function __construct(array $cookies = null)
2625
{
@@ -36,7 +35,6 @@ public function __construct(array $cookies = null)
3635

3736
/**
3837
* Adds a cookie
39-
* @param Cookie $cookie
4038
*/
4139
public function addCookie(Cookie $cookie)
4240
{
@@ -61,7 +59,7 @@ public function count()
6159

6260
/**
6361
* Get the cookie at the given index
64-
* @param $i
62+
* @param int $i
6563
* @return Cookie
6664
*/
6765
public function getAt($i): Cookie

src/Frame.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public function __construct(array $frameData)
5252
}
5353

5454
/**
55-
* @param array $event
5655
* @internal
5756
*/
5857
public function onLifecycleEvent(array $params)

src/FrameManager.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class FrameManager
3030

3131
/**
3232
* FrameManager constructor.
33-
* @param $page
3433
*/
3534
public function __construct(Page $page, array $frameTree)
3635
{
@@ -69,7 +68,7 @@ public function __construct(Page $page, array $frameTree)
6968

7069
/**
7170
* Checks if the given frame exists
72-
* @param $frameId
71+
* @param string $frameId
7372
* @return bool
7473
*/
7574
public function hasFrame($frameId): bool
@@ -79,7 +78,7 @@ public function hasFrame($frameId): bool
7978

8079
/**
8180
* Get a frame given its id
82-
* @param $frameId
81+
* @param string $frameId
8382
* @return Frame
8483
*/
8584
public function getFrame($frameId): Frame

src/Input/Mouse.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public function move(int $x, int $y, array $options = null)
7878
}
7979

8080
/**
81-
* @param $options
8281
* @throws \HeadlessChromium\Exception\CommunicationException
8382
* @throws \HeadlessChromium\Exception\NoResponseAvailable
8483
*/
@@ -97,7 +96,6 @@ public function press(array $options = null)
9796
}
9897

9998
/**
100-
* @param $options
10199
* @throws \HeadlessChromium\Exception\CommunicationException
102100
* @throws \HeadlessChromium\Exception\NoResponseAvailable
103101
*/

src/Page.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ public function waitForReload($eventName = Page::LOAD, $timeout = 30000, $loader
351351
}
352352

353353
/**
354-
* @param $loaderId
354+
* @param string $eventName
355+
* @param string $loaderId
355356
* @return bool|\Generator
356357
* @throws CommunicationException\CannotReadResponse
357358
* @throws CommunicationException\InvalidResponse
@@ -680,7 +681,7 @@ public function pdf(array $options = []): PagePdf
680681
* ```
681682
* $page->setDeviceMetricsOverride
682683
* ```
683-
* @param $overrides
684+
* @param array $overrides
684685
* @throws CommunicationException
685686
* @throws NoResponseAvailable
686687
*
@@ -772,7 +773,7 @@ public function assertNotClosed()
772773
/**
773774
* Gets the current url of the page, always in sync with the browser.
774775
*
775-
* @return mixed|null
776+
* @return mixed
776777
* @throws CommunicationException\CannotReadResponse
777778
* @throws CommunicationException\InvalidResponse
778779
*/

0 commit comments

Comments
 (0)