Passed
Push — master ( b0761f...1fb147 )
by Anton
03:12 queued 11s
created

TestController::input()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\App\Controller;
13
14
use Psr\Http\Message\ServerRequestInterface;
15
use Spiral\App\Request\BadRequest;
16
use Spiral\App\Request\TestRequest;
17
use Spiral\Filter\InputScope;
18
use Spiral\Http\PaginationFactory;
19
use Spiral\Pagination\Paginator;
20
use Spiral\Router\RouteInterface;
21
use Spiral\Translator\Traits\TranslatorTrait;
22
23
class TestController
24
{
25
    use TranslatorTrait;
26
27
    public function index(string $name = 'Dave')
28
    {
29
        return "Hello, {$name}.";
30
    }
31
32
    public function paginate(PaginationFactory $paginationFactory)
33
    {
34
        /** @var Paginator $p */
35
        $p = $paginationFactory->createPaginator('page');
36
37
        return $p->withCount(1000)->getPage();
38
    }
39
40
    public function filter(TestRequest $r)
41
    {
42
        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...
43
    }
44
45
    public function filter2(BadRequest $r): void
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

45
    public function filter2(/** @scrutinizer ignore-unused */ BadRequest $r): void

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