Passed
Branch master (249862)
by Adam
07:51
created

FbController::showByCategory()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 0
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
namespace Coyote\Http\Controllers\Job;
4
5
use Coyote\Http\Controllers\Controller;
6
use Coyote\Repositories\Contracts\JobRepositoryInterface as JobRepository;
7
use Coyote\Repositories\Contracts\TagRepositoryInterface as TagRepository;
8
use Coyote\Services\Elasticsearch\Builders\Job\FbBuilder;
9
use Coyote\Tag;
10
11
class FbController extends Controller
12
{
13
    /**
14
     * @var JobRepository
15
     */
16
    private $job;
17
18
    /**
19
     * @var TagRepository
20
     */
21
    private $tag;
22
23
    /**
24
     * @param TagRepository $tag
25
     * @param JobRepository $job
26
     */
27
    public function __construct(TagRepository $tag, JobRepository $job)
28
    {
29
        parent::__construct();
30
31
        $this->tag = $tag;
32
        $this->job = $job;
33
    }
34
35
    /**
36
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
37
     */
38
    public function showByCategory()
39
    {
40
        $tags = $this->tag->findAllBy('category_id', Tag\Category::LANGUAGE);
41
        $result = $hashTags = $count = [];
42
43
        foreach ($tags as $tag) {
44
            $builder = new FbBuilder();
45
            $builder->setLanguage($tag->name);
46
            $builder->onlyFromLastWeek();
47
48
            $source = $this->job->search($builder)->getSource();
0 ignored issues
show
Bug introduced by
The method search() does not exist on Coyote\Repositories\Cont...\JobRepositoryInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Coyote\Repositories\Cont...\JobRepositoryInterface. ( Ignorable by Annotation )

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

48
            $source = $this->job->/** @scrutinizer ignore-call */ search($builder)->getSource();
Loading history...
49
50
            if ($source) {
51
                $hashTags[] = '#' . $tag->name;
52
53
                $result[$tag->real_name] = $source;
54
                $count[$tag->real_name] = count($result[$tag->real_name]);
55
            }
56
        }
57
58
        array_multisort($count, SORT_DESC, $result);
59
60
        return view('job.fb_category', ['hash_tags' => $hashTags, 'result' => $result]);
61
    }
62
63
    /**
64
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
65
     */
66
    public function showByKeyword()
67
    {
68
        $builder = new FbBuilder();
69
        $builder->setLanguage($this->request->input('q'));
0 ignored issues
show
Bug introduced by
$this->request->input('q') of type array is incompatible with the type string expected by parameter $query of Coyote\Services\Elastics...bBuilder::setLanguage(). ( Ignorable by Annotation )

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

69
        $builder->setLanguage(/** @scrutinizer ignore-type */ $this->request->input('q'));
Loading history...
70
71
        $source = $this->job->search($builder)->getSource();
72
        $result = [];
73
74
        foreach ($source as $job) {
75
            foreach ($job->get('locations') as $location) {
76
                $result[$location->get('city')][] = $job;
77
            }
78
        }
79
80
        return view('job.fb_keyword', ['result' => $result]);
81
    }
82
}
83