CaptchaController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the MIT license.
18
 */
19
namespace LearnZF2Captcha\Controller;
20
21
use LearnZF2Captcha\Form\CaptchaForm;
22
use Zend\Mvc\Controller\AbstractActionController;
23
use Zend\View\Model\ViewModel;
24
25
/*
26
 *
27
 * @author Abdul Malik Ikhsan <[email protected]>
28
 */
29
class CaptchaController extends AbstractActionController
30
{
31
    /**
32
     * @var CaptchaForm
33
     */
34
    private $captchaForm;
35
36
    public function __construct(CaptchaForm $captchaForm)
37
    {
38
        $this->captchaForm = $captchaForm;
39
    }
40
41
    public function indexAction()
42
    {
43
        $form = $this->captchaForm;
44
        $request = $this->getRequest();
45
46
        $isValid = false;
47
        if ($request->isPost()) {
48
            $form->setAttribute('method', 'post');
49
50
            $form->setData($request->getPost());
51
            $isValid = $form->isValid();
52
53
            $form->setAttribute('method', 'get');
54
        }
55
56
        return new ViewModel([
57
            'form' => $form,
58
            'isValid' => $isValid,
59
            'isPost' => $request->isPost(),
60
        ]);
61
    }
62
}
63