IncidentHookController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 2
Metric Value
wmc 7
c 5
b 2
f 2
lcom 1
cbo 6
dl 0
loc 70
ccs 23
cts 23
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B emailReciveCheckProcHookAction() 0 24 4
A getIncident() 0 8 1
A getErrorHandlerCallback() 0 6 1
A getIdent() 0 4 1
1
<?php
2
3
namespace IncidentBundle\Controller;
4
5
use IncidentBundle\Entity\Incident;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Exception;
11
12
/**
13
 * Class IncidentHookController
14
 */
15
class IncidentHookController extends Controller
16
{
17
    /**
18
     * @Route("/dnnlpwo2cj287189282bbcnjskshewk/{checkIdent}")
19
     *
20
     * @param Request $request
21
     *
22
     * @return Response
23
     */
24 1
    public function emailReciveCheckProcHookAction($checkIdent, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26 1
        $ident = $this->getIdent($checkIdent);
27
28 1
        $errors = [];
29 1
        $responseData = [];
30 1
        set_error_handler($this->getErrorHandlerCallback($errors));
31
32
        try {
33 1
            $entityManager = $this->getDoctrine()->getManager();
34 1
            if (!$incident = $this->getIncident($ident)) {
35 1
                $incident = new Incident($ident);
36 1
                $entityManager->persist($incident);
37
            }
38 1
            $incident->setMessage('Can\'t send&receive email check fail');
39 1
            $incident->setStatus(500);
40 1
            $entityManager->flush();
41
        } catch (Exception $e) {
42
            $errors[] = $e;
43
        }
44 1
        $responseData['status'] = empty($errors) ? 'ok' : 'error';
45
46 1
        return new Response(json_encode($responseData));
47
    }
48
49
    /**
50
     * @param string $ident
51
     *
52
     * @return Incident
53
     */
54 1
    protected function getIncident($ident)
55
    {
56 1
        $incident = $this->getDoctrine()
57 1
            ->getRepository('IncidentBundle:Incident')
58 1
            ->findOneBy(['ident' => $ident], ['id' => 'desc']);
0 ignored issues
show
Unused Code introduced by
The call to ObjectRepository::findOneBy() has too many arguments starting with array('id' => 'desc').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
59
60 1
        return $incident;
61
    }
62
63
    /**
64
     * @param array $errors
65
     *
66
     * @return \Closure
67
     */
68
    protected function getErrorHandlerCallback(&$errors)
69
    {
70 1
        return function ($errno, $errstr, $errfile, $errline) use (&$errors) {
0 ignored issues
show
Unused Code introduced by
The parameter $errfile is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errline is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
            $errors[] = ['code' => $errno, 'text' => $errstr];
72 1
        };
73
    }
74
75
    /**
76
     * @param $checkIdent
77
     *
78
     * @return string
79
     */
80 1
    protected function getIdent($checkIdent)
81
    {
82 1
        return sprintf('%s.%s', $checkIdent, date('Ymd'));
83
    }
84
}
85