Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

ckeditor_init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * CKEditor wysiwyg editor
4
 *
5
 * @package ElggCKEditor
6
 */
7
8
/**
9
 * CKEditor init
10
 *
11
 * @return void
12
 */
13
function ckeditor_init() {
14 31
	elgg_extend_view('elgg.css', 'ckeditor.css');
15 31
	elgg_extend_view('admin.css', 'ckeditor.css');
16
17 31
	elgg_extend_view('elgg/wysiwyg.css', 'elements/reset.css', 100);
18 31
	elgg_extend_view('elgg/wysiwyg.css', 'elements/typography.css', 100);
19
20 31
	elgg_define_js('ckeditor/ckeditor', [
21 31
		'exports' => 'CKEDITOR',
22
	]);
23 31
	elgg_define_js('jquery.ckeditor', [
24 31
		'deps' => ['jquery', 'ckeditor/ckeditor'],
25
		'exports' => 'jQuery.fn.ckeditor',
26
	]);
27
28 31
	elgg_extend_view('input/longtext', 'ckeditor/init');
29
30 31
	elgg_register_plugin_hook_handler('register', 'menu:longtext', 'ckeditor_longtext_menu');
31 31
	elgg_register_plugin_hook_handler('view_vars', 'input/longtext', 'ckeditor_longtext_id');
32 31
}
33
34
/**
35
 * Add a menu item to an longtext
36
 *
37
 * @param string         $hook  'register'
38
 * @param string         $type  'menu:longtext'
39
 * @param ElggMenuItem[] $items current return value
40
 * @param array          $vars  supplied params
41
 *
42
 * @return void|ElggMenuItem[]
43
 */
44
function ckeditor_longtext_menu($hook, $type, $items, $vars) {
2 ignored issues
show
Unused Code introduced by Sem
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

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

44
function ckeditor_longtext_menu($hook, /** @scrutinizer ignore-unused */ $type, $items, $vars) {

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

Loading history...
Unused Code introduced by Sem
The parameter $hook is not used and could be removed. ( Ignorable by Annotation )

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

44
function ckeditor_longtext_menu(/** @scrutinizer ignore-unused */ $hook, $type, $items, $vars) {

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

Loading history...
45
46
	$id = elgg_extract('textarea_id', $vars);
47
	if ($id === null) {
48
		return;
49
	}
50
	
51
	$items[] = ElggMenuItem::factory([
52
		'name' => 'ckeditor_toggler',
53
		'link_class' => 'ckeditor-toggle-editor elgg-longtext-control hidden',
54
		'href' => "#{$id}",
55
		'text' => elgg_echo('ckeditor:html'),
56
	]);
57
58
	return $items;
59
}
60
61
/**
62
 * Set an id on input/longtext
63
 *
64
 * @param string $hook   'view_vars'
65
 * @param string $type   'input/longtext'
66
 * @param array  $vars   current return value
67
 * @param array  $params supplied params
68
 *
69
 * @return void|array
70
 */
71
function ckeditor_longtext_id($hook, $type, $vars, $params) {
3 ignored issues
show
Unused Code introduced by Jeroen Dalsem
The parameter $hook is not used and could be removed. ( Ignorable by Annotation )

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

71
function ckeditor_longtext_id(/** @scrutinizer ignore-unused */ $hook, $type, $vars, $params) {

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

Loading history...
Unused Code introduced by Jerôme Bakker
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

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

71
function ckeditor_longtext_id($hook, $type, $vars, /** @scrutinizer ignore-unused */ $params) {

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

Loading history...
Unused Code introduced by Jeroen Dalsem
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

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

71
function ckeditor_longtext_id($hook, /** @scrutinizer ignore-unused */ $type, $vars, $params) {

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

Loading history...
72
73
	$id = elgg_extract('id', $vars);
74
	if ($id !== null) {
75
		return;
76
	}
77
	
78
	// input/longtext view vars need to contain an id for editors to be initialized
79
	// random id generator is the same as in input/longtext
80
	$vars['id'] = 'elgg-input-' . base_convert(mt_rand(), 10, 36);
0 ignored issues
show
Bug introduced by Jerôme Bakker
The call to mt_rand() has too few arguments starting with min. ( Ignorable by Annotation )

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

80
	$vars['id'] = 'elgg-input-' . base_convert(/** @scrutinizer ignore-call */ mt_rand(), 10, 36);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
81
82
	return $vars;
83
}
84
85
return function() {
86 18
	elgg_register_event_handler('init', 'system', 'ckeditor_init');
87
};
88