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

Apps/Model/Front/Search/SearchComments.php (2 issues)

Checks if undeclared accessed properties appear in database migrations and if those migrations are correct.

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;
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');
0 ignored issues
show
The property pathway does not seem to exist on Apps\ActiveRecord\CommentPost. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
64
            $instance->setDate($item->created_at);
65
            $instance->setRelevance((int)$item->relevance);
0 ignored issues
show
The property relevance does not seem to exist on Apps\ActiveRecord\CommentPost. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
66
67
            // add instance to result set
68
            $result[] = $instance;
69
        }
70
71
        return $result;
72
    }
73
}
74