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

RecruiterFilter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filter() 0 17 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