Passed
Push — master ( 420639...4ea9f2 )
by Andreas
11:06
created

midgard_admin_asgard_handler_object_rcs   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 57.89%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 46
ccs 11
cts 19
cp 0.5789
rs 10
c 4
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get_breadcrumbs() 0 4 2
A load_object() 0 11 4
A reply() 0 3 1
A get_object_url() 0 3 1
A _on_initialize() 0 5 1
1
<?php
2
/**
3
 * @author tarjei huse
4
 * @package midgard.admin.asgard
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 Symfony\Component\HttpFoundation\Response;
10
use midgard\portable\api\error\exception as mgd_exception;
11
12
/**
13
 * Simple styling class to make html out of diffs and get a simple way
14
 * to provide rcs functionality
15
 *
16
 * @package midgard.admin.asgard
17
 */
18
class midgard_admin_asgard_handler_object_rcs extends midcom_services_rcs_handler
19
{
20
    use midgard_admin_asgard_handler;
0 ignored issues
show
introduced by
The trait midgard_admin_asgard_handler requires some properties which are not provided by midgard_admin_asgard_handler_object_rcs: $dbclassloader, $dbfactory
Loading history...
21
22
    protected string $style_prefix = 'midgard_admin_asgard_rcs_';
23
24
    protected string $url_prefix = '__mfa/asgard/object/rcs/';
25
26 3
    protected function load_object(string $guid) : midcom_core_dbaobject
27
    {
28
        try {
29 3
            return parent::load_object($guid);
30
        } catch (midcom_error_midgard $e) {
31
            $mgd_exception = $e->getPrevious();
32
            if (   $mgd_exception
33
                && $mgd_exception->getCode() == mgd_exception::OBJECT_DELETED) {
34
                return $this->load_deleted($guid);
35
            }
36
            throw $e;
37
        }
38
    }
39
40
    protected function get_object_url() : string
41
    {
42
        return $this->router->generate('object_open', ['guid' => $this->object->guid]);
43
    }
44
45 3
    protected function get_breadcrumbs() : array
46
    {
47 3
        midgard_admin_asgard_plugin::bind_to_object($this->object, $this->_request_data['handler_id'], $this->_request_data);
48 3
        return midcom_core_context::get()->get_custom_key('midcom.helper.nav.breadcrumb') ?: [];
49
    }
50
51 3
    protected function reply(string $element) : Response
52
    {
53 3
        return $this->get_response($element);
54
    }
55
56
    /**
57
     * Load l10n
58
     */
59 3
    public function _on_initialize()
60
    {
61 3
        midcom::get()->auth->require_user_do('midgard.admin.asgard:manage_objects', null, 'midgard_admin_asgard_plugin');
62 3
        $this->_component = 'midcom.admin.rcs';
63 3
        $this->_request_data['l10n'] = $this->_i18n->get_l10n('midcom.admin.rcs');
64
    }
65
}
66