Completed
Push — master ( be2cb9...8e4010 )
by Michael
9s
created

action_plugin_prosemirror_parser   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
dl 0
loc 58
rs 10
c 4
b 1
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
C handle_preprocess() 0 32 8
1
<?php
2
/**
3
 * DokuWiki Plugin prosemirror (Action Component)
4
 *
5
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6
 * @author  Andreas Gohr <[email protected]>
7
 */
8
9
// must be run within Dokuwiki
10
use dokuwiki\plugin\prosemirror\parser\SyntaxTreeBuilder;
11
12
if (!defined('DOKU_INC')) {
13
    die();
14
}
15
16
class action_plugin_prosemirror_parser extends DokuWiki_Action_Plugin
1 ignored issue
show
Bug introduced by
The type DokuWiki_Action_Plugin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
{
18
19
    /**
20
     * Registers a callback function for a given event
21
     *
22
     * @param Doku_Event_Handler $controller DokuWiki's event controller object
23
     *
24
     * @return void
25
     */
26
    public function register(Doku_Event_Handler $controller)
1 ignored issue
show
Bug introduced by
The type Doku_Event_Handler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
    {
28
        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_preprocess');
29
    }
30
31
    /**
32
     * [Custom event handler which performs action]
33
     *
34
     * Triggered by: ACTION_ACT_PREPROCESS
35
     *
36
     * @param Doku_Event $event  event object by reference
37
     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
38
     *                           handler was registered]
39
     *
40
     * @return void
41
     */
42
    public function handle_preprocess(Doku_Event $event, $param)
1 ignored issue
show
Bug introduced by
The type Doku_Event was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
    {
44
        global $TEXT, $INPUT;
45
        if ($INPUT->server->str('REQUEST_METHOD') !== 'POST'
46
            || !in_array($event->data, ['save', 'preview'])
47
            || !$INPUT->post->has('prosemirror_json')
48
        ) {
49
            return;
50
        }
51
52
        $unparsedJSON = $INPUT->post->str('prosemirror_json');
53
        if (json_decode($unparsedJSON, true) === null) {
54
            msg('Error decoding prosemirror data', -1);
1 ignored issue
show
Bug introduced by
The function msg was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

54
            /** @scrutinizer ignore-call */ 
55
            msg('Error decoding prosemirror data', -1);
Loading history...
55
            return;
56
        }
57
        try {
58
            $rootNode = SyntaxTreeBuilder::parseJsonIntoTree($unparsedJSON);
59
        } catch (Throwable $e) {
60
            $errorMsg = 'Parsing the data provided by the WYSIWYG editor failed with message: ' . hsc($e->getMessage());
1 ignored issue
show
Bug introduced by
The function hsc was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

60
            $errorMsg = 'Parsing the data provided by the WYSIWYG editor failed with message: ' . /** @scrutinizer ignore-call */ hsc($e->getMessage());
Loading history...
61
            /** @var helper_plugin_sentry $sentry */
62
            $sentry = plugin_load('helper', 'sentry');
1 ignored issue
show
Bug introduced by
The function plugin_load was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

62
            $sentry = /** @scrutinizer ignore-call */ plugin_load('helper', 'sentry');
Loading history...
63
            if ($sentry) {
0 ignored issues
show
introduced by
$sentry is of type helper_plugin_sentry, thus it always evaluated to true. If $sentry can have other possible types, add them to action/parser.php:61
Loading history...
64
                $sentry->logException($e);
65
                $errorMsg .= ' Error has been logged to Sentry.';
66
            }
67
68
            msg($errorMsg, -1);
69
            return;
70
        }
71
        $syntax = $rootNode->toSyntax();
72
        if (!empty($syntax)) {
73
            $TEXT = $syntax;
74
        }
75
    }
76
}
77
78
// vim:ts=4:sw=4:et:
79