Completed
Push — master ( e48405...3cf851 )
by Karl
27s
created

RecruiterFilter::filter()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 2
nop 2
crap 4
1
<?php namespace JobApis\JobsToMail\Filters;
2
3
use JobApis\JobsToMail\Models\Recruiter;
4
use JobApis\JobsToMail\Models\Search;
5
6
class RecruiterFilter
7
{
8 3
    public function __construct(Recruiter $recruiter)
9
    {
10 3
        $this->recruiter = $recruiter;
0 ignored issues
show
Bug introduced by
The property recruiter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
11 3
    }
12
13
    /**
14
     * Filters out jobs from recruiting companies if the user's prefers it.
15
     *
16
     * @param array $jobs
17
     * @param Search $search
18
     *
19
     * @return array
20
     */
21 3
    public function filter(array $jobs, Search $search)
22
    {
23
        // Make sure this search wants to filter recruiters
24 3
        if ($search->no_recruiters === true) {
25 2
            return array_filter($jobs, function ($job) {
26
                // Make sure this job has a company
27 2
                if (isset($job->company)) {
28
                    // Make sure this company is not a recruiter
29 1
                    if ($this->recruiter->whereNameLike($job->company)->first()) {
30 1
                        return false;
31
                    }
32
                }
33 1
                return true;
34 2
            });
35
        }
36 1
        return $jobs;
37
    }
38
}
39