Completed
Push — add/jetpack-mobile-package ( 96545e...4a9724 )
by
unknown
08:23
created

class.jetpack-user-agent.php ➔ jetpack_is_mobile()   B

Complexity

Conditions 8
Paths 11

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 11
nop 2
dl 0
loc 23
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
use Automattic\Jetpack\Device_Detection;
4
5
/**
6
 * Determine if the current User Agent matches the passed $kind
7
 *
8
 * @param string $kind Category of mobile device to check for.
9
 *                         Either: any, dumb, smart.
10
 * @param bool   $return_matched_agent Boolean indicating if the UA should be returned
11
 *
12
 * @return bool|string Boolean indicating if current UA matches $kind. If
13
 *                              $return_matched_agent is true, returns the UA string
14
 */
15
function jetpack_is_mobile( $kind = 'any', $return_matched_agent = false ) {
16
	$pre = apply_filters( 'pre_jetpack_is_mobile', null, $kind, $return_matched_agent );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $kind.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
17
	if ( $pre ) {
18
		return $pre;
19
	}
20
21
	$return = false;
22
	$device_info = Device_Detection::get_info();
23
24
	if ( 'any' === $kind ) {
25
		$return = $device_info['is_mobile'];
26
	} elseif ( 'smart' === $kind ) {
27
		$return = $device_info['is_smartphone'];
28
	} elseif ( 'dumb' === $kind ) {
29
		$return = $device_info['is_mobile'] && ! $device_info['is_smartphone'];
30
	}
31
32
	if ( $return_matched_agent && true === $return ) {
33
		$return = $device_info['is_mobile_matched_ua'];
34
	}
35
36
	return apply_filters( 'jetpack_is_mobile', $return, $kind, $return_matched_agent );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $kind.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
37
}
38