Inputs   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 20

5 Methods

Rating   Name   Duplication   Size   Complexity  
A replace() 0 4 1
A all() 0 3 1
B get() 0 13 11
A add() 0 4 2
A set() 0 7 5
1
<?php
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Http\Contributors;
24
25
use Syscodes\Core\Http\Exceptions\BadRequestHttpException;
26
27
/**
28
 * Inputs is a container for user input values such as 
29
 * $_GET, $_POST, $_REQUEST, and $_COOKIE.
30
 * 
31
 * @author Alexander Campo <[email protected]>
32
 */
33
final class Inputs extends Parameters
34
{
35
    /**
36
	 * {@inheritdoc}
37
	 */
38
	public function all(string $key = null)
39
	{
40
		return parent::all($key);
0 ignored issues
show
Unused Code introduced by
The call to Syscodes\Http\Contributors\Parameters::all() has too many arguments starting with $key. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
		return parent::/** @scrutinizer ignore-call */ all($key);

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. Please note the @ignore annotation hint above.

Loading history...
41
    }
42
    
43
    /**
44
	 * {@inheritdoc}
45
	 */
46
	public function replace(array $inputs = [])
47
	{
48
		$this->parameters = [];
49
        $this->add($inputs);
50
	}
51
52
	/**
53
	 * Adds input values.
54
     * 
55
     * @param  array  $inputs
56
     * 
57
     * @return mixed
58
	 */
59
	public function add(array $inputs = [])
60
	{
61
        foreach ($inputs as $key => $file) {
62
            $this->set($key, $file);
63
        }
64
    }
65
    
66
    /**
67
	 * Gets a string input value by name.
68
	 *
69
	 * @param  string  $key
70
	 * @param  string|null  $default  
71
	 *
72
	 * @return string|null
73
	 */
74
	public function get($key, $default = null)
75
	{
76
        if (null !== $default && ! is_scalar($default) && ! (is_object($default)) && ! method_exist($default, '__toString')) {
0 ignored issues
show
Bug introduced by
The function method_exist was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        if (null !== $default && ! is_scalar($default) && ! (is_object($default)) && ! /** @scrutinizer ignore-call */ method_exist($default, '__toString')) {
Loading history...
introduced by
The condition is_scalar($default) is always true.
Loading history...
77
            throw new BadRequestHttpException(sprintf('Passing a non-string value as 2nd argument to "%s()" is deprecated, pass a string or null instead', __METHOD__));
78
        }
79
80
        $value = parent::get($key, $this);
0 ignored issues
show
Bug introduced by
$this of type Syscodes\Http\Contributors\Inputs is incompatible with the type null|string expected by parameter $default of Syscodes\Http\Contributors\Parameters::get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

80
        $value = parent::get($key, /** @scrutinizer ignore-type */ $this);
Loading history...
81
82
        if (null !== $value && $this !== $value && ! is_scalar($value) && ! (is_object($value)) && ! method_exist($value, '__toString')) {
83
            throw new BadRequestHttpException(sprintf('Retrieving a non-string value from "%s()" is deprecated, and will throw a exception in Syscodes, use "%s::all($key)" instead', __METHOD__, __CLASS__));
84
        }
85
        
86
        return $value === $this ? $default : $value;
87
    }
88
    
89
    /**
90
	 * Sets an input by name.
91
	 *
92
	 * @param  string  $key
93
	 * @param  string|array|null  $value 
94
	 *
95
	 * @return mixed
96
	 */
97
	public function set($key, $value)
98
	{
99
        if (null !== $value && ! is_scalar($value) && ! is_array($value) && ! method_exist($value, '__toString')) {
0 ignored issues
show
Bug introduced by
The function method_exist was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
        if (null !== $value && ! is_scalar($value) && ! is_array($value) && ! /** @scrutinizer ignore-call */ method_exist($value, '__toString')) {
Loading history...
introduced by
The condition is_array($value) is always true.
Loading history...
100
            throw new BadRequestHttpException(sprintf('Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a string, array, or null instead', get_debug_type($value), __METHOD__));
101
        }
102
103
		$this->parameters[$key] = $value;
104
	}
105
}