These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
|||||||||||
2 | /** |
|||||||||||
3 | * Part of ci-phpunit-test |
|||||||||||
4 | * |
|||||||||||
5 | * @author Kenji Suzuki <https://github.com/kenjis> |
|||||||||||
6 | * @license MIT License |
|||||||||||
7 | * @copyright 2015 Kenji Suzuki |
|||||||||||
8 | * @link https://github.com/kenjis/ci-phpunit-test |
|||||||||||
9 | */ |
|||||||||||
10 | ||||||||||||
11 | /** |
|||||||||||
12 | * CodeIgniter URL Helpers with little modification for testing |
|||||||||||
13 | * |
|||||||||||
14 | * @package CodeIgniter |
|||||||||||
15 | * @subpackage Helpers |
|||||||||||
16 | * @category Helpers |
|||||||||||
17 | * @author Kenji Suzuki <http://github.com/kenjis/ci-phpunit-test> |
|||||||||||
18 | * @author EllisLab Dev Team |
|||||||||||
19 | * @link https://codeigniter.com/user_guide/helpers/url_helper.html |
|||||||||||
20 | */ |
|||||||||||
21 | ||||||||||||
22 | // ------------------------------------------------------------------------ |
|||||||||||
23 | ||||||||||||
24 | View Code Duplication | if ( ! function_exists('redirect')) |
||||||||||
25 | { |
|||||||||||
26 | function redirect($uri = '', $method = 'auto', $code = NULL) |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
27 | { |
|||||||||||
28 | if ( ! preg_match('#^(\w+:)?//#i', $uri)) |
|||||||||||
29 | { |
|||||||||||
30 | $uri = site_url($uri); |
|||||||||||
31 | } |
|||||||||||
32 | ||||||||||||
33 | // IIS environment likely? Use 'refresh' for better compatibility |
|||||||||||
34 | if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE) |
|||||||||||
35 | { |
|||||||||||
36 | $method = 'refresh'; |
|||||||||||
37 | } |
|||||||||||
38 | elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
39 | { |
|||||||||||
40 | if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') |
|||||||||||
41 | { |
|||||||||||
42 | $code = ($_SERVER['REQUEST_METHOD'] !== 'GET') |
|||||||||||
43 | ? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get |
|||||||||||
44 | : 307; |
|||||||||||
45 | } |
|||||||||||
46 | else |
|||||||||||
47 | { |
|||||||||||
48 | $code = 302; |
|||||||||||
49 | } |
|||||||||||
50 | } |
|||||||||||
51 | ||||||||||||
52 | switch ($method) |
|||||||||||
53 | { |
|||||||||||
54 | case 'refresh': |
|||||||||||
55 | if (ENVIRONMENT !== 'testing') |
|||||||||||
56 | { |
|||||||||||
57 | header('Refresh:0;url='.$uri); |
|||||||||||
58 | } |
|||||||||||
59 | break; |
|||||||||||
60 | default: |
|||||||||||
61 | if (ENVIRONMENT !== 'testing') |
|||||||||||
62 | { |
|||||||||||
63 | header('Location: '.$uri, TRUE, $code); |
|||||||||||
64 | } |
|||||||||||
65 | break; |
|||||||||||
66 | } |
|||||||||||
67 | ||||||||||||
68 | if (ENVIRONMENT !== 'testing') |
|||||||||||
69 | { |
|||||||||||
70 | exit; |
|||||||||||
71 | } |
|||||||||||
72 | else |
|||||||||||
73 | { |
|||||||||||
74 | while (ob_get_level() > 1) |
|||||||||||
75 | { |
|||||||||||
76 | ob_end_clean(); |
|||||||||||
77 | } |
|||||||||||
78 | ||||||||||||
79 | throw new CIPHPUnitTestRedirectException('Redirect to ' . $uri, $code); |
|||||||||||
80 | } |
|||||||||||
81 | } |
|||||||||||
82 | } |
|||||||||||
83 |
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.