Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Controller/Admin/Main/ActionSearch.php (3 issues)

Checks if the types of the passed arguments in a function/method call are compatible.

Bug Minor
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
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...
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
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, [
38
            'model' => $model
39
        ]);
40
41
        return $this->view->render('main/search', [
42
            'model' => $model
43
        ]);
44
    }
45
}