midgard_query_builder::execute()   A
last analyzed

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
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
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(string $name, string $operator, string $property) : bool
14
    {
15
        try {
16 1
            parent::add_constraint_with_property($name, $operator, $property);
17
        } catch (exception) {
18
            return false;
19
        }
20 1
        return true;
21
    }
22
23 49
    public function add_constraint(string $name, string $operator, $value) : bool
24
    {
25
        try {
26 49
            parent::add_constraint($name, $operator, $value);
27 2
        } catch (exception) {
28 2
            return false;
29
        }
30 47
        return true;
31
    }
32
33
    /**
34
     * @return midgard\portable\api\mgdobject[]
35
     */
36 37
    public function execute()
37
    {
38 37
        $query = $this->prepare_query();
39 37
        $result = $query->getResult();
40 37
        $this->post_execution();
41 37
        return $result;
42
    }
43
44
    /**
45
     * @return midgard\portable\api\mgdobject[]
46
     */
47 1
    public function iterate()
48
    {
49 1
        $query = $this->prepare_query();
50 1
        $resultset = $query->toIterable();
51 1
        $this->post_execution();
52 1
        foreach ($resultset as $result) {
53 1
            $this->qb->getEntityManager()->detach($result);
54 1
            yield $result;
55
        }
56
    }
57
58 38
    private function prepare_query() : \Doctrine\ORM\Query
59
    {
60 38
        $this->check_groups();
61 38
        $this->qb->addSelect('c');
62 38
        $this->pre_execution();
63 38
        return $this->qb->getQuery();
64
    }
65
}
66