Skip to content

Commit 241a244

Browse files
author
Wazabii
committed
Data types
1 parent cea1b9a commit 241a244

24 files changed

+572
-192
lines changed

Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(array $options = [])
3030
{
3131
$this->options = $options;
3232
}
33-
33+
3434
/**
3535
* Set option
3636
* https://www.php.net/manual/en/function.curl-setopt.php
@@ -47,11 +47,11 @@ public function setOption(int $key, mixed $value): void
4747
* Has option
4848
* https://www.php.net/manual/en/function.curl-setopt.php
4949
* @param int $key
50-
* @return void
50+
* @return bool
5151
*/
5252
public function hasOption(int $key): bool
5353
{
54-
return (bool)(isset($this->options[$key]));
54+
return (isset($this->options[$key]));
5555
}
5656

5757
/**

Cookies.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ public function __construct(
3535
$this->secure = $secure;
3636
$this->httpOnly = $httpOnly;
3737
}
38-
38+
3939
/**
4040
* Set cookie allowed path
4141
* @param string $path URI Path
42+
* @return self
4243
*/
43-
public function setPath(string $path)
44+
public function setPath(string $path): self
4445
{
4546
$this->path = $path;
4647
return $this;
@@ -49,18 +50,20 @@ public function setPath(string $path)
4950
/**
5051
* Set cookie allowed domain
5152
* @param string $domain URI Path
53+
* @return self
5254
*/
53-
public function setDomain(string $domain)
55+
public function setDomain(string $domain): self
5456
{
5557
$this->domain = $domain;
5658
return $this;
5759
}
5860

5961
/**
6062
* Set cookie secure flag (HTTPS only: true)
61-
* @param string $secure URI Path
63+
* @param bool $secure URI Path true/false
64+
* @return self
6265
*/
63-
public function setSecure(bool $secure)
66+
public function setSecure(bool $secure): self
6467
{
6568
$this->secure = $secure;
6669
return $this;
@@ -70,19 +73,21 @@ public function setSecure(bool $secure)
7073
* Set cookie http only flag. Cookie won't be accessible by scripting languages, such as JavaScript if true.
7174
* Can effectively help to reduce identity theft through XSS attacks, Not supported in all browsers tho
7275
* @param bool $httpOnly enable http only flag
76+
* @return self
7377
*/
74-
public function sethttpOnly(bool $httpOnly)
78+
public function sethttpOnly(bool $httpOnly): self
7579
{
7680
$this->httpOnly = $httpOnly;
7781
return $this;
7882
}
7983

8084

8185
/**
82-
* Set same site (Requires PHP version >= 7.3.0)
86+
* Set same site
8387
* @param string $samesite
88+
* @return self
8489
*/
85-
public function setSameSite(string $samesite)
90+
public function setSameSite(string $samesite): self
8691
{
8792
$samesite = ucfirst(strtolower($samesite));
8893
if ($samesite !== "None" && $samesite !== "Lax" && $samesite !== "Strict") {
@@ -97,6 +102,7 @@ public function setSameSite(string $samesite)
97102
* @param string $name
98103
* @param mixed $value
99104
* @param int $expires
105+
* @return void
100106
*/
101107
public function set(string $name, string $value, int $expires, bool $force = false): void
102108
{
@@ -113,11 +119,11 @@ public function set(string $name, string $value, int $expires, bool $force = fal
113119
/**
114120
* Check is cookie exists
115121
* @param string $name
116-
* @return boolean
122+
* @return bool
117123
*/
118124
public function has(string $name): bool
119125
{
120-
return (bool)(isset($_COOKIE[$name]));
126+
return (isset($_COOKIE[$name]));
121127
}
122128

123129
/**
@@ -147,11 +153,11 @@ public function delete(string $name): void
147153
/**
148154
* Check if cookies settings in this instance has great enough security to save e.g. CSRF token.
149155
* Can not be read or set in: frontend, cross domain or in http (only https)
150-
* @return boolean
156+
* @return bool
151157
*/
152158
public function isSecure(): bool
153159
{
154-
return (bool)($this->samesite === "Strict" && $this->secure && $this->httpOnly);
160+
return ($this->samesite === "Strict" && $this->secure && $this->httpOnly);
155161
}
156162

157163
/**

Dir.php

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,72 @@ public function __construct($dir)
1515
$this->dir = $dir;
1616
}
1717

18-
public function getDir(string $path = "")
18+
/**
19+
* Get root dir
20+
* @param string $path
21+
* @return string
22+
*/
23+
public function getDir(string $path = ""): string
1924
{
2025
return $this->dir . $path;
2126
}
2227

23-
public function getRoot(string $path = "")
28+
/**
29+
* Get root dir
30+
* @param string $path
31+
* @return string
32+
*/
33+
public function getRoot(string $path = ""): string
2434
{
2535
return $this->getDir($path);
2636
}
2737

28-
public function getResources(string $path = "")
38+
/**
39+
* Get resource dir
40+
* @param string $path
41+
* @return string
42+
*/
43+
public function getResources(string $path = ""): string
2944
{
3045
return $this->getDir("resources/{$path}");
3146
}
3247

33-
public function getPublic(string $path = "")
48+
/**
49+
* Get resource dir
50+
* @param string $path
51+
* @return string
52+
*/
53+
public function getPublic(string $path = ""): string
3454
{
3555
return $this->getDir("public/{$path}");
3656
}
3757

38-
public function getStorage(string $path = "")
58+
/**
59+
* Get storage dir
60+
* @param string $path
61+
* @return string
62+
*/
63+
public function getStorage(string $path = ""): string
3964
{
4065
return $this->getDir("storage/{$path}");
4166
}
4267

43-
public function getLogs(string $path = "")
68+
/**
69+
* Get log dir
70+
* @param string $path
71+
* @return string
72+
*/
73+
public function getLogs(string $path = ""): string
4474
{
4575
return $this->getStorage("logs/{$path}");
4676
}
4777

48-
public function getCaches(string $path = "")
78+
/**
79+
* Get cache dir
80+
* @param string $path
81+
* @return string
82+
*/
83+
public function getCaches(string $path = ""): string
4984
{
5085
return $this->getStorage("caches/{$path}");
5186
}

Env.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function drop(string $key): void
5353

5454
public function formatKey($key)
5555
{
56-
return Format\Str::value($key)->clearBreaks("-")->trim()->replaceSpecialChar()
56+
return Format\Str::value($key)->clearBreaks()->trim()->replaceSpecialChar()
5757
->trimSpaces()->replaceSpaces("-")->toUpper()->get();
5858
}
5959

Environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Environment implements EnvironmentInterface
1212

1313
public function __construct(array $env = [])
1414
{
15-
$this->env = array_merge(($_SERVER ?? []), $env);
15+
$this->env = array_merge($_SERVER, $env);
1616
}
1717

1818
/**

Headers.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@ public function __construct(array $headers = [])
1818
/**
1919
* Set new header
2020
* @param string $name
21-
* @param string/array $value
21+
* @param mixed $value
2222
* @return void
2323
*/
24-
public function setHeader($name, $value): void
24+
public function setHeader(string $name, mixed $value): void
2525
{
2626
$name = $this->normalizeKey($name);
2727
$this->headers[$name] = is_array($value) ? $value : array_map('trim', explode(';', $value));
2828
}
2929

3030
/**
3131
* Set new headers
32-
* @param string $name
33-
* @param string/array $value
32+
* @param array $arr
3433
* @return void
3534
*/
3635
public function setHeaders(array $arr): void
@@ -75,7 +74,7 @@ public function getHeader($name): array
7574
/**
7675
* Delete header from name/key
7776
* @param string $name name/key (case insensitive)
78-
* @return array
77+
* @return bool
7978
*/
8079
public function deleteHeader($name): bool
8180
{

Interfaces/CookiesInterface.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,77 @@
44

55
interface CookiesInterface
66
{
7+
/**
8+
* Set cookie allowed path
9+
* @param string $path URI Path
10+
* @return self
11+
*/
12+
public function setPath(string $path): self;
13+
14+
/**
15+
* Set cookie allowed domain
16+
* @param string $domain URI Path
17+
* @return self
18+
*/
19+
public function setDomain(string $domain): self;
20+
21+
/**
22+
* Set cookie secure flag (HTTPS only: true)
23+
* @param bool $secure URI Path true/false
24+
* @return self
25+
*/
26+
public function setSecure(bool $secure): self;
27+
28+
/**
29+
* Set cookie http only flag. Cookie won't be accessible by scripting languages, such as JavaScript if true.
30+
* Can effectively help to reduce identity theft through XSS attacks, Not supported in all browsers tho
31+
* @param bool $httpOnly enable http only flag
32+
* @return self
33+
*/
34+
public function sethttpOnly(bool $httpOnly): self;
35+
36+
/**
37+
* Set same site
38+
* @param string $samesite
39+
* @return self
40+
*/
41+
public function setSameSite(string $samesite): self;
42+
43+
/**
44+
* Set cookie
45+
* @param string $name
46+
* @param mixed $value
47+
* @param int $expires
48+
* @return void
49+
*/
750
public function set(string $name, string $value, int $expires, bool $force = false): void;
51+
52+
/**
53+
* Check is cookie exists
54+
* @param string $name
55+
* @return bool
56+
*/
857
public function has(string $name): bool;
58+
59+
/**
60+
* Get cookie
61+
* @param string $name
62+
* @param string|null $default
63+
* @return string|null
64+
*/
965
public function get(string $name, ?string $default = null): ?string;
66+
67+
/**
68+
* Delete Cookie
69+
* @param string $name
70+
* @return void
71+
*/
1072
public function delete(string $name): void;
73+
74+
/**
75+
* Check if cookies settings in this instance has great enough security to save e.g. CSRF token.
76+
* Can not be read or set in: frontend, cross domain or in http (only https)
77+
* @return bool
78+
*/
79+
public function isSecure(): bool;
1180
}

Interfaces/DirInterface.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,53 @@
44

55
interface DirInterface
66
{
7+
/**
8+
* Get root dir
9+
* @param string $path
10+
* @return string
11+
*/
12+
public function getDir(string $path = ""): string;
13+
14+
/**
15+
* Get root dir
16+
* @param string $path
17+
* @return string
18+
*/
19+
public function getRoot(string $path = ""): string;
20+
21+
/**
22+
* Get resource dir
23+
* @param string $path
24+
* @return string
25+
*/
26+
public function getResources(string $path = ""): string;
27+
28+
/**
29+
* Get resource dir
30+
* @param string $path
31+
* @return string
32+
*/
33+
public function getPublic(string $path = ""): string;
34+
35+
/**
36+
* Get storage dir
37+
* @param string $path
38+
* @return string
39+
*/
40+
public function getStorage(string $path = ""): string;
41+
42+
/**
43+
* Get log dir
44+
* @param string $path
45+
* @return string
46+
*/
47+
public function getLogs(string $path = ""): string;
48+
49+
50+
/**
51+
* Get cache dir
52+
* @param string $path
53+
* @return string
54+
*/
55+
public function getCaches(string $path = ""): string;
756
}

0 commit comments

Comments
 (0)