DMSShortcodeHandler   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 31 7
1
<?php
2
3
/**
4
 * Handles replacing `dms_document_link` shortcodes with links to the actual
5
 * document.
6
 *
7
 * @package dms
8
 */
9
class DMSShortcodeHandler
10
{
11
    public static function handle($arguments, $content, ShortcodeParser $parser, $tag, array $extra = array())
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Unused Code introduced by
The parameter $tag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
12
    {
13
        if (!empty($arguments['id'])) {
14
            $document = DMSDocument::get()->byID($arguments['id']);
15
16
            if ($document && !$document->isHidden()) {
17
                if ($content) {
18
                    return sprintf(
19
                        '<a href="%s">%s</a>',
20
                        $document->Link(),
21
                        $parser->parse($content)
22
                    );
23
                }
24
25
                if (isset($extra['element'])) {
26
                    $extra['element']->setAttribute('data-ext', $document->getExtension());
0 ignored issues
show
Bug introduced by
The method getExtension() does not exist on DataObject. Did you maybe mean getExtensionInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
27
                    $extra['element']->setAttribute('data-size', $document->getFileSizeFormatted());
28
                }
29
30
                return $document->Link();
31
            }
32
        }
33
34
        $error = ErrorPage::get()->filter('ErrorCode', '404')->First();
35
36
        if ($error) {
37
            return $error->Link();
38
        }
39
40
        return '';
41
    }
42
}
43