Passed
Push — master ( 35e6c8...e638f9 )
by Stephen
01:19
created

JsResponses   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 43
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsAlert() 0 3 1
A jsOpenInNewTab() 0 3 1
A consoleLog() 0 3 1
A reloadWindow() 0 3 1
1
<?php
2
3
4
namespace Sfneal\Helpers\Javascript;
5
6
7
class JsResponses
8
{
9
    /**
10
     * Reload current page.
11
     *
12
     * @return string
13
     */
14
    public static function reloadWindow(): string
15
    {
16
        return 'window.location.reload()';
17
    }
18
19
    /**
20
     * Return a JavaScript alert with a message.
21
     *
22
     * @param string $msg
23
     * @return string
24
     */
25
    public static function jsAlert(string $msg): string
26
    {
27
        return 'alert("'.$msg.'");';
28
    }
29
30
    /**
31
     * Open a $url in a new tab.
32
     *
33
     * @param string $url
34
     * @return string
35
     */
36
    public static function jsOpenInNewTab(string $url): string
37
    {
38
        return "window.open('{$url}', '_blank');";
39
    }
40
41
    /**
42
     * Log a message to the client side Javascript console.
43
     *
44
     * @param string $message
45
     * @return string
46
     */
47
    public static function consoleLog(string $message): string
48
    {
49
        return "console.log('$message');";
50
    }
51
}
52