Passed
Push — master ( 41e10c...0c10bb )
by Alexander
03:14
created

InteractsWithFlashData::flash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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 - 2023 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\Components\Http\Concerns;
24
25
use Syscodes\Components\Database\Erostrine\Model;
26
27
/**
28
 * Trait InteractWithFlashData.
29
 */
30
trait InteractsWithFlashData
31
{
32
    /**
33
     * Retrieve an old input item.
34
     * 
35
     * @param  string|null  $key
36
     * @param  \Syscodes\Components\Database\Eloquent\Model|string|array|null  $default
0 ignored issues
show
Bug introduced by
The type Syscodes\Components\Database\Eloquent\Model 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...
37
     * 
38
     * @return string|array|null
39
     */
40
    public function old($key = null, $default = null)
41
    {
42
        $default = $default instanceof Model ? $default->getAttribute($key) : $default;
43
        
44
        return $this->hasSession() ? $this->session()->getOldInput($key, $default) : $default;
0 ignored issues
show
Bug introduced by
It seems like hasSession() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

44
        return $this->/** @scrutinizer ignore-call */ hasSession() ? $this->session()->getOldInput($key, $default) : $default;
Loading history...
Bug introduced by
It seems like session() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

44
        return $this->hasSession() ? $this->/** @scrutinizer ignore-call */ session()->getOldInput($key, $default) : $default;
Loading history...
45
    }
46
    
47
    /**
48
     * Flash the input for the current request to the session.
49
     * 
50
     * @return void
51
     */
52
    public function flash(): void
53
    {
54
        $this->session()->flashInput($this->input());
0 ignored issues
show
Bug introduced by
It seems like input() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

54
        $this->session()->flashInput($this->/** @scrutinizer ignore-call */ input());
Loading history...
55
    }
56
    
57
    /**
58
     * Flash only some of the input to the session.
59
     * 
60
     * @param  array|mixed  $keys
61
     * 
62
     * @return void
63
     */
64
    public function flashOnly($keys): void
65
    {
66
        $this->session()->flashInput(
67
            $this->only(is_array($keys) ? $keys : func_get_args())
0 ignored issues
show
Bug introduced by
It seems like only() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

67
            $this->/** @scrutinizer ignore-call */ 
68
                   only(is_array($keys) ? $keys : func_get_args())
Loading history...
68
        );
69
    }
70
    
71
    /**
72
     * Flash only some of the input to the session.
73
     * 
74
     * @param  array|mixed  $keys
75
     * 
76
     * @return void
77
     */
78
    public function flashExcept($keys): void
79
    {
80
        $this->session()->flashInput(
81
            $this->except(is_array($keys) ? $keys : func_get_args())
0 ignored issues
show
Bug introduced by
It seems like except() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

81
            $this->/** @scrutinizer ignore-call */ 
82
                   except(is_array($keys) ? $keys : func_get_args())
Loading history...
82
        );
83
    }
84
    
85
    /**
86
     * Flush all of the old input from the session.
87
     * 
88
     * @return void
89
     */
90
    public function flush(): void
91
    {
92
        $this->session()->flashInput([]);
93
    }
94
}