Test Failed
Branch master (fdda4e)
by ANTHONIUS
03:39
created

InteractsWithProfile::iHaveProfileForUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 9
c 1
b 1
f 0
nc 2
nop 3
dl 0
loc 14
rs 9.9666
1
<?php
2
3
/*
4
 * This file is part of the EOffice project.
5
 *
6
 * (c) Anthonius Munthi <https://itstoni.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace EOffice\User\Testing;
15
16
use EOffice\Contracts\User\Model\UserInterface;
17
use EOffice\User\Model\Profile;
18
19
trait InteractsWithProfile
20
{
21
    protected function iDontHaveProfileForUser(UserInterface $user)
22
    {
23
        $em      = $this->getEntityManager();
0 ignored issues
show
Bug introduced by
It seems like getEntityManager() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

23
        /** @scrutinizer ignore-call */ 
24
        $em      = $this->getEntityManager();
Loading history...
24
        $profile = $em->getRepository(Profile::class)->findOneBy([
25
            'user' => $user->getId(),
26
        ]);
27
        if (null !== $profile) {
28
            $em->remove($profile);
29
            $em->flush();
30
        }
31
    }
32
33
    protected function iHaveProfileForUser(UserInterface $user, string $nama='Nama Profile', string $jabatan = 'Staff'): Profile
0 ignored issues
show
Unused Code introduced by
The parameter $jabatan is not used and could be removed. ( Ignorable by Annotation )

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

33
    protected function iHaveProfileForUser(UserInterface $user, string $nama='Nama Profile', /** @scrutinizer ignore-unused */ string $jabatan = 'Staff'): Profile

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        $em      = $this->getEntityManager();
36
        $profile = $em->getRepository(Profile::class)
37
            ->findOneBy([
38
                'user' => $user->getId(),
39
            ]);
40
        if (null === $profile) {
41
            $profile = new Profile($nama, $user);
42
            $em->persist($profile);
43
            $em->flush();
44
        }
45
46
        return $profile;
47
    }
48
}
49