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

midgard_query_builder   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 92.59%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 51
ccs 25
cts 27
cp 0.9259
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add_constraint_with_property() 0 6 2
A execute() 0 6 1
A add_constraint() 0 6 2
A iterate() 0 8 2
A prepare_query() 0 6 1
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