Skip to content

Commit 6df452f

Browse files
Merge pull request #8 from Kick-In/fix-deprecation
Fix some deprecations and remove superfluous PHPDoc
2 parents 8789394 + 2f8d352 commit 6df452f

9 files changed

+38
-176
lines changed

Backtrace/BacktraceLogFile.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,18 @@ class BacktraceLogFile
3737
private $folder;
3838

3939
/**
40-
* Constructor -> generate an unique name
41-
*
42-
* @param string $folder
43-
*
4440
* @throws Exception
4541
*/
46-
public function __construct($folder)
42+
public function __construct(string $folder)
4743
{
4844
$this->folder = $folder;
4945
$this->generateNewName();
5046
}
5147

5248
/**
5349
* Returns the name of the file that will be uploaded
54-
*
55-
* @return string
5650
*/
57-
public function getName()
51+
public function getName(): string
5852
{
5953
return $this->name;
6054
}
@@ -64,19 +58,15 @@ public function getName()
6458
*
6559
* @throws Exception
6660
*/
67-
public function generateNewName()
61+
public function generateNewName(): void
6862
{
6963
$this->name = $this->folder . "/" . bin2hex(random_bytes(20)) . ".btl";
7064
}
7165

7266
/**
7367
* Sets the content for the file to be uploaded
74-
*
75-
* @param $code
76-
*
77-
* @return $this
7868
*/
79-
public function setFileContent($code)
69+
public function setFileContent(string $code): self
8070
{
8171
$this->fileContent = $code;
8272

@@ -85,21 +75,18 @@ public function setFileContent($code)
8575

8676
/**
8777
* Returns the content of the backtrace file that will be uploaded
88-
*
89-
* @return string
9078
*/
91-
public function getFileContent()
79+
public function getFileContent(): string
9280
{
9381
return $this->fileContent;
9482
}
9583

9684
/**
97-
* Upload the file. Returns the true if it the upload was succesful, else returns false
85+
* Upload the file. Returns true if the upload was successful, else throws
9886
*
99-
* @return bool
10087
* @throws UploadFailedException|FileAlreadyExistsException
10188
*/
102-
public function uploadFile()
89+
public function uploadFile(): bool
10390
{
10491
$fs = new Filesystem();
10592

Configuration/ConfigurationInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
66

77
/**
8-
* Interface ConfigurationInterface
9-
*
108
* @internal
119
*/
1210
interface ConfigurationInterface

Configuration/SwiftMailerConfigurationInterface.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22

33
namespace Kickin\ExceptionHandlerBundle\Configuration;
44

5-
/**
6-
* Interface SwiftMailerConfigurationInterface
7-
*/
85
interface SwiftMailerConfigurationInterface extends ConfigurationInterface
96
{
107
/**
11-
* @inheritDoc
12-
*
138
* @return string|array
149
*/
1510
public function getSender();
1611

1712
/**
18-
* @inheritDoc
19-
*
2013
* @return mixed
2114
*/
2215
public function getReceiver();

Configuration/SymfonyMailerConfigurationInterface.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44

55
use Symfony\Component\Mime\Address;
66

7-
/**
8-
* Interface SymfonyMailerConfigurationInterface
9-
*/
107
interface SymfonyMailerConfigurationInterface extends ConfigurationInterface
118
{
129
/**
13-
* @inheritDoc
14-
*
1510
* @return Address|string
1611
*/
1712
public function getSender();
1813

1914
/**
20-
* @inheritDoc
21-
*
2215
* @return Address|string
2316
*/
2417
public function getReceiver();

DependencyInjection/Configuration.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,13 @@
55
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
66
use Symfony\Component\Config\Definition\ConfigurationInterface;
77

8-
/**
9-
* This is the class that validates and merges configuration from your app/config files
10-
*
11-
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12-
*/
138
class Configuration implements ConfigurationInterface
149
{
15-
/**
16-
* {@inheritDoc}
17-
*/
1810
public function getConfigTreeBuilder(): TreeBuilder
1911
{
2012
$treeBuilder = new TreeBuilder('kickin_exception_handler');
2113

22-
if (method_exists($treeBuilder, 'getRootNode')) {
23-
$rootNode = $treeBuilder->getRootNode();
24-
} else {
25-
// for symfony/config 4.1 and older
26-
$rootNode = $treeBuilder->root('kickin_exception_handler');
27-
}
14+
$rootNode = $treeBuilder->getRootNode();
2815

2916
// Here you should define the parameters that are allowed to
3017
// configure your bundle. See the documentation linked above for

DependencyInjection/KickinExceptionHandlerExtension.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,9 @@
1111
use Symfony\Component\DependencyInjection\Reference;
1212
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1313

14-
/**
15-
* This is the class that loads and manages your bundle configuration
16-
*
17-
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
18-
*/
1914
class KickinExceptionHandlerExtension extends Extension
2015
{
21-
/**
22-
* {@inheritDoc}
23-
* @throws Exception
24-
*/
25-
public function load(array $configs, ContainerBuilder $container)
16+
public function load(array $configs, ContainerBuilder $container): void
2617
{
2718
// Parse configuration
2819
$configuration = new Configuration();
@@ -38,10 +29,8 @@ public function load(array $configs, ContainerBuilder $container)
3829

3930
/**
4031
* Configures the Swift Mailer handler
41-
*
42-
* @param ContainerBuilder $container
4332
*/
44-
private function configureSwiftMailer(ContainerBuilder $container)
33+
private function configureSwiftMailer(ContainerBuilder $container): void
4534
{
4635
if (!class_exists('Swift_Mailer')) {
4736
throw new InvalidConfigurationException('You selected SwiftMailer as mail backend, but it is not installed. Try running `composer req symfony/swiftmailer-bundle` or switch to the Symfony mailer in the configuration.');
@@ -57,10 +46,8 @@ private function configureSwiftMailer(ContainerBuilder $container)
5746

5847
/**
5948
* Configures the Symfony Mailer handler
60-
*
61-
* @param ContainerBuilder $container
6249
*/
63-
private function configureSymfonyMailer(ContainerBuilder $container)
50+
private function configureSymfonyMailer(ContainerBuilder $container): void
6451
{
6552
if (!class_exists('Symfony\Component\Mailer\Mailer')) {
6653
throw new InvalidConfigurationException('You selected the Symfony mailer as mail backend, but it is not installed. Try running `composer req symfony/mailer` or switch to SwiftMailer in the configuration.');
@@ -71,11 +58,6 @@ private function configureSymfonyMailer(ContainerBuilder $container)
7158

7259
/**
7360
* Configure the shared defaults for both handlers
74-
*
75-
* @param ContainerBuilder $container
76-
* @param string $handlerClass
77-
*
78-
* @return Definition
7961
*/
8062
private function configureMailer(ContainerBuilder $container, string $handlerClass): Definition
8163
{

Handler/AbstractExceptionHandler.php

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2121
use Symfony\Component\HttpKernel\KernelEvents;
2222
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
23+
use Throwable;
2324
use Traversable;
2425

2526
/**
2627
* This Service triggers on the kernel.exception and catches any HTTP 500 error. When an HTTP 500 error is detected,
27-
* an e-mail is send to maintainers.
28+
* an e-mail is sent to maintainers.
2829
*
2930
* Pick one of the available implementations, based on your mailer configuration.
3031
*
@@ -77,24 +78,22 @@ public function __construct(TokenStorageInterface $tokenStorage, ConfigurationIn
7778
* while the KernelResponse event is used to determine if the 500 error message is actually displayed to the user.
7879
* This ensures that NotAuthorizedExceptions are not mailed as a 500 error (as a 403 error is presented).
7980
*/
80-
static protected function getSubscribedEvents()
81+
static protected function getSubscribedEvents(): array
8182
{
82-
return array(
83-
KernelEvents::EXCEPTION => array(array('onKernelException', 0)),
84-
KernelEvents::RESPONSE => array(array('onKernelResponse', 0)),
85-
);
83+
return [
84+
KernelEvents::EXCEPTION => [['onKernelException', 0]],
85+
KernelEvents::RESPONSE => [['onKernelResponse', 0]],
86+
];
8687
}
8788

8889
/**
89-
* This function will create create the backtrace and save it with an random
90+
* This function will create the backtrace and save it with a random
9091
* name in /web/uploads/exceptionBacktrace/ and save the name in the session so
9192
* in the html status exception handler load the backtrace and send it in an email.
9293
*
93-
* @param ExceptionEvent $event
94-
*
9594
* @throws Exception
9695
*/
97-
public function onKernelException(ExceptionEvent $event)
96+
public function onKernelException(ExceptionEvent $event): void
9897
{
9998
// Skip some exception types directly
10099
$exception = $event->getThrowable();
@@ -172,12 +171,8 @@ public function onKernelException(ExceptionEvent $event)
172171

173172
/**
174173
* This function builds a backtrace
175-
*
176-
* @param ExceptionEvent $event
177-
*
178-
* @return string
179174
*/
180-
protected function buildBacktrace(ExceptionEvent $event)
175+
protected function buildBacktrace(ExceptionEvent $event): string
181176
{
182177
$user = $this->configuration->getUserInformation($this->tokenStorage->getToken());
183178

@@ -196,11 +191,9 @@ protected function buildBacktrace(ExceptionEvent $event)
196191
* This function handles the Kernel exception response. When the response contains an http 500 error, it is tried to
197192
* get the backtrace from the server (via the file name stored in the session) and mail this to the maintainers
198193
*
199-
* @param ResponseEvent $responseObject
200-
*
201194
* @throws Exception
202195
*/
203-
public function onKernelResponse(ResponseEvent $responseObject)
196+
public function onKernelResponse(ResponseEvent $responseObject): void
204197
{
205198
$response = $responseObject->getResponse();
206199
$request = $responseObject->getRequest();
@@ -318,25 +311,15 @@ public function onKernelResponse(ResponseEvent $responseObject)
318311
}
319312
}
320313

321-
/**
322-
* @param $url
323-
* @param $exceptionMessage
324-
*
325-
* @return string
326-
*/
327-
protected function generateHash($url, $exceptionMessage)
314+
protected function generateHash(string $url, string $exceptionMessage): string
328315
{
329316
return md5($url . $exceptionMessage);
330317
}
331318

332319
/**
333320
* Removes a variable from the request
334-
*
335-
* @param Request $request
336-
* @param string $parameterBin
337-
* @param string $variable
338321
*/
339-
protected function removeVar(Request $request, $parameterBin, $variable)
322+
protected function removeVar(Request $request, string $parameterBin, string $variable): void
340323
{
341324
if ($request->$parameterBin->has($variable)) {
342325
$request->$parameterBin->set($variable, '**REMOVED**');
@@ -345,12 +328,8 @@ protected function removeVar(Request $request, $parameterBin, $variable)
345328

346329
/**
347330
* Removes a variables from the request
348-
*
349-
* @param Request $request
350-
* @param string $parameterBin
351-
* @param array $variables
352331
*/
353-
protected function removeVars(Request $request, $parameterBin, array $variables)
332+
protected function removeVars(Request $request, string $parameterBin, array $variables): void
354333
{
355334
foreach ($variables as $variable) {
356335
$this->removeVar($request, $parameterBin, $variable);
@@ -363,12 +342,8 @@ protected function removeVars(Request $request, $parameterBin, array $variables)
363342

364343
/**
365344
* Returns the request as a string.
366-
*
367-
* @param Request $request
368-
*
369-
* @return string The request
370345
*/
371-
protected function getRequestString(Request $request)
346+
protected function getRequestString(Request $request): string
372347
{
373348
$string =
374349
sprintf('%s %s %s', $request->getMethod(), $request->getRequestUri(), $request->server->get('SERVER_PROTOCOL')) . "\r\n\r\nRequest headers:\r\n" .
@@ -389,14 +364,8 @@ protected function getRequestString(Request $request)
389364

390365
/**
391366
* Convert an array to string
392-
*
393-
* @param $array
394-
* @param int $currentDepth
395-
* @param int $maxDepth
396-
*
397-
* @return string
398367
*/
399-
protected function arrayToString($array, $currentDepth = 0, $maxDepth = 3)
368+
protected function arrayToString(array $array, int $currentDepth = 0, int $maxDepth = 3): string
400369
{
401370
if ($currentDepth >= $maxDepth) {
402371
return '**Maximum recursion level reached**';
@@ -418,25 +387,11 @@ protected function arrayToString($array, $currentDepth = 0, $maxDepth = 3)
418387
}
419388

420389
/**
421-
* @param $uploadException
422-
* @param BacktraceLogFile $backtrace
423-
*
424390
* @throws Exception
425391
*/
426-
abstract protected function sendExceptionHandledFailedMessage($uploadException, BacktraceLogFile $backtrace): void;
392+
abstract protected function sendExceptionHandledFailedMessage(Throwable $uploadException, BacktraceLogFile $backtrace): void;
427393

428394
/**
429-
* @param SessionInterface|null $session
430-
* @param string $requestUri
431-
* @param string $baseUrl
432-
* @param string $method
433-
* @param string $requestString
434-
* @param array $responseString
435-
* @param string $backtrace
436-
* @param string $serverVariablesString
437-
* @param string $globalVariablesString
438-
* @param string $extension
439-
*
440395
* @throws Exception
441396
*/
442397
abstract protected function sendExceptionMessage(

0 commit comments

Comments
 (0)