Completed
Push — master ( 36b8cd...f7ff46 )
by Andreas
02:55
created

midgard_query_builder   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 25
c 4
b 0
f 1
dl 0
loc 53
ccs 26
cts 28
cp 0.9286
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add_constraint_with_property() 0 8 2
A execute() 0 6 1
A add_constraint() 0 8 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(string $name, string $operator, string $property) : bool
14
    {
15
        try {
16 1
            parent::add_constraint_with_property($name, $operator, $property);
17
        } catch (exception $e) {
18
            return false;
19
        }
20 1
        return true;
21
    }
22
23 48
    public function add_constraint(string $name, string $operator, $value) : bool
24
    {
25
        try {
26 48
            parent::add_constraint($name, $operator, $value);
27 2
        } catch (exception $e) {
28 2
            return false;
29
        }
30 46
        return true;
31
    }
32
33
    /**
34
     * @return midgard\portable\api\mgdobject[]
35
     */
36 36
    public function execute()
37
    {
38 36
        $query = $this->prepare_query();
39 36
        $result = $query->getResult();
40 36
        $this->post_execution();
41 36
        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->iterate();
51 1
        $this->post_execution();
52 1
        foreach ($resultset as $result) {
53 1
            $this->qb->getEntityManager()->detach($result[0]);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\EntityManager::detach() has been deprecated: 2.7 This method is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

53
            /** @scrutinizer ignore-deprecated */ $this->qb->getEntityManager()->detach($result[0]);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
54 1
            yield $result[0];
55
        }
56 1
    }
57
58 37
    private function prepare_query() : \Doctrine\ORM\Query
59
    {
60 37
        $this->check_groups();
61 37
        $this->qb->addSelect('c');
62 37
        $this->pre_execution();
63 37
        return $this->qb->getQuery();
64
    }
65
}
66