Passed
Push — master ( cea48f...3c52fb )
by Jean-Christophe
05:56
created

UCookie::exists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Ubiquity\utils\http;
4
5
/**
6
 * Http Cookies utilities
7
 * Ubiquity\utils\http$UCookie
8
 * This class is part of Ubiquity
9
 *
10
 * @author jcheron <[email protected]>
11
 * @version 1.0.3
12
 *
13
 */
14
class UCookie {
15
16
	/**
17
	 * Sends a cookie
18
	 *
19
	 * @param string $name
20
	 *        	the name of the cookie
21
	 * @param string $value
22
	 *        	The value of the cookie.
23
	 * @param int $duration
24
	 *        	default : 1 day
25
	 * @param string $path
26
	 *        	default : / the cookie will be available within the entire domain
27
	 * @param boolean $secure
28
	 *        	Indicates that the cookie should only be transmitted over asecure HTTPS
29
	 * @param boolean $httpOnly
30
	 *        	When true the cookie will be made accessible only through the HTTPprotocol
31
	 * @return boolean
32
	 */
33 1
	public static function set($name, $value, $duration = 60*60*24, $path = "/", $secure = false, $httpOnly = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $secure 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

33
	public static function set($name, $value, $duration = 60*60*24, $path = "/", /** @scrutinizer ignore-unused */ $secure = false, $httpOnly = false) {

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...
Unused Code introduced by
The parameter $httpOnly 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

33
	public static function set($name, $value, $duration = 60*60*24, $path = "/", $secure = false, /** @scrutinizer ignore-unused */ $httpOnly = false) {

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...
34 1
		\setcookie ( $name, $value, \time () + $duration, $path );
35 1
	}
36
37
	/**
38
	 * Returns the Cookie with the name $name
39
	 *
40
	 * @param string $name
41
	 * @param string $default
42
	 * @return null|string
43
	 */
44 2
	public static function get($name, $default = null) {
45 2
		return isset ( $_COOKIE [$name] ) ? $_COOKIE [$name] : $default;
46
	}
47
48
	/**
49
	 * Removes the cookie with the name $name
50
	 *
51
	 * @param string $name
52
	 * @param string $path
53
	 */
54 1
	public static function delete($name, $path = "/") {
55 1
		if (isset ( $_COOKIE [$name] )) {
56
			unset ( $_COOKIE [$name] );
57
		}
58 1
		\setcookie ( $name, "", \time () - 3600, $path );
59 1
	}
60
61
	/**
62
	 * Deletes all cookies
63
	 */
64 1
	public static function deleteAll($path = "/") {
65 1
		foreach ( $_COOKIE as $name => $value ) {
66
			self::delete ( $name, $path );
67
		}
68 1
	}
69
70
	/**
71
	 * Tests the existence of a cookie
72
	 *
73
	 * @param string $name
74
	 * @return boolean
75
	 * @since Ubiquity 2.0.11
76
	 */
77
	public static function exists($name) {
78
		return isset ( $_COOKIE [$name] );
79
	}
80
81
	/**
82
	 * Sends a raw cookie without urlencoding the cookie value
83
	 *
84
	 * @param string $name
85
	 *        	the name of the cookie
86
	 * @param string $value
87
	 *        	The value of the cookie.
88
	 * @param int $duration
89
	 *        	default : 1 day
90
	 * @param string $path
91
	 *        	default : / the cookie will be available within the entire domain
92
	 * @param boolean $secure
93
	 *        	Indicates that the cookie should only be transmitted over asecure HTTPS
94
	 * @param boolean $httpOnly
95
	 *        	When true the cookie will be made accessible only through the HTTPprotocol
96
	 * @return boolean
97
	 * @since Ubiquity 2.0.11
98
	 */
99
	public static function setRaw($name, $value, $duration = 60*60*24, $path = "/", $secure = false, $httpOnly = false) {
100
		return \setrawcookie ( $name, $value, \time () + $duration, $path, $secure, $httpOnly );
101
	}
102
}
103