Completed
Push — tmp ( 61b6a8 )
by Romain
02:27
created

formObjectInstanceAlreadyRegistered()   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 2
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\FormInterface;
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 FORM_OBJECT_INSTANCE_ALREADY_REGISTERED = 'The form instance of type "%s" (name "%s") was already registered in the form object factory.';
30
31
    /**
32
     * @code 1465242575
33
     *
34
     * @return self
35
     */
36
    final public static function duplicatedFormContext()
37
    {
38
        /** @var self $exception */
39
        $exception = self::getNewExceptionInstance(self::DUPLICATED_FORM_CONTEXT);
40
41
        return $exception;
42
    }
43
44
    /**
45
     * @code 1477255145
46
     *
47
     * @param FormObjectStatic $form
48
     * @return self
49
     */
50
    final public static function formWasAlreadyRegistered(FormObjectStatic $form)
51
    {
52
        /** @var self $exception */
53
        $exception = self::getNewExceptionInstance(
54
            self::FORM_WAS_ALREADY_REGISTERED,
55
            [$form->getClassName(), Configuration::class]
56
        );
57
58
        return $exception;
59
    }
60
61
    /**
62
     * @code 1491898212
63
     *
64
     * @param FormObject $formObject
65
     * @return self
66
     */
67
    final public static function formInstanceAlreadyAdded(FormObject $formObject)
68
    {
69
        /** @var self $exception */
70
        $exception = self::getNewExceptionInstance(
71
            self::FORM_INSTANCE_ALREADY_ADDED,
72
            [$formObject->getClassName()]
73
        );
74
75
        return $exception;
76
    }
77
78
    /**
79
     * @code 1494515318
80
     *
81
     * @param FormInterface $form
82
     * @param string        $name
83
     * @return self
84
     */
85
    final public static function formObjectInstanceAlreadyRegistered(FormInterface $form, $name)
86
    {
87
        /** @var self $exception */
88
        $exception = self::getNewExceptionInstance(
89
            self::FORM_OBJECT_INSTANCE_ALREADY_REGISTERED,
90
            [get_class($form), $name]
91
        );
92
93
        return $exception;
94
    }
95
}
96