Skip to content

Commit 9cd362a

Browse files
committed
added PHP 7.1 scalar and return type hints
1 parent c40daec commit 9cd362a

14 files changed

Lines changed: 158 additions & 372 deletions

src/Bridges/HttpTracy/SessionPanel.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ class SessionPanel implements Tracy\IBarPanel
2222

2323
/**
2424
* Renders tab.
25-
* @return string
2625
*/
27-
public function getTab()
26+
public function getTab(): string
2827
{
2928
ob_start(function () {});
3029
require __DIR__ . '/templates/SessionPanel.tab.phtml';
@@ -34,9 +33,8 @@ public function getTab()
3433

3534
/**
3635
* Renders panel.
37-
* @return string
3836
*/
39-
public function getPanel()
37+
public function getPanel(): string
4038
{
4139
ob_start(function () {});
4240
require __DIR__ . '/templates/SessionPanel.panel.phtml';

src/Http/Context.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ public function __construct(IRequest $request, IResponse $response)
3636
/**
3737
* Attempts to cache the sent entity by its last modification date.
3838
* @param string|int|\DateTimeInterface last modified time
39-
* @param string strong entity tag validator
40-
* @return bool
4139
*/
42-
public function isModified($lastModified = NULL, $etag = NULL)
40+
public function isModified($lastModified = NULL, string $etag = NULL): bool
4341
{
4442
if ($lastModified) {
4543
$this->response->setHeader('Last-Modified', Helpers::formatDate($lastModified));
@@ -83,19 +81,13 @@ public function isModified($lastModified = NULL, $etag = NULL)
8381
}
8482

8583

86-
/**
87-
* @return IRequest
88-
*/
89-
public function getRequest()
84+
public function getRequest(): IRequest
9085
{
9186
return $this->request;
9287
}
9388

9489

95-
/**
96-
* @return IResponse
97-
*/
98-
public function getResponse()
90+
public function getResponse(): IResponse
9991
{
10092
return $this->response;
10193
}

src/Http/FileUpload.php

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,26 @@ public function __construct($value)
6161

6262
/**
6363
* Returns the file name.
64-
* @return string
6564
*/
66-
public function getName()
65+
public function getName(): string
6766
{
6867
return $this->name;
6968
}
7069

7170

7271
/**
7372
* Returns the sanitized file name.
74-
* @return string
7573
*/
76-
public function getSanitizedName()
74+
public function getSanitizedName(): string
7775
{
7876
return trim(Nette\Utils\Strings::webalize($this->name, '.', FALSE), '.-');
7977
}
8078

8179

8280
/**
8381
* Returns the MIME content type of an uploaded file.
84-
* @return string|NULL
8582
*/
86-
public function getContentType()
83+
public function getContentType(): ?string
8784
{
8885
if ($this->isOk() && $this->type === NULL) {
8986
$this->type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->tmpName);
@@ -94,69 +91,60 @@ public function getContentType()
9491

9592
/**
9693
* Returns the size of an uploaded file.
97-
* @return int
9894
*/
99-
public function getSize()
95+
public function getSize(): int
10096
{
10197
return $this->size;
10298
}
10399

104100

105101
/**
106102
* Returns the path to an uploaded file.
107-
* @return string
108103
*/
109-
public function getTemporaryFile()
104+
public function getTemporaryFile(): string
110105
{
111106
return $this->tmpName;
112107
}
113108

114109

115110
/**
116111
* Returns the path to an uploaded file.
117-
* @return string
118112
*/
119-
public function __toString()
113+
public function __toString(): string
120114
{
121115
return (string) $this->tmpName;
122116
}
123117

124118

125119
/**
126120
* Returns the error code. {@link http://php.net/manual/en/features.file-upload.errors.php}
127-
* @return int
128121
*/
129-
public function getError()
122+
public function getError(): int
130123
{
131124
return $this->error;
132125
}
133126

134127

135128
/**
136129
* Is there any error?
137-
* @return bool
138130
*/
139-
public function isOk()
131+
public function isOk(): bool
140132
{
141133
return $this->error === UPLOAD_ERR_OK;
142134
}
143135

144136

145-
/**
146-
* @return bool
147-
*/
148-
public function hasFile()
137+
public function hasFile(): bool
149138
{
150139
return $this->error !== UPLOAD_ERR_NO_FILE;
151140
}
152141

153142

154143
/**
155144
* Move uploaded file to new location.
156-
* @param string
157145
* @return static
158146
*/
159-
public function move($dest)
147+
public function move(string $dest)
160148
{
161149
$dir = dirname($dest);
162150
@mkdir($dir, 0777, TRUE); // @ - dir may already exist
@@ -179,40 +167,36 @@ function ($message) use ($dest) {
179167

180168
/**
181169
* Is uploaded file GIF, PNG or JPEG?
182-
* @return bool
183170
*/
184-
public function isImage()
171+
public function isImage(): bool
185172
{
186173
return in_array($this->getContentType(), ['image/gif', 'image/png', 'image/jpeg'], TRUE);
187174
}
188175

189176

190177
/**
191178
* Returns the image.
192-
* @return Nette\Utils\Image
193179
* @throws Nette\Utils\ImageException
194180
*/
195-
public function toImage()
181+
public function toImage(): Nette\Utils\Image
196182
{
197183
return Nette\Utils\Image::fromFile($this->tmpName);
198184
}
199185

200186

201187
/**
202188
* Returns the dimensions of an uploaded image as array.
203-
* @return array|NULL
204189
*/
205-
public function getImageSize()
190+
public function getImageSize(): ?array
206191
{
207192
return $this->isOk() ? @getimagesize($this->tmpName) : NULL; // @ - files smaller than 12 bytes causes read error
208193
}
209194

210195

211196
/**
212197
* Get file contents.
213-
* @return string|NULL
214198
*/
215-
public function getContents()
199+
public function getContents(): ?string
216200
{
217201
// future implementation can try to work around safe_mode and open_basedir limitations
218202
return $this->isOk() ? file_get_contents($this->tmpName) : NULL;

src/Http/Helpers.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ class Helpers
2323
/**
2424
* Returns HTTP valid date format.
2525
* @param string|int|\DateTimeInterface
26-
* @return string
2726
*/
28-
public static function formatDate($time)
27+
public static function formatDate($time): string
2928
{
3029
$time = DateTime::from($time);
3130
$time->setTimezone(new \DateTimeZone('GMT'));
@@ -35,9 +34,8 @@ public static function formatDate($time)
3534

3635
/**
3736
* Is IP address in CIDR block?
38-
* @return bool
3937
*/
40-
public static function ipMatch($ip, $mask)
38+
public static function ipMatch($ip, $mask): bool
4139
{
4240
[$mask, $size] = explode('/', $mask . '/');
4341
$tmp = function ($n) { return sprintf('%032b', $n); };
@@ -53,10 +51,9 @@ public static function ipMatch($ip, $mask)
5351

5452
/**
5553
* Removes duplicate cookies from response.
56-
* @return void
5754
* @internal
5855
*/
59-
public static function removeDuplicateCookies()
56+
public static function removeDuplicateCookies(): void
6057
{
6158
if (headers_sent($file, $line) || ini_get('suhosin.cookie.encrypt')) {
6259
return;

src/Http/IRequest.php

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,111 +27,93 @@ interface IRequest
2727

2828
/**
2929
* Returns URL object.
30-
* @return UrlScript
3130
*/
32-
function getUrl();
31+
function getUrl(): UrlScript;
3332

3433
/********************* query, post, files & cookies ****************d*g**/
3534

3635
/**
3736
* Returns variable provided to the script via URL query ($_GET).
3837
* If no key is passed, returns the entire array.
39-
* @param string key
4038
* @return mixed
4139
*/
42-
function getQuery($key = NULL);
40+
function getQuery(string $key = NULL);
4341

4442
/**
4543
* Returns variable provided to the script via POST method ($_POST).
4644
* If no key is passed, returns the entire array.
47-
* @param string key
4845
* @return mixed
4946
*/
50-
function getPost($key = NULL);
47+
function getPost(string $key = NULL);
5148

5249
/**
5350
* Returns uploaded file.
54-
* @param string key
5551
* @return FileUpload|array|NULL
5652
*/
57-
function getFile($key);
53+
function getFile(string $key);
5854

5955
/**
6056
* Returns uploaded files.
61-
* @return array
6257
*/
63-
function getFiles();
58+
function getFiles(): array;
6459

6560
/**
6661
* Returns variable provided to the script via HTTP cookies.
67-
* @param string key
6862
* @return mixed
6963
*/
70-
function getCookie($key);
64+
function getCookie(string $key);
7165

7266
/**
7367
* Returns variables provided to the script via HTTP cookies.
74-
* @return array
7568
*/
76-
function getCookies();
69+
function getCookies(): array;
7770

7871
/********************* method & headers ****************d*g**/
7972

8073
/**
8174
* Returns HTTP request method (GET, POST, HEAD, PUT, ...). The method is case-sensitive.
82-
* @return string
8375
*/
84-
function getMethod();
76+
function getMethod(): string;
8577

8678
/**
8779
* Checks HTTP request method.
88-
* @param string
89-
* @return bool
9080
*/
91-
function isMethod($method);
81+
function isMethod(string $method): bool;
9282

9383
/**
9484
* Return the value of the HTTP header. Pass the header name as the
9585
* plain, HTTP-specified header name (e.g. 'Accept-Encoding').
96-
* @param string
97-
* @return string|NULL
9886
*/
99-
function getHeader($header);
87+
function getHeader(string $header): ?string;
10088

10189
/**
10290
* Returns all HTTP headers.
103-
* @return array
10491
*/
105-
function getHeaders();
92+
function getHeaders(): array;
10693

10794
/**
10895
* Is the request is sent via secure channel (https).
109-
* @return bool
11096
*/
111-
function isSecured();
97+
function isSecured(): bool;
11298

11399
/**
114100
* Is AJAX request?
115-
* @return bool
116101
*/
117-
function isAjax();
102+
function isAjax(): bool;
118103

119104
/**
120105
* Returns the IP address of the remote client.
121-
* @return string|NULL
122106
*/
123-
function getRemoteAddress();
107+
function getRemoteAddress(): ?string;
124108

125109
/**
126110
* Returns the host of the remote client.
127-
* @return string|NULL
128111
*/
129-
function getRemoteHost();
112+
function getRemoteHost(): ?string;
130113

131114
/**
132115
* Returns raw content of HTTP request body.
133-
* @return string|NULL
134116
*/
135-
function getRawBody();
117+
function getRawBody(): ?string;
136118

137119
}

0 commit comments

Comments
 (0)