Completed
Push — middleware-wip ( ffd957...48fd00 )
by Romain
02:53
created

StepFetchingMiddleware   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 9
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B before() 0 40 5
A getCurrentStep() 0 4 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\Middleware\Item\Step;
15
16
use Romm\Formz\Middleware\Argument\Arguments;
17
use Romm\Formz\Middleware\Item\AbstractMiddleware;
18
use Romm\Formz\Middleware\Item\FormValidation\FormValidationSignal;
19
use Romm\Formz\Middleware\Signal\Before;
20
21
/**
22
 * @todo
23
 */
24
class StepFetchingMiddleware extends AbstractMiddleware implements Before, FormValidationSignal
25
{
26
    /**
27
     * @var int
28
     */
29
    protected $priority = self::PRIORITY_STEP;
30
31
    /**
32
     * @param Arguments $arguments
33
     */
34
    public function before(Arguments $arguments)
35
    {
36
        $formObject = $this->getFormObject();
37
        $configuration = $formObject->getConfiguration();
38
39
        if (false === $configuration->hasStep()
40
            || false === $formObject->getPersistenceManager()->formIsPersistent()
41
        ) {
42
            return;
43
        }
44
45
        $metadata = $formObject->getFormMetadata()->getMetadata();
46
        $currentStep = $this->getCurrentStep();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $currentStep is correct as $this->getCurrentStep() (which targets Romm\Formz\Middleware\It...eware::getCurrentStep()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
47
48
        if ($currentStep) {
49
            // @todo check step valid
50
        } else {
51
            $key = 'core.step';
52
53
            if ($metadata->has($key)) { // @todo check default step
54
                // @todo
55
            } else {
56
                $metadata->set($key, 1);
57
58
                $defaultStep = $configuration->getStep()->getDefaultStep();
59
60
                $this->redirect()
61
                    ->toPage($defaultStep->getPageUid())
62
                    ->toExtension($defaultStep->getExtension())
63
                    ->toController($defaultStep->getController())
64
                    ->toAction($defaultStep->getAction())
65
                    ->withArguments([
66
                        'fz-hash' => [
67
                            $formObject->getName() => $formObject->getFormHash()
68
                        ]
69
                    ])
70
                    ->dispatch();
71
            }
72
        }
73
    }
74
75
    protected function getCurrentStep()
76
    {
77
78
    }
79
}
80