Passed
Push — master ( 4d9ea0...ff80d7 )
by Anton
02:10
created

TestController::payloadAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\App\Controller;
10
11
use Psr\Http\Message\ServerRequestInterface;
12
use Spiral\App\Request\BadRequest;
13
use Spiral\App\Request\TestRequest;
14
use Spiral\Core\Controller;
15
use Spiral\Filter\RequestInput;
16
use Spiral\Http\PaginationFactory;
17
use Spiral\Pagination\Paginator;
18
use Spiral\Router\RouteInterface;
19
use Spiral\Translator\Traits\TranslatorTrait;
20
21
class TestController extends Controller
22
{
23
    use TranslatorTrait;
24
25
    public function indexAction(string $name = 'Dave')
26
    {
27
        return "Hello, {$name}.";
28
    }
29
30
    public function paginateAction(PaginationFactory $paginationFactory)
31
    {
32
        /** @var Paginator $p */
33
        $p = $paginationFactory->createPaginator('page');
34
35
        return $p->withCount(1000)->getPage();
36
    }
37
38
    public function filterAction(TestRequest $r)
39
    {
40
        return $r->isValid() ? ($r->value ?? 'ok') : json_encode($r->getErrors());
0 ignored issues
show
Bug Best Practice introduced by
The property value does not exist on Spiral\App\Request\TestRequest. Since you implemented __get, consider adding a @property annotation.
Loading history...
41
    }
42
43
    public function filter2Action(BadRequest $r)
0 ignored issues
show
Unused Code introduced by
The parameter $r is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    public function filter2Action(/** @scrutinizer ignore-unused */ BadRequest $r)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
    }
46
47
    public function inputAction(RequestInput $i)
48
    {
49
        return 'value: ' . $i->withPrefix('section')->getValue('query', 'value');
50
    }
51
52
    public function errorAction()
53
    {
54
        echo $undefined;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $undefined seems to be never defined.
Loading history...
55
    }
56
57
    public function routeAction(RouteInterface $route)
58
    {
59
        return $route->getMatches();
60
    }
61
62
    public function payloadAction(ServerRequestInterface $request)
63
    {
64
        return $request->getParsedBody();
65
    }
66
67
    public function requiredAction(int $id)
68
    {
69
        //no index
70
        $this->say(get_class($this));
71
        $this->say('Hello world');
72
        $this->say('Hello world', [], 'external');
73
74
        l('l');
75
        l('l', [], 'external');
76
        p('%s unit|%s units', 10);
77
        p('%s unit|%s units', 10, [], 'external');
78
79
        return $id;
80
    }
81
}
82