Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created
plugin/Defaults/DefaultsAbstract.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -8,137 +8,137 @@
 block discarded – undo
8 8
 
9 9
 abstract class DefaultsAbstract
10 10
 {
11
-    /**
12
-     * @var array
13
-     */
14
-    protected $callable = [
15
-        'defaults', 'filter', 'merge', 'restrict', 'unguarded',
16
-    ];
17
-
18
-    /**
19
-     * @var array
20
-     */
21
-    protected $guarded = [];
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $mapped = [];
27
-
28
-    /**
29
-     * @param string $name
30
-     * @return void|array
31
-     */
32
-    public function __call($name, array $args = [])
33
-    {
34
-        if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
35
-            return;
36
-        }
37
-        $args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
-        $defaults = call_user_func_array([$this, $name], $args);
39
-        $hookName = (new ReflectionClass($this))->getShortName();
40
-        $hookName = str_replace('Defaults', '', $hookName);
41
-        $hookName = Str::dashCase($hookName);
42
-        return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
43
-    }
44
-
45
-    /**
46
-     * @return array
47
-     */
48
-    abstract protected function defaults();
49
-
50
-    /**
51
-     * @return array
52
-     */
53
-    protected function filter(array $values = [])
54
-    {
55
-        return $this->normalize($this->merge(array_filter($values)), $values);
56
-    }
57
-
58
-    /**
59
-     * @return string
60
-     */
61
-    protected function filteredJson(array $values = [])
62
-    {
63
-        $defaults = $this->flattenArrayValues(
64
-            array_diff_key($this->defaults(), array_flip($this->guarded))
65
-        );
66
-        $values = $this->flattenArrayValues(
67
-            shortcode_atts($defaults, $values)
68
-        );
69
-        $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
-            return !$this->isEmpty($value);
71
-        });
72
-        return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
73
-    }
74
-
75
-    /**
76
-     * @return array
77
-     */
78
-    protected function flattenArrayValues(array $values)
79
-    {
80
-        array_walk($values, function (&$value) {
81
-            if (!is_array($value)) {
82
-                return;
83
-            }
84
-            $value = implode(',', $value);
85
-        });
86
-        return $values;
87
-    }
88
-
89
-    /**
90
-     * @param mixed $var
91
-     * @return bool
92
-     */
93
-    protected function isEmpty($var)
94
-    {
95
-        return !is_numeric($var) && !is_bool($var) && empty($var);
96
-    }
97
-
98
-    /**
99
-     * @return array
100
-     */
101
-    protected function mapKeys(array $args)
102
-    {
103
-        foreach ($this->mapped as $old => $new) {
104
-            if (array_key_exists($old, $args)) {
105
-                $args[$new] = $args[$old];
106
-                unset($args[$old]);
107
-            }
108
-        }
109
-        return $args;
110
-    }
111
-
112
-    /**
113
-     * @return array
114
-     */
115
-    protected function merge(array $values = [])
116
-    {
117
-        return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
118
-    }
119
-
120
-    /**
121
-     * @return array
122
-     */
123
-    protected function normalize(array $values, array $originalValues)
124
-    {
125
-        $values['json'] = $this->filteredJson($originalValues);
126
-        return $values;
127
-    }
128
-
129
-    /**
130
-     * @return array
131
-     */
132
-    protected function restrict(array $values = [])
133
-    {
134
-        return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
135
-    }
136
-
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function unguarded()
141
-    {
142
-        return array_diff_key($this->defaults(), array_flip($this->guarded));
143
-    }
11
+	/**
12
+	 * @var array
13
+	 */
14
+	protected $callable = [
15
+		'defaults', 'filter', 'merge', 'restrict', 'unguarded',
16
+	];
17
+
18
+	/**
19
+	 * @var array
20
+	 */
21
+	protected $guarded = [];
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $mapped = [];
27
+
28
+	/**
29
+	 * @param string $name
30
+	 * @return void|array
31
+	 */
32
+	public function __call($name, array $args = [])
33
+	{
34
+		if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
35
+			return;
36
+		}
37
+		$args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
+		$defaults = call_user_func_array([$this, $name], $args);
39
+		$hookName = (new ReflectionClass($this))->getShortName();
40
+		$hookName = str_replace('Defaults', '', $hookName);
41
+		$hookName = Str::dashCase($hookName);
42
+		return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
43
+	}
44
+
45
+	/**
46
+	 * @return array
47
+	 */
48
+	abstract protected function defaults();
49
+
50
+	/**
51
+	 * @return array
52
+	 */
53
+	protected function filter(array $values = [])
54
+	{
55
+		return $this->normalize($this->merge(array_filter($values)), $values);
56
+	}
57
+
58
+	/**
59
+	 * @return string
60
+	 */
61
+	protected function filteredJson(array $values = [])
62
+	{
63
+		$defaults = $this->flattenArrayValues(
64
+			array_diff_key($this->defaults(), array_flip($this->guarded))
65
+		);
66
+		$values = $this->flattenArrayValues(
67
+			shortcode_atts($defaults, $values)
68
+		);
69
+		$filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
+			return !$this->isEmpty($value);
71
+		});
72
+		return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
73
+	}
74
+
75
+	/**
76
+	 * @return array
77
+	 */
78
+	protected function flattenArrayValues(array $values)
79
+	{
80
+		array_walk($values, function (&$value) {
81
+			if (!is_array($value)) {
82
+				return;
83
+			}
84
+			$value = implode(',', $value);
85
+		});
86
+		return $values;
87
+	}
88
+
89
+	/**
90
+	 * @param mixed $var
91
+	 * @return bool
92
+	 */
93
+	protected function isEmpty($var)
94
+	{
95
+		return !is_numeric($var) && !is_bool($var) && empty($var);
96
+	}
97
+
98
+	/**
99
+	 * @return array
100
+	 */
101
+	protected function mapKeys(array $args)
102
+	{
103
+		foreach ($this->mapped as $old => $new) {
104
+			if (array_key_exists($old, $args)) {
105
+				$args[$new] = $args[$old];
106
+				unset($args[$old]);
107
+			}
108
+		}
109
+		return $args;
110
+	}
111
+
112
+	/**
113
+	 * @return array
114
+	 */
115
+	protected function merge(array $values = [])
116
+	{
117
+		return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
118
+	}
119
+
120
+	/**
121
+	 * @return array
122
+	 */
123
+	protected function normalize(array $values, array $originalValues)
124
+	{
125
+		$values['json'] = $this->filteredJson($originalValues);
126
+		return $values;
127
+	}
128
+
129
+	/**
130
+	 * @return array
131
+	 */
132
+	protected function restrict(array $values = [])
133
+	{
134
+		return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
135
+	}
136
+
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function unguarded()
141
+	{
142
+		return array_diff_key($this->defaults(), array_flip($this->guarded));
143
+	}
144 144
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
      * @param string $name
30 30
      * @return void|array
31 31
      */
32
-    public function __call($name, array $args = [])
32
+    public function __call( $name, array $args = [] )
33 33
     {
34
-        if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
34
+        if( !method_exists( $this, $name ) || !in_array( $name, $this->callable ) ) {
35 35
             return;
36 36
         }
37
-        $args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
-        $defaults = call_user_func_array([$this, $name], $args);
39
-        $hookName = (new ReflectionClass($this))->getShortName();
40
-        $hookName = str_replace('Defaults', '', $hookName);
41
-        $hookName = Str::dashCase($hookName);
42
-        return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
37
+        $args[0] = $this->mapKeys( Arr::get( $args, 0, [] ) );
38
+        $defaults = call_user_func_array( [$this, $name], $args );
39
+        $hookName = (new ReflectionClass( $this ))->getShortName();
40
+        $hookName = str_replace( 'Defaults', '', $hookName );
41
+        $hookName = Str::dashCase( $hookName );
42
+        return apply_filters( 'site-reviews/defaults/'.$hookName, $defaults, $name );
43 43
     }
44 44
 
45 45
     /**
@@ -50,38 +50,38 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * @return array
52 52
      */
53
-    protected function filter(array $values = [])
53
+    protected function filter( array $values = [] )
54 54
     {
55
-        return $this->normalize($this->merge(array_filter($values)), $values);
55
+        return $this->normalize( $this->merge( array_filter( $values ) ), $values );
56 56
     }
57 57
 
58 58
     /**
59 59
      * @return string
60 60
      */
61
-    protected function filteredJson(array $values = [])
61
+    protected function filteredJson( array $values = [] )
62 62
     {
63 63
         $defaults = $this->flattenArrayValues(
64
-            array_diff_key($this->defaults(), array_flip($this->guarded))
64
+            array_diff_key( $this->defaults(), array_flip( $this->guarded ) )
65 65
         );
66 66
         $values = $this->flattenArrayValues(
67
-            shortcode_atts($defaults, $values)
67
+            shortcode_atts( $defaults, $values )
68 68
         );
69
-        $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
-            return !$this->isEmpty($value);
69
+        $filtered = array_filter( array_diff_assoc( $values, $defaults ), function( $value ) {
70
+            return !$this->isEmpty( $value );
71 71
         });
72
-        return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
72
+        return json_encode( $filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
73 73
     }
74 74
 
75 75
     /**
76 76
      * @return array
77 77
      */
78
-    protected function flattenArrayValues(array $values)
78
+    protected function flattenArrayValues( array $values )
79 79
     {
80
-        array_walk($values, function (&$value) {
81
-            if (!is_array($value)) {
80
+        array_walk( $values, function( &$value ) {
81
+            if( !is_array( $value ) ) {
82 82
                 return;
83 83
             }
84
-            $value = implode(',', $value);
84
+            $value = implode( ',', $value );
85 85
         });
86 86
         return $values;
87 87
     }
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
      * @param mixed $var
91 91
      * @return bool
92 92
      */
93
-    protected function isEmpty($var)
93
+    protected function isEmpty( $var )
94 94
     {
95
-        return !is_numeric($var) && !is_bool($var) && empty($var);
95
+        return !is_numeric( $var ) && !is_bool( $var ) && empty($var);
96 96
     }
97 97
 
98 98
     /**
99 99
      * @return array
100 100
      */
101
-    protected function mapKeys(array $args)
101
+    protected function mapKeys( array $args )
102 102
     {
103
-        foreach ($this->mapped as $old => $new) {
104
-            if (array_key_exists($old, $args)) {
103
+        foreach( $this->mapped as $old => $new ) {
104
+            if( array_key_exists( $old, $args ) ) {
105 105
                 $args[$new] = $args[$old];
106 106
                 unset($args[$old]);
107 107
             }
@@ -112,26 +112,26 @@  discard block
 block discarded – undo
112 112
     /**
113 113
      * @return array
114 114
      */
115
-    protected function merge(array $values = [])
115
+    protected function merge( array $values = [] )
116 116
     {
117
-        return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
117
+        return $this->normalize( wp_parse_args( $values, $this->defaults() ), $values );
118 118
     }
119 119
 
120 120
     /**
121 121
      * @return array
122 122
      */
123
-    protected function normalize(array $values, array $originalValues)
123
+    protected function normalize( array $values, array $originalValues )
124 124
     {
125
-        $values['json'] = $this->filteredJson($originalValues);
125
+        $values['json'] = $this->filteredJson( $originalValues );
126 126
         return $values;
127 127
     }
128 128
 
129 129
     /**
130 130
      * @return array
131 131
      */
132
-    protected function restrict(array $values = [])
132
+    protected function restrict( array $values = [] )
133 133
     {
134
-        return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
134
+        return $this->normalize( shortcode_atts( $this->defaults(), $values ), $values );
135 135
     }
136 136
 
137 137
     /**
@@ -139,6 +139,6 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function unguarded()
141 141
     {
142
-        return array_diff_key($this->defaults(), array_flip($this->guarded));
142
+        return array_diff_key( $this->defaults(), array_flip( $this->guarded ) );
143 143
     }
144 144
 }
Please login to merge, or discard this patch.