Passed
Branch master (2fcc75)
by Paul
11:46
created
plugin/Helpers/Str.php 1 patch
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -4,187 +4,187 @@
 block discarded – undo
4 4
 
5 5
 class Str
6 6
 {
7
-    /**
8
-     * @param string $subject
9
-     * @param string $search
10
-     * @return string
11
-     */
12
-    public static function afterLast($subject, $search)
13
-    {
14
-        return '' === $search
15
-            ? $subject
16
-            : array_reverse(explode($search, $subject))[0];
17
-    }
7
+	/**
8
+	 * @param string $subject
9
+	 * @param string $search
10
+	 * @return string
11
+	 */
12
+	public static function afterLast($subject, $search)
13
+	{
14
+		return '' === $search
15
+			? $subject
16
+			: array_reverse(explode($search, $subject))[0];
17
+	}
18 18
 
19
-    /**
20
-     * @param string $string
21
-     * @return string
22
-     */
23
-    public static function camelCase($string)
24
-    {
25
-        $string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
26
-        return str_replace(' ', '', $string);
27
-    }
19
+	/**
20
+	 * @param string $string
21
+	 * @return string
22
+	 */
23
+	public static function camelCase($string)
24
+	{
25
+		$string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
26
+		return str_replace(' ', '', $string);
27
+	}
28 28
 
29
-    /**
30
-     * @param string $haystack
31
-     * @param string $needle
32
-     * @return bool
33
-     */
34
-    public static function contains($haystack, $needle)
35
-    {
36
-        return false !== strpos($haystack, $needle);
37
-    }
29
+	/**
30
+	 * @param string $haystack
31
+	 * @param string $needle
32
+	 * @return bool
33
+	 */
34
+	public static function contains($haystack, $needle)
35
+	{
36
+		return false !== strpos($haystack, $needle);
37
+	}
38 38
 
39
-    /**
40
-     * @param string $name
41
-     * @param string $nameType first|first_initial|initials|last|last_initial
42
-     * @param string $initialType period|period_space|space
43
-     * @return string
44
-     */
45
-    public static function convertName($name, $nameType = '', $initialType = '')
46
-    {
47
-        $names = preg_split('/\W/u', $name, 0, PREG_SPLIT_NO_EMPTY);
48
-        $firstName = array_shift($names);
49
-        $lastName = array_pop($names);
50
-        $initialTypes = [
51
-            'period' => '.',
52
-            'period_space' => '. ',
53
-            'space' => ' ',
54
-        ];
55
-        $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' ');
56
-        if ('initials' == $nameType) {
57
-            return static::convertToInitials($name, $initialPunctuation);
58
-        }
59
-        $nameTypes = [
60
-            'first' => $firstName,
61
-            'first_initial' => static::convertToInitials($firstName).$initialPunctuation.$lastName,
62
-            'last' => $lastName,
63
-            'last_initial' => $firstName.' '.static::convertToInitials($lastName).$initialPunctuation,
64
-        ];
65
-        return trim((string) Arr::get($nameTypes, $nameType, $name));
66
-    }
39
+	/**
40
+	 * @param string $name
41
+	 * @param string $nameType first|first_initial|initials|last|last_initial
42
+	 * @param string $initialType period|period_space|space
43
+	 * @return string
44
+	 */
45
+	public static function convertName($name, $nameType = '', $initialType = '')
46
+	{
47
+		$names = preg_split('/\W/u', $name, 0, PREG_SPLIT_NO_EMPTY);
48
+		$firstName = array_shift($names);
49
+		$lastName = array_pop($names);
50
+		$initialTypes = [
51
+			'period' => '.',
52
+			'period_space' => '. ',
53
+			'space' => ' ',
54
+		];
55
+		$initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' ');
56
+		if ('initials' == $nameType) {
57
+			return static::convertToInitials($name, $initialPunctuation);
58
+		}
59
+		$nameTypes = [
60
+			'first' => $firstName,
61
+			'first_initial' => static::convertToInitials($firstName).$initialPunctuation.$lastName,
62
+			'last' => $lastName,
63
+			'last_initial' => $firstName.' '.static::convertToInitials($lastName).$initialPunctuation,
64
+		];
65
+		return trim((string) Arr::get($nameTypes, $nameType, $name));
66
+	}
67 67
 
68
-    /**
69
-     * @param string $path
70
-     * @param string $prefix
71
-     * @return string
72
-     */
73
-    public static function convertPathToId($path, $prefix = '')
74
-    {
75
-        return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix));
76
-    }
68
+	/**
69
+	 * @param string $path
70
+	 * @param string $prefix
71
+	 * @return string
72
+	 */
73
+	public static function convertPathToId($path, $prefix = '')
74
+	{
75
+		return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix));
76
+	}
77 77
 
78
-    /**
79
-     * @param string $path
80
-     * @param string $prefix
81
-     * @return string
82
-     */
83
-    public static function convertPathToName($path, $prefix = '')
84
-    {
85
-        $levels = explode('.', $path);
86
-        return array_reduce($levels, function ($result, $value) {
87
-            return $result .= '['.$value.']';
88
-        }, $prefix);
89
-    }
78
+	/**
79
+	 * @param string $path
80
+	 * @param string $prefix
81
+	 * @return string
82
+	 */
83
+	public static function convertPathToName($path, $prefix = '')
84
+	{
85
+		$levels = explode('.', $path);
86
+		return array_reduce($levels, function ($result, $value) {
87
+			return $result .= '['.$value.']';
88
+		}, $prefix);
89
+	}
90 90
 
91
-    /**
92
-     * @param string $name
93
-     * @param string $initialPunctuation
94
-     * @return string
95
-     */
96
-    public static function convertToInitials($name, $initialPunctuation = '')
97
-    {
98
-        preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches);
99
-        return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) {
100
-            $string = extension_loaded('mbstring') ? mb_substr($word, 0, 1) : substr($word, 0, 1);
101
-            return $carry.strtoupper($string).$initialPunctuation;
102
-        });
103
-    }
91
+	/**
92
+	 * @param string $name
93
+	 * @param string $initialPunctuation
94
+	 * @return string
95
+	 */
96
+	public static function convertToInitials($name, $initialPunctuation = '')
97
+	{
98
+		preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches);
99
+		return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) {
100
+			$string = extension_loaded('mbstring') ? mb_substr($word, 0, 1) : substr($word, 0, 1);
101
+			return $carry.strtoupper($string).$initialPunctuation;
102
+		});
103
+	}
104 104
 
105
-    /**
106
-     * @param string $string
107
-     * @return string
108
-     */
109
-    public static function dashCase($string)
110
-    {
111
-        return str_replace('_', '-', static::snakeCase($string));
112
-    }
105
+	/**
106
+	 * @param string $string
107
+	 * @return string
108
+	 */
109
+	public static function dashCase($string)
110
+	{
111
+		return str_replace('_', '-', static::snakeCase($string));
112
+	}
113 113
 
114
-    /**
115
-     * @param string $needle
116
-     * @param string $haystack
117
-     * @return bool
118
-     */
119
-    public static function endsWith($needle, $haystack)
120
-    {
121
-        $length = strlen($needle);
122
-        return 0 != $length
123
-            ? substr($haystack, -$length) === $needle
124
-            : true;
125
-    }
114
+	/**
115
+	 * @param string $needle
116
+	 * @param string $haystack
117
+	 * @return bool
118
+	 */
119
+	public static function endsWith($needle, $haystack)
120
+	{
121
+		$length = strlen($needle);
122
+		return 0 != $length
123
+			? substr($haystack, -$length) === $needle
124
+			: true;
125
+	}
126 126
 
127
-    /**
128
-     * @param string $prefix
129
-     * @param string $string
130
-     * @param string|null $trim
131
-     * @return string
132
-     */
133
-    public static function prefix($prefix, $string, $trim = null)
134
-    {
135
-        if (null === $trim) {
136
-            $trim = $prefix;
137
-        }
138
-        return $prefix.trim(static::removePrefix($trim, $string));
139
-    }
127
+	/**
128
+	 * @param string $prefix
129
+	 * @param string $string
130
+	 * @param string|null $trim
131
+	 * @return string
132
+	 */
133
+	public static function prefix($prefix, $string, $trim = null)
134
+	{
135
+		if (null === $trim) {
136
+			$trim = $prefix;
137
+		}
138
+		return $prefix.trim(static::removePrefix($trim, $string));
139
+	}
140 140
 
141
-    /**
142
-     * @param string $prefix
143
-     * @param string $string
144
-     * @return string
145
-     */
146
-    public static function removePrefix($prefix, $string)
147
-    {
148
-        return static::startsWith($prefix, $string)
149
-            ? substr($string, strlen($prefix))
150
-            : $string;
151
-    }
141
+	/**
142
+	 * @param string $prefix
143
+	 * @param string $string
144
+	 * @return string
145
+	 */
146
+	public static function removePrefix($prefix, $string)
147
+	{
148
+		return static::startsWith($prefix, $string)
149
+			? substr($string, strlen($prefix))
150
+			: $string;
151
+	}
152 152
 
153
-    /**
154
-     * @param string $string
155
-     * @return string
156
-     */
157
-    public static function snakeCase($string)
158
-    {
159
-        if (!ctype_lower($string)) {
160
-            $string = preg_replace('/\s+/u', '', $string);
161
-            $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
162
-            $string = function_exists('mb_strtolower')
163
-                ? mb_strtolower($string, 'UTF-8')
164
-                : strtolower($string);
165
-        }
166
-        return str_replace('-', '_', $string);
167
-    }
153
+	/**
154
+	 * @param string $string
155
+	 * @return string
156
+	 */
157
+	public static function snakeCase($string)
158
+	{
159
+		if (!ctype_lower($string)) {
160
+			$string = preg_replace('/\s+/u', '', $string);
161
+			$string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
162
+			$string = function_exists('mb_strtolower')
163
+				? mb_strtolower($string, 'UTF-8')
164
+				: strtolower($string);
165
+		}
166
+		return str_replace('-', '_', $string);
167
+	}
168 168
 
169
-    /**
170
-     * @param string $needle
171
-     * @param string $haystack
172
-     * @return bool
173
-     */
174
-    public static function startsWith($needle, $haystack)
175
-    {
176
-        return substr($haystack, 0, strlen($needle)) === $needle;
177
-    }
169
+	/**
170
+	 * @param string $needle
171
+	 * @param string $haystack
172
+	 * @return bool
173
+	 */
174
+	public static function startsWith($needle, $haystack)
175
+	{
176
+		return substr($haystack, 0, strlen($needle)) === $needle;
177
+	}
178 178
 
179
-    /**
180
-     * @param string $string
181
-     * @param int $length
182
-     * @return string
183
-     */
184
-    public static function truncate($string, $length)
185
-    {
186
-        return strlen($string) > $length
187
-            ? substr($string, 0, $length)
188
-            : $string;
189
-    }
179
+	/**
180
+	 * @param string $string
181
+	 * @param int $length
182
+	 * @return string
183
+	 */
184
+	public static function truncate($string, $length)
185
+	{
186
+		return strlen($string) > $length
187
+			? substr($string, 0, $length)
188
+			: $string;
189
+	}
190 190
 }
Please login to merge, or discard this patch.
plugin/Controllers/RestReviewController.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -12,62 +12,62 @@
 block discarded – undo
12 12
 
13 13
 class RestReviewController extends RestController
14 14
 {
15
-    public function __construct()
16
-    {
17
-        $this->meta = new WP_REST_Post_Meta_Fields(Application::POST_TYPE);
18
-        $this->namespace = Application::ID.'/v1';
19
-        $this->post_type = Application::POST_TYPE;
20
-        $this->rest_base = 'reviews';
21
-    }
15
+	public function __construct()
16
+	{
17
+		$this->meta = new WP_REST_Post_Meta_Fields(Application::POST_TYPE);
18
+		$this->namespace = Application::ID.'/v1';
19
+		$this->post_type = Application::POST_TYPE;
20
+		$this->rest_base = 'reviews';
21
+	}
22 22
 
23
-    /**
24
-     * @return void
25
-     */
26
-    public function register_routes()
27
-    {
28
-        // register_rest_route($this->namespace, '/'.$this->rest_base, [
29
-        //  ['callback' => [$this, 'createReview'], 'methods' => Server::CREATABLE],
30
-        //  ['callback' => [$this, 'getReviews'], 'methods' => Server::READABLE],
31
-        // ]);
32
-        register_rest_route($this->namespace, '/types', [
33
-            [
34
-                'callback' => [$this, 'getReviewTypes'],
35
-                'methods' => Server::READABLE,
36
-                'permission_callback' => [$this, 'get_items_permissions_check'],
37
-            ],
38
-        ]);
39
-    }
23
+	/**
24
+	 * @return void
25
+	 */
26
+	public function register_routes()
27
+	{
28
+		// register_rest_route($this->namespace, '/'.$this->rest_base, [
29
+		//  ['callback' => [$this, 'createReview'], 'methods' => Server::CREATABLE],
30
+		//  ['callback' => [$this, 'getReviews'], 'methods' => Server::READABLE],
31
+		// ]);
32
+		register_rest_route($this->namespace, '/types', [
33
+			[
34
+				'callback' => [$this, 'getReviewTypes'],
35
+				'methods' => Server::READABLE,
36
+				'permission_callback' => [$this, 'get_items_permissions_check'],
37
+			],
38
+		]);
39
+	}
40 40
 
41
-    /**
42
-     * @return WP_Error|Response|mixed
43
-     */
44
-    public function createReview()
45
-    {
46
-        $response = [];
47
-        return rest_ensure_response($response);
48
-    }
41
+	/**
42
+	 * @return WP_Error|Response|mixed
43
+	 */
44
+	public function createReview()
45
+	{
46
+		$response = [];
47
+		return rest_ensure_response($response);
48
+	}
49 49
 
50
-    /**
51
-     * @return WP_Error|Response|mixed
52
-     */
53
-    public function getReviews()
54
-    {
55
-        $response = [];
56
-        return rest_ensure_response($response);
57
-    }
50
+	/**
51
+	 * @return WP_Error|Response|mixed
52
+	 */
53
+	public function getReviews()
54
+	{
55
+		$response = [];
56
+		return rest_ensure_response($response);
57
+	}
58 58
 
59
-    /**
60
-     * @return WP_Error|Response|mixed
61
-     */
62
-    public function getReviewTypes()
63
-    {
64
-        $response = [];
65
-        foreach (glsr()->reviewTypes as $slug => $name) {
66
-            $response[] = [
67
-                'name' => $name,
68
-                'slug' => $slug,
69
-            ];
70
-        }
71
-        return rest_ensure_response($response);
72
-    }
59
+	/**
60
+	 * @return WP_Error|Response|mixed
61
+	 */
62
+	public function getReviewTypes()
63
+	{
64
+		$response = [];
65
+		foreach (glsr()->reviewTypes as $slug => $name) {
66
+			$response[] = [
67
+				'name' => $name,
68
+				'slug' => $slug,
69
+			];
70
+		}
71
+		return rest_ensure_response($response);
72
+	}
73 73
 }
Please login to merge, or discard this patch.