Test Failed
Push — master ( 880e7c...336987 )
by Jean-Christophe
11:06
created

ApplicationStorage::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Ubiquity\utils\store;
4
5
/**
6
 * Data storage for async platforms
7
 *
8
 * Ubiquity\core$Application
9
 * This class is part of Ubiquity
10
 * @author jc
11
 * @version 1.0.0
12
 *
13
 */
14
class ApplicationStorage {
15
	/**
16
	 * @var array
17
	 */
18
	private static $datas;
19
20
	/**
21
	 * Put a value in storage at key position.
22
	 * @param string $key
23
	 * @param mixed $value
24
	 */
25
	public static function put(string $key, $value){
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

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

25
	public static function put(/** @scrutinizer ignore-unused */ string $key, $value){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
		self::$datas[$key=$value];
0 ignored issues
show
Unused Code introduced by
The assignment to $key is dead and can be removed.
Loading history...
27
	}
28
29
	/**
30
	 * Return a value by key.
31
	 * @param string $key
32
	 * @param mixed $default
33
	 * @return mixed
34
	 */
35
	public static function get(string $key,$default=null){
36
		return self::$datas[$key]??$default;
37
	}
38
39
	/**
40
	 * Return all keys in storage.
41
	 * @return array
42
	 */
43
	public static function getAllKeys(){
44
		return \array_keys(self::$datas);
45
	}
46
47
	/**
48
	 * Return all datas in storage.
49
	 * @return array
50
	 */
51
	public static function getAll(){
52
		return self::$datas;
53
	}
54
55
	/**
56
	 * Check if a key exists or not.
57
	 * @param string $key
58
	 * @return boolean
59
	 */
60
	public static function exists(string $key){
61
		return isset(self::$datas[$key]);
62
	}
63
64
	/**
65
	 * Search for a given value and returns the first corresponding key if successful.
66
	 * @param mixed $value
67
	 * @return string|boolean
68
	 */
69
	public static function search($value){
70
		return \array_search($value,self::$datas);
71
	}
72
73
	/**
74
	 * Clear all values in storage.
75
	 */
76
	public static function clear(){
77
		self::$datas=[];
78
	}
79
80
	/**
81
	 * Remove a value by key.
82
	 * @param string $key
83
	 */
84
	public static function remove(string $key){
85
		unset(self::$datas[$key]);
86
	}
87
}
88
89