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::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 5
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