Code Duplication    Length = 30-46 lines in 2 locations

src/Ui/Form/Component/Action/Guesser/EnabledGuesser.php 1 location

@@ 13-42 (lines=30) @@
10
 * @author        Ryan Thompson <[email protected]>
11
 * @package       Anomaly\Streams\Platform\Ui\Form\Component\Action\Guesser
12
 */
13
class EnabledGuesser
14
{
15
16
    /**
17
     * Guess the action's enabled parameter.
18
     *
19
     * @param FormBuilder $builder
20
     */
21
    public function guess(FormBuilder $builder)
22
    {
23
        $actions = $builder->getActions();
24
25
        $mode = $builder->getFormMode();
26
27
        foreach ($actions as &$action) {
28
29
            if (!isset($action['enabled'])) {
30
                continue;
31
            }
32
33
            if (is_bool($action['enabled'])) {
34
                continue;
35
            }
36
37
            $action['enabled'] = ($mode === $action['enabled']);
38
        }
39
40
        $builder->setActions($actions);
41
    }
42
}
43

src/Ui/Form/Component/Button/Guesser/EnabledGuesser.php 1 location

@@ 14-59 (lines=46) @@
11
 * @author        Ryan Thompson <[email protected]>
12
 * @package       Anomaly\Streams\Platform\Ui\Form\Component\Button\Guesser
13
 */
14
class EnabledGuesser
15
{
16
17
    /**
18
     * The request object.
19
     *
20
     * @var Request
21
     */
22
    protected $request;
23
24
    /**
25
     * Create a new EnabledGuesser instance.
26
     *
27
     * @param Request $request
28
     */
29
    public function __construct(Request $request)
30
    {
31
        $this->request = $request;
32
    }
33
34
    /**
35
     * Guess the HREF for a button.
36
     *
37
     * @param FormBuilder $builder
38
     */
39
    public function guess(FormBuilder $builder)
40
    {
41
        $buttons = $builder->getButtons();
42
        $mode    = $builder->getFormMode();
43
44
        foreach ($buttons as &$button) {
45
46
            if (!isset($button['enabled'])) {
47
                continue;
48
            }
49
50
            if (is_bool($button['enabled'])) {
51
                continue;
52
            }
53
54
            $button['enabled'] = ($mode === $button['enabled']);
55
        }
56
57
        $builder->setButtons($buttons);
58
    }
59
}
60