GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ValidationFormException   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 77
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getForm() 0 4 1
C getFlattenErrors() 0 31 7
1
<?php
2
3
namespace M6Web\Bundle\ApiExceptionBundle\Exception;
4
5
use Symfony\Component\Form\FormInterface;
6
use M6Web\Bundle\ApiExceptionBundle\Exception\Interfaces\FlattenErrorExceptionInterface;
7
8
/**
9
 * Class ValidationFormException
10
 */
11
class ValidationFormException extends HttpException implements FlattenErrorExceptionInterface
12
{
13
    /**
14
     * @var FormInterface
15
     */
16
    protected $form;
17
18
    /**
19
     * Constructor
20
     *
21
     * @param FormInterface $form
22
     * @param integer       $statusCode
23
     * @param integer       $code
24
     * @param string        $message
25
     * @param array         $headers
26
     */
27
    public function __construct(
28
        FormInterface $form,
29
        $statusCode = 500,
30
        $code = 0,
31
        $message = '',
32
        array $headers = []
33
    ) {
34
        $this->form = $form;
35
        parent::__construct($statusCode, $code, $message, $headers);
36
    }
37
38
    /**
39
     * Get form
40
     *
41
     * @return FormInterface
42
     */
43
    public function getForm()
44
    {
45
        return $this->form;
46
    }
47
48
    /**
49
     * Flatten form errors
50
     *
51
     * @param FormInterface $form
52
     * @param boolean       $subForm
53
     *
54
     * @return array
55
     */
56
    public function getFlattenErrors(FormInterface $form = null, $subForm = false)
57
    {
58
        $form    = $form ?: $this->form;
59
        $flatten = [];
60
61
        foreach ($form->getErrors() as $error) {
62
            if ($subForm) {
63
                $flatten[] = $error->getMessage();
0 ignored issues
show
Bug introduced by
The method getMessage() does not seem to exist on object<Symfony\Component\Form\FormErrorIterator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
            } else {
65
                $path = $error->getCause()->getPropertyPath();
0 ignored issues
show
Bug introduced by
The method getCause() does not seem to exist on object<Symfony\Component\Form\FormErrorIterator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
67
                if (!array_key_exists($path, $flatten)) {
68
                    $flatten[$path] = [$error->getMessage()];
0 ignored issues
show
Bug introduced by
The method getMessage() does not seem to exist on object<Symfony\Component\Form\FormErrorIterator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
                    continue;
70
                }
71
72
                $flatten[$path][] = $error->getMessage();
0 ignored issues
show
Bug introduced by
The method getMessage() does not seem to exist on object<Symfony\Component\Form\FormErrorIterator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
            }
74
        }
75
76
        $subForm = true;
77
        foreach ($form->all() as $key => $child) {
78
            $childErrors = $this->getFlattenErrors($child, $subForm);
79
80
            if (!empty($childErrors)) {
81
                $flatten[$key] = $childErrors;
82
            }
83
        }
84
85
        return $flatten;
86
    }
87
}
88