Skip to content

Commit dc7a979

Browse files
staabmclxmstaab
andauthored
level up phpstan (#25)
* Update phpstan.neon.dist * return types * types * Update SystemMonitor.php * Update SystemMonitor.php * Update phpstan.neon.dist * Update SerializableException.php Co-authored-by: Markus Staab <m.staab@complex-it.de>
1 parent e76630c commit dc7a979

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
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: 5
2+
level: 7
33
paths:
44
- src/
55
ignoreErrors:

src/sysmonitor/SerializableException.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,64 @@ class SerializableException
3939
*/
4040
private $previous;
4141

42+
/**
43+
* @return string
44+
*/
4245
public function getMessage()
4346
{
4447
return $this->message;
4548
}
49+
50+
/**
51+
* @return string
52+
*/
4653
public function getCode()
4754
{
4855
return $this->code;
4956
}
57+
58+
/**
59+
* @return string
60+
*/
5061
public function getFile()
5162
{
5263
return $this->file;
5364
}
65+
66+
/**
67+
* @return int
68+
*/
5469
public function getLine()
5570
{
5671
return $this->line;
5772
}
73+
74+
/**
75+
* @return string
76+
*/
5877
public function getTraceAsString()
5978
{
6079
return $this->trace;
6180
}
81+
82+
/**
83+
* @return SerializableException
84+
*/
6285
public function getPrevious()
6386
{
6487
return $this->previous;
6588
}
89+
90+
/**
91+
* @return string
92+
*/
6693
public function getOriginClass()
6794
{
6895
return $this->originClass;
6996
}
7097

7198
/**
72-
* @param \Exception|\Throwable $e
99+
* @param \Exception|\Throwable|self $e
73100
* @return self
74101
*/
75102
public static function fromException($e)

src/sysmonitor/SeverityNotifier.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class SeverityNotifier implements Notifier
1616
*/
1717
private $wrapped;
1818

19+
/**
20+
* @param int $minSeverity
21+
*/
1922
public function __construct(Notifier $wrappedNotifier, $minSeverity)
2023
{
2124
$this->minSeverity = $minSeverity;

src/sysmonitor/SystemEventStats.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,26 @@ class SystemEventStats
1515
*/
1616
private $count;
1717

18+
/**
19+
* @param int $count
20+
*/
1821
public function __construct(SystemEvent $sysEvt, $count)
1922
{
2023
$this->count = $count;
2124
$this->sysEvt = $sysEvt;
2225
}
2326

27+
/**
28+
* @return SystemEvent
29+
*/
2430
public function getEvent()
2531
{
2632
return $this->sysEvt;
2733
}
2834

35+
/**
36+
* @return int
37+
*/
2938
public function getCount()
3039
{
3140
return $this->count;

src/sysmonitor/SystemMonitor.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function __construct(SystemEventStorage $storage, RequestEnvironment $env
4646
}
4747
}
4848

49+
/**
50+
* @return void
51+
*/
4952
public function collectStats(RequestStatsEvent $evt)
5053
{
5154
// we won't even collect data for requests which don't hit either of these min-values, to prevent unnecessary garbage.
@@ -65,6 +68,9 @@ public function collectStats(RequestStatsEvent $evt)
6568
}
6669
}
6770

71+
/**
72+
* @return void
73+
*/
6874
public function collectException(RequestExceptionEvent $evt)
6975
{
7076
$sysEvt = $this->createSystemEvent($evt);
@@ -86,6 +92,9 @@ protected function notifyException(RequestExceptionEvent $evt)
8692
return !($evt->exception instanceof UnreportedException);
8793
}
8894

95+
/**
96+
* @return void
97+
*/
8998
private function rateAndStore(SystemEvent $sysEvt)
9099
{
91100
$evt = $sysEvt->origin;
@@ -156,6 +165,10 @@ private function rateAndStore(SystemEvent $sysEvt)
156165
$this->storage->store($sysEvt);
157166
}
158167

168+
/**
169+
* @param RequestStatsEvent|RequestExceptionEvent $evt
170+
* @return SystemEvent
171+
*/
159172
private function createSystemEvent($evt)
160173
{
161174
if ($evt instanceof RequestStatsEvent) {
@@ -166,6 +179,7 @@ private function createSystemEvent($evt)
166179
$title = sprintf('Exception: "%s" in %s:%s', $exc->getMessage(), $exc->getFile(), $exc->getLine());
167180
$hash = md5($title);
168181
} else {
182+
// @phpstan-ignore-next-line
169183
throw new \Exception(sprintf('Unsupported event type "%s"', is_object($evt) ? get_class($evt) : gettype($evt)));
170184
}
171185

@@ -178,13 +192,20 @@ private function createSystemEvent($evt)
178192
return $sysEvt;
179193
}
180194

195+
/**
196+
* @return bool
197+
*/
181198
private function expectsSoap()
182199
{
183200
// depending on the used framework, there are different was to check for soap requests
184201
return !empty($_SERVER['HTTP_SOAPACTION']) ||
185202
!empty($_SERVER['HTTP_ACCEPT']) && stripos($_SERVER['HTTP_ACCEPT'], 'application/soap+xml') !== false;
186203
}
187204

205+
/**
206+
* @param int $errno
207+
* @return bool
208+
*/
188209
private function isFatalError($errno)
189210
{
190211
return in_array(

0 commit comments

Comments
 (0)