Passed
Push — master ( 8bbdf4...6cccb4 )
by Andreas
10:01
created

org_openpsa_invoices_interface   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 38
ccs 6
cts 18
cp 0.3333
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve_object_link() 0 6 2
A _on_reindex() 0 9 1
A _on_watched_dba_delete() 0 10 2
1
<?php
2
/**
3
 * @package org.openpsa.invoices
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
use midcom\datamanager\datamanager;
10
11
/**
12
 * Invoice management MidCOM interface class.
13
 *
14
 * @package org.openpsa.invoices
15
 */
16
class org_openpsa_invoices_interface extends midcom_baseclasses_components_interface
17
implements midcom_services_permalinks_resolver
18
{
19
    public function resolve_object_link(midcom_db_topic $topic, midcom_core_dbaobject $object) : ?string
20
    {
21
        if ($object instanceof org_openpsa_invoices_invoice_dba) {
22
            return "invoice/{$object->guid}/";
23
        }
24
        return null;
25
    }
26
27
    /**
28
     * Handle deletes of "parent" objects
29
     */
30 11
    public function _on_watched_dba_delete(midcom_core_dbaobject $object)
31
    {
32 11
        midcom::get()->auth->request_sudo($this->_component);
33 11
        $qb = org_openpsa_invoices_billing_data_dba::new_query_builder();
34 11
        $qb->add_constraint('linkGuid', '=', $object->guid);
35 11
        foreach ($qb->execute() as $billing_data) {
36
            debug_add("Delete billing data with guid:" . $billing_data->guid . " for object with guid:" . $object->guid);
37
            $billing_data->delete();
38
        }
39 11
        midcom::get()->auth->drop_sudo();
40
    }
41
42
    /**
43
     * Prepare the indexer client
44
     */
45
    public function _on_reindex($topic, midcom_helper_configuration $config, midcom_services_indexer $indexer)
46
    {
47
        $qb = org_openpsa_invoices_invoice_dba::new_query_builder();
48
        $dm = datamanager::from_schemadb($config->get('schemadb'));
0 ignored issues
show
Bug introduced by
It seems like $config->get('schemadb') can also be of type false; however, parameter $path of midcom\datamanager\datamanager::from_schemadb() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

48
        $dm = datamanager::from_schemadb(/** @scrutinizer ignore-type */ $config->get('schemadb'));
Loading history...
49
50
        $indexer = new org_openpsa_invoices_midcom_indexer($topic, $indexer);
51
        $indexer->add_query('invoices', $qb, $dm);
52
53
        return $indexer;
54
    }
55
}
56