Input::post()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 3
rs 10
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 Input
20
 * @package App\Utility
21
 */
22
class Input
23
{
24
25
    /**
26
     * @param array $source
27
     * @param array $inputs
28
     * @param null $recordID
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $recordID is correct as it would always require null to be passed?
Loading history...
29
     * @return bool
30
     */
31
    public static function check(array $source, array $inputs, $recordID = null)
32
    {
33
        $_return=true;
34
35
        if (!Input::exists()) {
36
            $_return=false;
37
        }
38
        if (!isset($source["csrf_token"]) && ! Token::check($source["csrf_token"])) {
0 ignored issues
show
Bug introduced by
The type App\Utility\Token was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
            Flash::danger(Text::getText("INPUT_INCORRECT_CSRF_TOKEN"));
0 ignored issues
show
Bug introduced by
The type App\Utility\Flash was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
            $_return=false;
41
        }
42
        $valid = new Validate($source, $recordID);
0 ignored issues
show
Bug introduced by
The type App\Utility\Validate was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
        $validation = $valid->check($inputs);
44
        if (!$validation->passed()) {
45
            Session::put(SESSION_ERRORS, $validation->errors());
0 ignored issues
show
Bug introduced by
The constant App\Utility\SESSION_ERRORS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
46
            $_return=false;
47
        }
48
        return $_return;
49
    }
50
51
    /**
52
     * @param string $source
53
     * @return bool
54
     */
55
    public static function exists($source = "post")
56
    {
57
        switch ($source) {
58
            case 'post':
59
                return(!empty($_POST));
60
            case 'get':
61
                return(!empty($_GET));
62
            default:
63
                break;
64
        }
65
        return false;
66
    }
67
68
    /**
69
     * @param $key
70
     * @param string $default
71
     * @return mixed|string
72
     */
73
    public static function get($key, $default = "")
74
    {
75
        return(isset($_GET[$key]) ? $_GET[$key] : $default);
76
    }
77
78
    /**
79
     * @param $key
80
     * @param string $default
81
     * @return mixed|string
82
     */
83
    public static function post($key, $default = "")
84
    {
85
        return(isset($_POST[$key]) ? $_POST[$key] : $default);
86
    }
87
}
88
89