Completed
Push — master ( a52438...bf8826 )
by Henry
06:30
created

modules/LiveReload/LiveReload.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\LiveReload;
3
4
use Redaxscript\Head;
5
use Redaxscript\Module;
6
use Redaxscript\Reader;
7
8
/**
9
 * reload your application on changes
10
 *
11
 * @since 3.3.0
12
 *
13
 * @package Redaxscript
14
 * @category Modules
15
 * @author Henry Ruhs
16
 */
17
18
class LiveReload extends Module\Metadata
19
{
20
	/**
21
	 * array of the module
22
	 *
23
	 * @var array
24
	 */
25
26
	protected static $_moduleArray =
27
	[
28
		'name' => 'Live Reload',
29
		'alias' => 'LiveReload',
30
		'author' => 'Redaxmedia',
31
		'description' => 'Reload your application on changes',
32
		'version' => '5.0.0',
33
		'license' => 'MIT',
34
		'access' => '[1]'
35
	];
36
37
	/**
38
	 * array of the option
39
	 *
40
	 * @var array
41
	 */
42
43
	protected $_optionArray =
44
	[
45
		'url' => 'http://localhost:7000/livereload.js'
46
	];
47
48
	/**
49
	 * renderStart
50
	 *
51
	 * @since 3.3.0
52
	 */
53
54
	public function renderStart() : void
55
	{
56
		$this->_registry->set('noAssetCache', true);
57
		$this->_registry->set('noPageCache', true);
58
		$script = Head\Script::getInstance();
59
		$script
60
			->init('foot')
61
			->appendFile($this->_optionArray['url']);
62
	}
63
64
	/**
65
	 * adminNotification
66
	 *
67
	 * @since 3.3.0
68
	 *
69
	 * @return array
70
	 */
71
72
	public function adminNotification() : array
73
	{
74
		$reader = new Reader();
75
		$reader->init();
76
		$content = $reader->load($this->_optionArray['url']);
77
78
		/* handle notification */
79
80
		if ($content)
0 ignored issues
show
Bug Best Practice introduced by
The expression $content of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
81
		{
82
			$this->setNotification('success', $this->_language->get('_live_reload')['server_online'] . $this->_language->get('point'));
83
		}
84
		else
85
		{
86
			$this->setNotification('error', $this->_language->get('_live_reload')['server_offline'] . $this->_language->get('colon') . ' ' . $this->_optionArray['url']);
87
		}
88
		return $this->getNotificationArray();
89
	}
90
}
91