Redirect::to()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 22
rs 9.8333
1
<?php
2
/**
3
 * This file is part of product_management
4
 * User: Sinan TURGUT <[email protected]>
5
 * Date: 24.06.2019
6
 * php version 7.2
7
 *
8
 * @category Assessment
9
 * @package  ProductManagement
10
 * @author   Sinan TURGUT <[email protected]>
11
 * @license  See LICENSE file
12
 * @link     https://dev.sinanturgut.com.tr
13
 */
14
15
namespace App\Utility;
16
17
18
/**
19
 * Class Redirect
20
 * @package App\Utility
21
 */
22
class Redirect
23
{
24
25
26
    /**
27
     * @param string $location
28
     * @param null $errCode
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $errCode is correct as it would always require null to be passed?
Loading history...
29
     * @param null $replaceMessage
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $replaceMessage is correct as it would always require null to be passed?
Loading history...
30
     */
31
    public static function to($location = "", $errCode=null, $replaceMessage=null)
32
    {
33
        if ($location) {
34
            if ($location === 404) {
0 ignored issues
show
introduced by
The condition $location === 404 is always false.
Loading history...
35
36
                http_response_code(404);
37
                $errorStrings = json_decode(file_get_contents(VDIR.'/errorStrings.json'), true);
38
                $errorString =  $errorStrings[$errCode];
39
                $errorString = str_replace('@errMessage', $replaceMessage, $errorString);
40
41
                extract($errorString);
42
43
                ob_start();
44
45
                require VDIR . '/template/404.php';
46
47
                echo ob_get_clean();
48
            } else {
49
                header("Location: " . $location);
50
//                header("Location: /index.php?url=login");
51
            }
52
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
53
        }
54
    }
55
}
56
57