RecruiterFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 33
ccs 11
cts 11
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 5
1
<?php namespace JobApis\JobsToMail\Filters;
2
3
use JobApis\Jobs\Client\Job;
4
use JobApis\JobsToMail\Models\Recruiter;
5
use JobApis\JobsToMail\Models\Search;
6
7
class RecruiterFilter
8
{
9 3
    public function __construct(Recruiter $recruiter)
10
    {
11 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...
12 3
    }
13
14
    /**
15
     * Filters out jobs from recruiting companies if the user prefers it.
16
     *
17
     * @param array $jobs
18
     * @param Search $search
19
     *
20
     * @return array
21
     */
22
    public function filter(array $jobs, Search $search)
23
    {
24 3
        return array_filter($jobs, function (Job $job) use ($search) {
25
            // Make sure this job has a company
26 3
            if (isset($job->company) && $job->company) {
27
                // See if this company is not a recruiter
28 2
                if ($this->recruiter->whereNameLike($job->company)->first()) {
29 2
                    if ($search->no_recruiters === true) {
30 1
                        return false;
31
                    } else {
32 1
                        $job->setIndustry("Staffing");
33
                    }
34
                }
35
            }
36 2
            return true;
37 3
        });
38
    }
39
}
40