Passed
Branch master (056094)
by Andreas
04:47
created

midgard_query_builder::prepare_query()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
1
<?php
2
/**
3
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
4
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
6
 */
7
8
use midgard\portable\query;
9
use midgard\portable\api\error\exception;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, exception. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
11
class midgard_query_builder extends query
12
{
13 1
    public function add_constraint_with_property($name, $operator, $value)
14
    {
15
        try {
16 1
            return parent::add_constraint_with_property($name, $operator, $value);
17
        } catch (exception $e) {
18
            return false;
19
        }
20
    }
21
22 48
    public function add_constraint($name, $operator, $value)
23
    {
24
        try {
25 48
            return parent::add_constraint($name, $operator, $value);
26 1
        } catch (exception $e) {
27 1
            return false;
28
        }
29
    }
30
31
    /**
32
     * @return midgard\portable\api\mgdobject[]
33
     */
34 36
    public function execute()
35
    {
36 36
        $query = $this->prepare_query();
37 36
        $result = $query->getResult();
38 36
        $this->post_execution();
39 36
        return $result;
40
    }
41
42
    /**
43
     * @return midgard\portable\api\mgdobject[]
44
     */
45 1
    public function iterate()
46
    {
47 1
        $query = $this->prepare_query();
48 1
        $resultset = $query->iterate();
49 1
        $this->post_execution();
50 1
        foreach ($resultset as $result) {
51 1
            $this->qb->getEntityManager()->detach($result[0]);
52 1
            yield $result[0];
53 1
        }
54 1
    }
55
56 37
    private function prepare_query()
57
    {
58 37
        $this->check_groups();
59 37
        $this->qb->addSelect('c');
60 37
        $this->pre_execution();
61 37
        return $this->qb->getQuery();
62
    }
63
}
64