Passed
Pull Request — master (#643)
by Mathias
07:17
created

InternalReferences::setJobsManagers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright https://yawik.org/COPYRIGHT.php
7
 * @license   MIT
8
 */
9
10
/** InternalReferences.php */
11
namespace Applications\Entity;
12
13
use Auth\Entity\UserInterface;
14
use Jobs\Entity\JobInterface;
15
use Core\Entity\AbstractEntity;
16
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
17
18
/**
19
 * @ODM\EmbeddedDocument
20
 */
21
class InternalReferences extends AbstractEntity
22
{
23
24
    /** @ODM\Field(type="hash") */
25
    protected $jobs = array();
26
27 3
    /**
28
     * @ODM\Field(type="collection")
29 3
     * @var array
30
     */
31
    protected $jobManagers = [];
32
33 3
    public function setJob(JobInterface $job)
34 3
    {
35 3
        if (isset($this->jobs['__id__']) && $this->jobs['__id__'] == $job->getId()) {
36
            return $this;
37 3
        }
38
39
        $this->jobs = array(
40
            '__id__' => $job->getId(),
41
            'userId' => ($user = $job->getUser()) ? $user->getId() : null,
42
        );
43
        $this->setJobsManagers($job->getMetaData('organizations:managers', []));
0 ignored issues
show
Unused Code introduced by
The call to Core\Entity\MetaDataProv...nterface::getMetaData() has too many arguments starting with array(). ( Ignorable by Annotation )

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

43
        $this->setJobsManagers($job->/** @scrutinizer ignore-call */ getMetaData('organizations:managers', []));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
44
        return $this;
45
    }
46
47
    public function setJobsId($id)
48
    {
49
        $this->jobs['__id__'] = $id;
50
        return $this;
51
    }
52
53
    public function setJobsUserId($userOrId)
54
    {
55
        if ($userOrId instanceof UserInterface) {
56
            $userOrId = $userOrId->getId();
57
        }
58
        $this->jobs['userId'] = $userOrId;
59
        return $this;
60
    }
61
62
    public function setJobsManagers($managers)
63
    {
64
        $this->jobManagers = $managers;
65
        return $this;
66
    }
67
}
68