Completed
Push — bugfix/SUN-4277-formz-error-aj... ( 340776 )
by Romain
36:59
created

ajaxDataMapperError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Exceptions;
15
16
use Romm\Formz\Middleware\Signal\SendsMiddlewareSignal;
17
18
use Romm\Formz\Form\FormInterface;
19
use TYPO3\CMS\Extbase\Error\Error;
20
21
class InvalidArgumentValueException extends FormzException
22
{
23
    const FIELD_VIEW_HELPER_EMPTY_LAYOUT = 'The layout name cannot be empty, please fill with a value.';
24
25
    const SIGNAL_NOT_ALLOWED = 'Trying to dispatch a signal that was not allowed by the middleware "%s". Authorized signals for this middleware are: "%s".';
26
27
    const FORM_NAME_EMPTY = 'The name of the form (type: "%s") can not be empty.';
28
29
    const AJAX_DATA_MAPPER_ERROR = 'Arguments mapping validation error %s';
30
31
    /**
32
     * @code 1485786285
33
     *
34
     * @return self
35
     */
36
    final public static function fieldViewHelperEmptyLayout()
37
    {
38
        /** @var self $exception */
39
        $exception = self::getNewExceptionInstance(self::FIELD_VIEW_HELPER_EMPTY_LAYOUT);
40
41
        return $exception;
42
    }
43
44
    /**
45
     * @code 1490798201
46
     *
47
     * @param SendsMiddlewareSignal $middleware
48
     * @return InvalidArgumentValueException
49
     */
50
    final public static function signalNotAllowed(SendsMiddlewareSignal $middleware)
51
    {
52
        /** @var self $exception */
53
        $exception = self::getNewExceptionInstance(
54
            self::SIGNAL_NOT_ALLOWED,
55
            [
56
                get_class($middleware),
57
                implode('", "', $middleware->getAllowedSignals())
58
            ]
59
        );
60
61
        return $exception;
62
    }
63
64
    /**
65
     * @code 1494515073
66
     *
67
     * @param FormInterface $form
68
     * @return self
69
     */
70
    final public static function formNameEmpty(FormInterface $form)
71
    {
72
        /** @var self $exception */
73
        $exception = self::getNewExceptionInstance(
74
            self::FORM_NAME_EMPTY,
75
            [get_class($form)]
76
        );
77
78
        return $exception;
79
    }
80
81
    /**
82
     * @code 1539693830
83
     *
84
     * @param Error[] $errorsList
85
     * @return self
86
     */
87
    final public static function ajaxDataMapperError(array $errorsList)
88
    {
89
        $message = '';
90
91
        foreach ($errorsList as $key => $errors) {
92
            $message .= ' / ' . $key . ': ' . implode('; ', $errors);
93
        }
94
95
        /** @var self $exception */
96
        $exception = self::getNewExceptionInstance(
97
            self::AJAX_DATA_MAPPER_ERROR,
98
            [$message]
99
        );
100
101
        return $exception;
102
    }
103
}
104