SoftReferenceResolverTrait::getReferenceSoft()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 3
crap 3
1
<?php
2
3
namespace LRC\Repository;
4
5
/**
6
 * Soft-deletion-aware foreign-key reference resolution.
7
 */
8 View Code Duplication
trait SoftReferenceResolverTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    use ReferenceResolverTrait;
11
    
12
    
13
    /**
14
     * Retrieve a reference by foreign key, ignoring soft-deleted entries.
15
     *
16
     * @param SoftRepositoryInterface   $repository Repository to query.
17
     * @param string                    $attr       Name of foreign key attribute.
18
     * @param string                    $key        Name of primary key attribute in referenced table.
19
     *
20
     * @return mixed                                Model instance if found, null otherwise.
21
     */
22 1
    public function getReferenceSoft($repository, $attr, $key = 'id')
23
    {
24 1
        if (isset($this->$attr)) {
25 1
            return ($repository->findSoft($key, $this->$attr) ?: null);
26
        }
27 1
        return null;
28
    }
29
}
30