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

Apps/Model/Front/Search/SearchComments.php (1 issue)

Checks if used types are declared or listed as dependencies.

Bug Major
1
<?php
2
3
namespace Apps\Model\Front\Search;
4
5
use Apps\ActiveRecord\CommentPost;
6
use Apps\Model\Front\Search\Interfaces\SearchContainer;
0 ignored issues
show
The type Apps\Model\Front\Search\Interfaces\SearchContainer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\Model;
9
use Ffcms\Core\Helper\Text;
10
11
/**
12
 * Class SearchComments. Search instance for comments text.
13
 * @package Apps\Model\Front\Search
14
 */
15
class SearchComments extends Model implements SearchContainer
16
{
17
    private $query;
18
    private $limit;
19
20
    /**
21
     * SearchContainer constructor. Pass string query inside
22
     * @param string $query
23
     * @param int $limit
24
     */
25
    public function __construct($query, $limit = 10)
26
    {
27
        $this->query = $query;
28
        $this->limit = (int)$limit;
29
        if ($this->limit < 1) {
30
            $this->limit = 1;
31
        }
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Build search results. Should return array collection: [AbstractSearchResult]
37
     * @return array
38
     */
39
    public function getResult()
40
    {
41
        // search in comments post
42
        $query = CommentPost::search($this->query)
43
            ->where('moderate', '=', 0)
44
            ->take($this->limit)
45
            ->get();
46
47
        // check if response is empty
48
        if ($query->count() < 1) {
49
            return [];
50
        }
51
52
        // build output
53
        $result = [];
54
        foreach ($query as $item) {
55
            /** @var CommentPost $item */
56
            $snippet = App::$Security->strip_tags($item->message);
57
            $snippet = Text::snippet($snippet);
58
59
            // make unique instance object
60
            $instance = new AbstractSearchResult();
61
            $instance->setTitle(App::$Translate->get('Search', 'Comment on the page'));
62
            $instance->setSnippet($snippet);
63
            $instance->setUri($item->pathway . '#comments-list');
64
            $instance->setDate($item->created_at);
65
            $instance->setRelevance((int)$item->relevance);
66
67
            // add instance to result set
68
            $result[] = $instance;
69
        }
70
71
        return $result;
72
    }
73
}
74