ScriptsAndStyles   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 109
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hospitalRegisterScript() 0 4 1
B init() 0 24 2
A hospitalRegisterStyle() 0 5 1
A hospitalLocalizeScript() 0 8 1
A hospitalPluginStyles() 0 8 3
A hospitalPluginScripts() 0 11 3
A removeCustomScripts() 0 5 1
1
<?php
2
/**
3
 * ScriptsAndStyles
4
 *
5
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6
 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7
 *
8
 * Permission is hereby granted to use or copy this program
9
 * for any purpose, provided the above notices are retained on all copies.
10
 * Permission to modify the code and to distribute modified code is granted,
11
 * provided the above notices are retained, and a notice that the code was
12
 * modified is included with the above copyright notice.
13
 *
14
 * @category  Wp
15
 * @package   Punction
16
 * @author    Andrzej Marcinkowski <[email protected]>
17
 * @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz
18
 * @license   MIT http://opensource.org/licenses/MIT
19
 * @version   1.0  $Format:%H$
20
 * @link      http://
21
 * @since     File available since Release 1.0.0
22
 * PHP Version 5
23
 */
24
namespace Hospitalplugin\WP;
25
26
/**
27
 * ScriptsAndStyles
28
 *
29
 * @category  Wp
30
 * @package   Punction
31
 * @author    Andrzej Marcinkowski <[email protected]>
32
 * @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz
33
 * @license   MIT http://opensource.org/licenses/MIT
34
 * @version   1.0 $Format:%H$
35
 * @link      http://
36
 * @since     File available since Release 1.0.0
37
 *
38
 */
39
class ScriptsAndStyles
40
{
41
42
    private $scripts;
43
44
    private $styles;
45
46
    private $pages;
47
48
    private $path;
49
50
    /**
51
     * init
52
     */
53
    public function init($path, $pages, $scripts, $styles, $type = 'admin')
54
    {
55
        if ($type == 'admin') {
56
            $action = 'admin_enqueue_scripts';
57
        } else {
58
            $action = 'wp_enqueue_scripts';
59
        }
60
        $this->path = $path;
61
        $this->pages = $pages;
62
        $this->scripts = $scripts;
63
        $this->styles = $styles;
64
        add_action($action, array(
65
            $this,
66
            'hospitalPluginStyles'
67
        ));
68
        add_action($action, array(
69
            $this,
70
            'hospitalPluginScripts'
71
        ));
72
        add_action($action, array(
73
            $this,
74
            'removeCustomScripts'
75
        ));
76
    }
77
78
    /**
79
     * hospitalRegisterStyle
80
     * @param $file
81
     */
82
    public function hospitalRegisterStyle($file)
83
    {
84
        wp_register_style('hospital_admin_style' . $file, $this->path . '/css/' . $file, array(), '1', 'all');
85
        wp_enqueue_style('hospital_admin_style' . $file);
86
    }
87
88
    /**
89
     * hospitalRegisterScript
90
     * @param unknown $file
91
     * @param unknown $required
92
     */
93
    public function hospitalRegisterScript($file, $required = null, $hook = null)
0 ignored issues
show
Unused Code introduced by
The parameter $hook is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
    {
95
        wp_enqueue_script('hospital_admin_script' . $file, $this->path . '/js/' . $file, $required);
96
    }
97
98
    /**
99
     * hospitalLocalizeScript
100
     * @param unknown $file
101
     * @param unknown $data
102
     */
103
    public function hospitalLocalizeScript($file, $data)
104
    {
105
        $json_dates = json_encode($data);
106
        $params = array(
107
            'my_arr' => $json_dates
108
        );
109
        wp_localize_script('hospital_admin_script' . $file, 'php_params', $params);
110
    }
111
112
    /**
113
     * hospitalPluginStyles
114
     */
115
    public function hospitalPluginStyles($hook)
116
    {
117
        if (in_array($hook, $this->pages)) {
118
            foreach ($this->styles as $style) {
119
                self::hospitalRegisterStyle($style);
120
            }
121
        }
122
    }
123
124
    /**
125
     * hospitalPluginScripts
126
     * @param string $hook hook to the page
127
     */
128
    public function hospitalPluginScripts($hook)
129
    {
130
        $jQ = array(
131
            'jquery'
132
        );
133
        if (in_array($hook, $this->pages)) {
134
            foreach ($this->scripts as $script) {
135
                self::hospitalRegisterScript($script, $jQ, $hook);
0 ignored issues
show
Documentation introduced by
$jQ is of type array<integer,string,{"0":"string"}>, but the function expects a object<Hospitalplugin\WP\unknown>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
136
            }
137
        }
138
    }
139
140
    /**
141
     */
142
    public function removeCustomScripts()
143
    {
144
        wp_dequeue_style('google-webfonts');
145
        wp_dequeue_script('wplms-events-gmaps-js');
146
    }
147
}
148
149