Passed
Push — master ( fb7d6f...41a003 )
by Anthony
09:37
created

ExceptionListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
c 1
b 0
f 1
dl 0
loc 29
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A onKernelException() 0 20 2
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\EventListener;
4
5
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
6
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
7
8
class ExceptionListener
9
{
10
    private $paramter;
11
12
    public function __construct(ParameterBagInterface $parameterBag)
13
    {
14
        $this->paramter = $parameterBag;
15
    }
16
17
    public function onKernelException(ExceptionEvent $event)
18
    {
19
        $slack_webhook = $this->paramter->get('ribs_admin.slack_webhook');
20
        if ($slack_webhook) {
21
            $data = array();
22
            $data['channel'] = '#errors';
23
            $data['username'] = $_SERVER['HTTP_HOST'];
24
            $data['text'] = "• *Erreur* : " . strip_tags($event->getThrowable()->getMessage());
25
            $data['text'] .= "\n• *Erreur File* : " . strip_tags($event->getThrowable()->getFile()) . " at line :" . strip_tags($event->getThrowable()->getLine());
26
            $data['unfurl_links'] = false;
27
            $data_json = json_encode($data);
28
29
            $ch = curl_init();
30
            curl_setopt($ch, CURLOPT_URL, $slack_webhook);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
            curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_URL, $slack_webhook);
Loading history...
31
            curl_setopt($ch, CURLOPT_POST, 1);
32
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
33
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
34
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
35
            curl_exec($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
            curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
36
            curl_close($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
            curl_close(/** @scrutinizer ignore-type */ $ch);
Loading history...
37
        }
38
    }
39
}