Completed
Push — master ( 116ca6...19b0f3 )
by Anton
03:42 queued 01:47
created

WelcomeController::visualsAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Vault\Controllers;
10
11
use Spiral\Core\Controller;
12
use Spiral\Vault\Controllers\Grids\SampleSource;
13
use Spiral\Vault\Controllers\Requests\WelcomeRequest;
14
15
/**
16
 * No guard check in this sample controller.
17
 */
18
class WelcomeController extends Controller
19
{
20
    /**
21
     * @return string
22
     */
23
    public function indexAction()
24
    {
25
        return $this->views->render('vault:welcome/index');
0 ignored issues
show
Documentation introduced by
The property views does not exist on object<Spiral\Vault\Cont...lers\WelcomeController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function visualsAction()
32
    {
33
        return $this->views->render('vault:welcome/visuals', [
0 ignored issues
show
Documentation introduced by
The property views does not exist on object<Spiral\Vault\Cont...lers\WelcomeController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
34
            'grid' => (new SampleSource())->paginate(2)
35
        ]);
36
    }
37
38
    /**
39
     * @param WelcomeRequest $request
40
     *
41
     * @return array
42
     */
43
    public function submitAction(WelcomeRequest $request)
44
    {
45
        if (!$request->isValid()) {
46
            return [
47
                'status' => 400,
48
                'errors' => $request->getErrors()
49
            ];
50
        }
51
52
        return [
53
            'status'  => 200,
54
            'message' => 'All good!'
55
        ];
56
    }
57
}
58