Completed
Push — tmp-wip ( afad54...8ffff6 )
by Romain
02:25
created

DuplicateEntryException::conditionAlreadyAdded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
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\Configuration\Configuration;
17
use Romm\Formz\Form\Definition\FormDefinition;
18
use Romm\Formz\Form\FormObject\FormObject;
19
use Romm\Formz\Form\FormObject\FormObjectStatic;
20
21
class DuplicateEntryException extends FormzException
22
{
23
    const DUPLICATED_FORM_CONTEXT = 'You can not use a form view helper inside another one.';
24
25
    const FORM_WAS_ALREADY_REGISTERED = 'The form "%s" was already registered. You can only register a form once. Check the function `%s::hasForm()`.';
26
27
    const FORM_INSTANCE_ALREADY_ADDED = 'The form instance was already added for the form object of class "%s". You cannot add it twice.';
28
29
    const FIELD_ALREADY_ADDED = 'The field "%s" already exists in the form definition. Please use the function `%s::hasField()` before.';
30
31
    const CONDITION_ALREADY_ADDED = 'The condition "%s" already exists in the form definition. Please use the function `%s::hasCondition()` before.';
32
33
    /**
34
     * @code 1465242575
35
     *
36
     * @return self
37
     */
38
    final public static function duplicatedFormContext()
39
    {
40
        /** @var self $exception */
41
        $exception = self::getNewExceptionInstance(self::DUPLICATED_FORM_CONTEXT);
42
43
        return $exception;
44
    }
45
46
    /**
47
     * @code 1477255145
48
     *
49
     * @param FormObjectStatic $form
50
     * @return self
51
     */
52
    final public static function formWasAlreadyRegistered(FormObjectStatic $form)
53
    {
54
        /** @var self $exception */
55
        $exception = self::getNewExceptionInstance(
56
            self::FORM_WAS_ALREADY_REGISTERED,
57
            [$form->getClassName(), Configuration::class]
58
        );
59
60
        return $exception;
61
    }
62
63
    /**
64
     * @code 1491898212
65
     *
66
     * @param FormObject $formObject
67
     * @return self
68
     */
69
    final public static function formInstanceAlreadyAdded(FormObject $formObject)
70
    {
71
        /** @var self $exception */
72
        $exception = self::getNewExceptionInstance(
73
            self::FORM_INSTANCE_ALREADY_ADDED,
74
            [$formObject->getClassName()]
75
        );
76
77
        return $exception;
78
    }
79
80
    /**
81
     * @code 1493881202
82
     *
83
     * @param string $name
84
     * @return self
85
     */
86
    final public static function fieldAlreadyAdded($name)
87
    {
88
        /** @var self $exception */
89
        $exception = self::getNewExceptionInstance(
90
            self::FIELD_ALREADY_ADDED,
91
            [$name, FormDefinition::class]
92
        );
93
94
        return $exception;
95
    }
96
97
    /**
98
     * @code 1493882348
99
     *
100
     * @param string $name
101
     * @return self
102
     */
103
    final public static function conditionAlreadyAdded($name)
104
    {
105
        /** @var self $exception */
106
        $exception = self::getNewExceptionInstance(
107
            self::CONDITION_ALREADY_ADDED,
108
            [$name, FormDefinition::class]
109
        );
110
111
        return $exception;
112
    }
113
}
114