EntityFetcherMock   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A one() 0 8 2
A count() 0 4 1
1
<?php
2
3
namespace ORM\Testing;
4
5
use ORM\EntityFetcher;
6
7
class EntityFetcherMock extends EntityFetcher
8
{
9
    /** @var array */
10
    protected $currentResult;
11
12
    /** @var EntityManagerMock */
13
    public $entityManager;
14
15
    /** {@inheritDoc} */
16
    public function one()
17
    {
18
        if ($this->currentResult === null) {
19
            $this->currentResult = $this->entityManager->getResults($this->class, $this);
0 ignored issues
show
Bug introduced by
It seems like $this->class can also be of type object<ORM\Entity>; however, ORM\Testing\EntityManagerMock::getResults() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
20
        }
21
22
        return array_shift($this->currentResult);
23
    }
24
25
    /** {@inheritDoc} */
26
    public function count()
27
    {
28
        return count($this->entityManager->getResults($this->class, $this));
0 ignored issues
show
Bug introduced by
It seems like $this->class can also be of type object<ORM\Entity>; however, ORM\Testing\EntityManagerMock::getResults() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
29
    }
30
}
31