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

wizard   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 94.29%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 30
dl 0
loc 96
ccs 33
cts 35
cp 0.9429
rs 10
c 5
b 0
f 0
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A bbcode_wizard() 0 14 4
A generate_bbvideo_wizard() 0 26 6
1
<?php
2
/**
3
 *
4
 * Advanced BBCode Box
5
 *
6
 * @copyright (c) 2013 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\abbc3\controller;
12
13
use phpbb\cache\driver\driver_interface as cache_driver;
0 ignored issues
show
Bug introduced by
The type phpbb\cache\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\controller\helper;
0 ignored issues
show
Bug introduced by
The type phpbb\controller\helper 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\exception\http_exception;
0 ignored issues
show
Bug introduced by
The type phpbb\exception\http_exception 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\request\request;
0 ignored issues
show
Bug introduced by
The type phpbb\request\request 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
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...
18
use phpbb\textformatter\s9e\factory as textformatter;
0 ignored issues
show
Bug introduced by
The type phpbb\textformatter\s9e\factory 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...
19
20
/**
21
 * ABBC3 BBCode Wizard class
22
 */
23
class wizard
24
{
25
	/** @var string The default BBvideo site */
26
	const BBVIDEO_DEFAULT = 'youtube';
27
28
	/** @var cache_driver */
29
	protected $cache;
30
31
	/** @var helper */
32
	protected $helper;
33
34
	/** @var request */
35
	protected $request;
36
37
	/** @var template */
38
	protected $template;
39
40
	/** @var textformatter */
41
	protected $textformatter;
42
43
	/**
44
	 * Constructor
45
	 *
46
	 * @param cache_driver  $cache         Cache driver
47
	 * @param helper        $helper        Controller helper object
48
	 * @param request       $request       Request object
49
	 * @param template      $template      Template object
50
	 * @param textformatter $textformatter TextFormatter Factory
51
	 * @access public
52
	 */
53 10
	public function __construct(cache_driver $cache, helper $helper, request $request, template $template, textformatter $textformatter)
54
	{
55 10
		$this->cache = $cache;
56 10
		$this->helper = $helper;
57 10
		$this->request = $request;
58 10
		$this->template = $template;
59 10
		$this->textformatter = $textformatter;
60 10
	}
61
62
	/**
63
	 * BBCode wizard controller accessed with the URL /wizard/bbcode/{mode}
64
	 * (where {mode} is a placeholder for a string of the bbcode tag name)
65
	 * intended to be accessed via AJAX only
66
	 *
67
	 * @param string $mode Mode taken from the URL
68
	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Response 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...
69
	 * @throws http_exception An http exception
70
	 * @access public
71
	 */
72
	public function bbcode_wizard($mode)
73 10
	{
74
		// Only allow valid AJAX requests
75
		if ($this->request->is_ajax() && in_array($mode, ['bbvideo', 'pipes', 'url']))
76 10
		{
77 10
			if ($mode === 'bbvideo')
78 3
			{
79 3
				$this->generate_bbvideo_wizard();
80 1
			}
81 1
82
			return $this->helper->render("abbc3_{$mode}_wizard.html");
83 3
		}
84
85
		throw new http_exception(404, 'GENERAL_ERROR');
86 7
	}
87
88
	/**
89
	 * Set template variables for the BBvideo wizard
90
	 *
91
	 * @access protected
92
	 */
93
	protected function generate_bbvideo_wizard()
94 1
	{
95
		if (($bbvideo_sites = $this->cache->get('_bbvideo_sites')) === false)
96 1
		{
97 1
			$bbvideo_sites = [];
98 1
			$configurator = $this->textformatter->get_configurator();
99 1
			foreach ($configurator->MediaEmbed->defaultSites as $siteId => $siteConfig)
100 1
			{
101
				// check that siteID is not already a custom bbcode and that it exists in MediaEmbed
102
				if (!isset($configurator->BBCodes[$siteId]) && $configurator->tags->exists($siteId))
103 1
				{
104 1
					$bbvideo_sites[$siteId] = [
105
						'name'    => $siteConfig['name'],
106
						'example' => isset($siteConfig['example']) ? current((array) $siteConfig['example']) : '',
107 1
					];
108
				}
109 1
			}
110 1
111
			ksort($bbvideo_sites);
112 1
113
			$this->cache->put('_bbvideo_sites', $bbvideo_sites);
114 1
		}
115 1
116 1
		$this->template->assign_vars([
117 1
			'ABBC3_BBVIDEO_SITES'	=> $bbvideo_sites,
118 1
			'ABBC3_BBVIDEO_DEFAULT'	=> self::BBVIDEO_DEFAULT,
119 1
		]);
120
	}
121
}
122