Completed
Push — master ( 72c7b6...2e4b99 )
by
unknown
16s queued 11s
created

RecordQuery   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 63
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getRawQuery() 0 4 1
A setRawQuery() 0 5 1
A getQueryType() 0 4 1
A execute() 0 14 4
1
<?php
2
3
namespace Alchemy\Phraseanet\Query;
4
5
use PhraseanetSDK\Repository\Record;
6
use PhraseanetSDK\Repository\Story;
7
8
class RecordQuery
9
{
10
11
    private $type = 0;
12
13
    private $query;
14
15
    /**
16
     * @param array $query
17
     * @param $type
18
     */
19 32
    public function __construct(array $query, $type)
20
    {
21 32
        $this->query = $query;
22 32
        $this->type = intval($type);
23 32
    }
24
25
    /**
26
     * @return array
27
     */
28 28
    public function getRawQuery()
29
    {
30 28
        return $this->query;
31
    }
32
33
	/**
34
	 * @param array $query
35
	 * @return RecordQuery
36 1
	 */
37
	public function setRawQuery($query)
38 1
	{
39
		$this->query = $query;
40
		return $this;
41
	}
42
43
    /**
44
     * @return int
45 4
     */
46
    public function getQueryType()
47 4
    {
48 4
        return $this->type;
49
    }
50
51
    /**
52
     * @param $repository
53
	 * @param int $pAPINumber API number (e.g. 3)
54
     * @return \Doctrine\Common\Collections\ArrayCollection
55
     */
56
    public function execute($repository, $pAPINumber = 1)
57
    {
58
        if (! $repository instanceof Record && ! $repository instanceof Story) {
59
            throw new \InvalidArgumentException('Invalid repository type (story or record required).');
60
        }
61
62
        $result = $repository->search($this->query, $pAPINumber);
0 ignored issues
show
Unused Code introduced by
The call to Record::search() has too many arguments starting with $pAPINumber.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to Story::search() has too many arguments starting with $pAPINumber.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
63
64
        if ($this->type == 1) {
65
            return $result->getResults()->getStories();
66
        }
67
68
        return $result->getResults()->getRecords();
69
    }
70
}
71