Completed
Push — master ( 4eb4a8...a52438 )
by Henry
07:48
created

modules/CssValidator/CssValidator.php (1 issue)

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\CssValidator;
3
4
use Redaxscript\Module;
5
use Redaxscript\Reader;
6
use function array_key_exists;
7
use function http_build_query;
8
use function urldecode;
9
10
/**
11
 * realtime w3c validator for your css
12
 *
13
 * @since 4.0.0
14
 *
15
 * @package Redaxscript
16
 * @category Modules
17
 * @author Henry Ruhs
18
 */
19
20
class CssValidator extends Module\Metadata
21
{
22
	/**
23
	 * array of the module
24
	 *
25
	 * @var array
26
	 */
27
28
	protected static $_moduleArray =
29
	[
30
		'name' => 'CSS Validator',
31
		'alias' => 'CssValidator',
32
		'author' => 'Redaxmedia',
33
		'description' => 'Realtime W3C validator for your CSS',
34
		'version' => '5.0.0',
35
		'license' => 'MIT',
36
		'access' => '[1]'
37
	];
38
39
	/**
40
	 * array of the option
41
	 *
42
	 * @var array
43
	 */
44
45
	protected $_optionArray =
46
	[
47
		'apiUrl' => 'http://jigsaw.w3.org/css-validator/validator',
48
		'profile' => 'css3svg'
49
	];
50
51
	/**
52
	 * adminNotification
53
	 *
54
	 * @since 4.0.0
55
	 *
56
	 * @return array
57
	 */
58
59
	public function adminNotification() : array
60
	{
61
		if ($this->_registry->get('firstParameter') !== 'admin')
62
		{
63
			/* load result */
64
65
			$url = $this->_optionArray['apiUrl'] . '?' . urldecode(http_build_query(
66
			[
67
				'uri' => $this->_registry->get('root') . '/' . $this->_registry->get('parameterRoute') . $this->_registry->get('fullRoute'),
68
				'profile' => $this->_optionArray['profile'],
69
				'output' => 'json'
70
			]));
71
			$reader = new Reader();
72
			$reader->init(
73
			[
74
				'curl' =>
75
				[
76
					CURLOPT_USERAGENT => $this->_language->get('_package')['name']
77
				]
78
			]);
79
			$result = $reader->loadJSON($url)->getArray();
80
81
			/* process result */
82
83
			if ($result['cssvalidation']['errors'])
84
			{
85
				foreach ($result['cssvalidation']['errors'] as $value)
86
				{
87
					$message =
88
					[
89
						'text' => $value['message'],
90
						'attr' =>
91
						[
92
							'href' => $url,
93
							'target' => '_blank'
94
						]
95
					];
96
					$this->setNotification('error', $message);
97
				}
98
			}
99
			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...
100
			{
101
				$this->setNotification('warning', $this->_language->get('_validator')['service_no'] . $this->_language->get('point'));
102
			}
103
			else if (!array_key_exists('error', $this->getNotificationArray()))
104
			{
105
				$this->setNotification('success', $this->_language->get('_validator')['document_validate'] . $this->_language->get('point'));
106
			}
107
		}
108
		return $this->getNotificationArray();
109
	}
110
}
111