Completed
Push — master ( 0ea243...da58d4 )
by Henry
10:25 queued 33s
created

modules/HtmlValidator/HtmlValidator.php (1 issue)

Check for implicit conversion of array to boolean.

Best Practice Bug Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Modules\HtmlValidator;
3
4
use Redaxscript\Module;
5
use Redaxscript\Reader;
6
use function http_build_query;
7
8
/**
9
 * html validator for developers
10
 *
11
 * @since 2.2.0
12
 *
13
 * @package Redaxscript
14
 * @category Modules
15
 * @author Henry Ruhs
16
 */
17
18
class HtmlValidator extends Module\Notification
19
{
20
	/**
21
	 * array of the module
22
	 *
23
	 * @var array
24
	 */
25
26
	protected static $_moduleArray =
27
	[
28
		'name' => 'HTML Validator',
29
		'alias' => 'HtmlValidator',
30
		'author' => 'Redaxmedia',
31
		'description' => 'HTML validator for developers',
32
		'version' => '4.0.0',
33
		'access' => '[1]'
34
	];
35
36
	/**
37
	 * array of the option
38
	 *
39
	 * @var array
40
	 */
41
42
	protected $_optionArray =
43
	[
44
		'apiUrl' => 'https://validator.w3.org/nu/'
45
	];
46
47
	/**
48
	 * adminNotification
49
	 *
50
	 * @since 3.0.1
51
	 *
52
	 * @return array|null
53
	 */
54
55
	public function adminNotification() : ?array
56
	{
57
		if ($this->_registry->get('firstParameter') !== 'admin')
58
		{
59
			/* load result */
60
61
			$url = $this->_optionArray['apiUrl'] . '?' . http_build_query(
62
			[
63
				'doc' => $this->_registry->get('root') . '/' . $this->_registry->get('parameterRoute') . $this->_registry->get('fullRoute'),
64
				'checkerrorpages' => 'yes',
65
				'out' => 'json'
66
			]);
67
			$reader = new Reader();
68
			$reader->init(
69
			[
70
				'curl' =>
71
				[
72
					CURLOPT_USERAGENT => $this->_language->get('name', '_package')
73
				]
74
			]);
75
			$result = $reader->loadJSON($url)->getArray();
76
77
			/* process result */
78
79
			if ($result['messages'])
80
			{
81
				foreach ($result['messages'] as $value)
82
				{
83
					if ($value['type'] === 'error' || $value['type'] === 'non-document-error')
84
					{
85
						$message =
86
						[
87
							'text' => $value['message'],
88
							'attr' =>
89
							[
90
								'href' => $url,
91
								'target' => '_blank'
92
							]
93
						];
94
						$this->setNotification('error', $message);
95
					}
96
				}
97
			}
98
			if (!$result)
0 ignored issues
show
Bug Best Practice introduced by
The expression $result of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
99
			{
100
				$this->setNotification('warning', $this->_language->get('service_no', '_html_validator') . $this->_language->get('point'));
101
			}
102
			else if (!$this->getNotification('error'))
103
			{
104
				$this->setNotification('success', $this->_language->get('document_validate', '_html_validator') . $this->_language->get('point'));
105
			}
106
		}
107
		return $this->getNotification();
108
	}
109
}
110