Passed
Push — master ( 3a195a...0456bd )
by Mihail
06:35
created

ActionSearch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A search() 0 14 4
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
6
use Apps\Model\Admin\Main\CollectionSearchResults;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\ForbiddenException;
10
use Ffcms\Core\Helper\Type\Any;
11
use Ffcms\Core\Helper\Type\Str;
12
use Ffcms\Core\Network\Request;
13
use Ffcms\Core\Network\Response;
14
15
/**
16
 * Trait ActionSearch
17
 * @package Apps\Controller\Admin\Main
18
 * @property Request $request
19
 * @property Response $response
20
 * @property View $view
21
 */
22
trait ActionSearch
23
{
24
    /**
25
     * Process search action
26
     * @return string|null
27
     * @throws ForbiddenException
28
     */
29
    public function search(): ?string
30
    {
31
        $query = App::$Security->strip_tags($this->request->query->get('search'), null);
32
        if (!Any::isStr($query) || Str::likeEmpty($query) || Str::length($query) > static::SEARCH_QUERY_MAX_LENGTH) {
0 ignored issues
show
Bug introduced by zenn
The constant Apps\Controller\Admin\Ma...SEARCH_QUERY_MAX_LENGTH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by zenn
It seems like $query can also be of type array; however, parameter $string of Ffcms\Core\Helper\Type\Str::length() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

32
        if (!Any::isStr($query) || Str::likeEmpty($query) || Str::length(/** @scrutinizer ignore-type */ $query) > static::SEARCH_QUERY_MAX_LENGTH) {
Loading history...
Bug introduced by zenn
It seems like $query can also be of type array; however, parameter $string of Ffcms\Core\Helper\Type\Str::likeEmpty() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

32
        if (!Any::isStr($query) || Str::likeEmpty(/** @scrutinizer ignore-type */ $query) || Str::length($query) > static::SEARCH_QUERY_MAX_LENGTH) {
Loading history...
33
            throw new ForbiddenException(__('Wrong query format'));
34
        }
35
36
        $model = new CollectionSearchResults($query, 10);
0 ignored issues
show
Bug introduced by zenn
It seems like $query can also be of type array and null; however, parameter $query of Apps\Model\Admin\Main\Co...hResults::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

36
        $model = new CollectionSearchResults(/** @scrutinizer ignore-type */ $query, 10);
Loading history...
37
        App::$Event->run(static::SEARCH_EVENT_NAME, [
0 ignored issues
show
Bug introduced by zenn
The constant Apps\Controller\Admin\Ma...arch::SEARCH_EVENT_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
            'model' => $model
39
        ]);
40
41
        return $this->view->render('main/search', [
42
            'model' => $model
43
        ]);
44
    }
45
}