Passed
Branch master (e751cb)
by Matt
02:48
created

bbcodes_help::faq()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 45
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 37
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 36
nc 2
nop 0
dl 0
loc 45
ccs 37
cts 37
cp 1
crap 3
rs 9.344
c 1
b 0
f 0
1
<?php
2
/**
3
 *
4
 * Advanced BBCode Box
5
 *
6
 * @copyright (c) 2017 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\abbc3\core;
12
13
use phpbb\db\driver\driver_interface;
0 ignored issues
show
Bug introduced by
The type phpbb\db\driver\driver_interface 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...
14
use phpbb\language\language;
0 ignored issues
show
Bug introduced by
The type phpbb\language\language 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...
15
use phpbb\template\template;
0 ignored issues
show
Bug introduced by
The type phpbb\template\template 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...
16
use phpbb\user;
0 ignored issues
show
Bug introduced by
The type phpbb\user 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
 * ABBC3 core BBCodes parser class
20
 */
21
class bbcodes_help
22
{
23
	/** @var driver_interface */
24
	protected $db;
25
26
	/** @var language */
27
	protected $language;
28
29
	/** @var template */
30
	protected $template;
31
32
	/** @var user */
33
	protected $user;
34
35
	/** @var bbcodes_display */
36
	private $bbcodes_display;
37
38
	/**
39
	 * Constructor
40
	 *
41
	 * @param bbcodes_display  $bbcodes_display
42
	 * @param driver_interface $db
43
	 * @param language         $language
44
	 * @param template         $template
45
	 * @param user             $user
46
	 */
47
	public function __construct(bbcodes_display $bbcodes_display, driver_interface $db, language $language, template $template, user $user)
48 2
	{
49
		$this->bbcodes_display = $bbcodes_display;
50 2
		$this->db = $db;
51 2
		$this->language = $language;
52 2
		$this->template = $template;
53 2
		$this->user = $user;
54 2
	}
55 2
56
	/**
57
	 * Generate BBCode help FAQ for ABBC3's custom BBCodes
58
	 */
59
	public function faq()
60 2
	{
61
		// Set the block template data
62
		$this->template->assign_block_vars('faq_block', [
63 2
			'BLOCK_TITLE'	=> $this->language->lang('ABBC3_FAQ_TITLE'),
64 2
			'SWITCH_COLUMN'	=> false,
65 2
		]);
66 2
67
		$example_text = $this->language->lang('ABBC3_FAQ_SAMPLE_TEXT');
68 2
		$abbc3_faq_data = array_intersect_key([
69 2
			'ABBC3_FONT_HELPLINE'		=> "[font=Comic Sans MS]{$example_text}[/font]",
70 2
			'ABBC3_HIGHLIGHT_HELPLINE'	=> "[highlight=yellow]{$example_text}[/highlight]",
71 2
			'ABBC3_ALIGN_HELPLINE'		=> "[align=center]{$example_text}[/align]",
72 2
			'ABBC3_FLOAT_HELPLINE'		=> "[float=right]{$example_text}[/float]",
73 2
			'ABBC3_STRIKE_HELPLINE'		=> "[s]{$example_text}[/s]",
74 2
			'ABBC3_SUB_HELPLINE'		=> "[sub]{$example_text}[/sub] {$example_text}",
75 2
			'ABBC3_SUP_HELPLINE'		=> "[sup]{$example_text}[/sup] {$example_text}",
76 2
			'ABBC3_GLOW_HELPLINE'		=> "[glow=red]{$example_text}[/glow]",
77 2
			'ABBC3_SHADOW_HELPLINE'		=> "[shadow=blue]{$example_text}[/shadow]",
78 2
			'ABBC3_DROPSHADOW_HELPLINE'	=> "[dropshadow=blue]{$example_text}[/dropshadow]",
79 2
			'ABBC3_BLUR_HELPLINE'		=> "[blur=blue]{$example_text}[/blur]",
80 2
			'ABBC3_FADE_HELPLINE'		=> "[fade]{$example_text}[/fade]",
81 2
			'ABBC3_PREFORMAT_HELPLINE'	=> "[pre]{$example_text}\n\t{$example_text}[/pre]",
82 2
			'ABBC3_DIR_HELPLINE'		=> "[dir=rtl]{$example_text}[/dir]",
83 2
			'ABBC3_MARQUEE_HELPLINE'	=> "[marq=left]{$example_text}[/marq]",
84 2
			'ABBC3_SPOILER_HELPLINE'	=> "[spoil]{$example_text}[/spoil]",
85 2
			'ABBC3_HIDDEN_HELPLINE'		=> "[hidden]{$example_text}[/hidden]",
86 2
			'ABBC3_MOD_HELPLINE'		=> "[mod={$this->language->lang('USERNAME')}]{$example_text}[/mod]",
87 2
			'ABBC3_OFFTOPIC_HELPLINE'	=> "[offtopic]{$example_text}[/offtopic]",
88 2
			'ABBC3_NFO_HELPLINE'		=> '[nfo]༼ つ ◕_◕ ༽つ    ʕ•ᴥ•ʔ   ¯\_(ツ)_/¯[/nfo]',
89 2
			'ABBC3_BBVIDEO_HELPLINE'	=> '[bbvideo]http://www.youtube.com/watch?v=sP4NMoJcFd4[/bbvideo]',
90 2
		], $this->allowed_bbcodes());
91 2
92
		// Process faq data for display as parsed and un-parsed bbcodes
93
		foreach ($abbc3_faq_data as $key => $question)
94 2
		{
95
			$uid = $bitfield = $flags = '';
96 2
			generate_text_for_storage($question, $uid, $bitfield, $flags, true);
0 ignored issues
show
Bug introduced by
The function generate_text_for_storage 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

96
			/** @scrutinizer ignore-call */ 
97
   generate_text_for_storage($question, $uid, $bitfield, $flags, true);
Loading history...
97 2
			$example = generate_text_for_edit($question, $uid, $flags);
0 ignored issues
show
Bug introduced by
The function generate_text_for_edit 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

97
			$example = /** @scrutinizer ignore-call */ generate_text_for_edit($question, $uid, $flags);
Loading history...
98 2
			$result = generate_text_for_display($question, $uid, $bitfield, $flags);
0 ignored issues
show
Bug introduced by
The function generate_text_for_display 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

98
			$result = /** @scrutinizer ignore-call */ generate_text_for_display($question, $uid, $bitfield, $flags);
Loading history...
99 2
			$title = explode(':', $this->language->lang($key), 2);
100 2
101
			$this->template->assign_block_vars('faq_block.faq_row', [
102 2
				'FAQ_QUESTION'	=> $title[0],
103 2
				'FAQ_ANSWER'	=> $this->language->lang('ABBC3_FAQ_ANSWER', (isset($title[1]) ? $title[1] : $title[0]), $example['text'], $result),
104 2
			]);
105 2
		}
106 2
	}
107 2
108
	/**
109
	 * Get custom BBCodes the current user is allowed to use
110
	 *
111
	 * @return array
112
	 */
113
	protected function allowed_bbcodes()
114 2
	{
115
		$allowed = [];
116 2
		$sql = 'SELECT bbcode_helpline, bbcode_group
117
			FROM ' . BBCODES_TABLE . '
0 ignored issues
show
Bug introduced by
The constant vse\abbc3\core\BBCODES_TABLE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
118 2
			WHERE bbcode_helpline ' . $this->db->sql_like_expression('ABBC3_' . $this->db->get_any_char()) . '
119 2
				AND display_on_posting = 1';
120 2
		$result = $this->db->sql_query($sql);
121 2
		while ($row = $this->db->sql_fetchrow($result))
122 2
		{
123
			if ($this->bbcodes_display->user_in_bbcode_group($row['bbcode_group']))
124 2
			{
125 2
				$allowed[$row['bbcode_helpline']] = true;
126 2
			}
127 2
		}
128 2
		$this->db->sql_freeresult($result);
129 2
130
		return $allowed;
131 2
	}
132
}
133