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

RecordQuery::setRawQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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