Skip to content

Commit 07414ed

Browse files
committed
added PHP 7.0 scalar and return type hints
1 parent fe193ae commit 07414ed

File tree

14 files changed

+130
-307
lines changed

14 files changed

+130
-307
lines changed

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: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,17 @@ 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
}
@@ -94,69 +92,60 @@ public function getContentType()
9492

9593
/**
9694
* Returns the size of an uploaded file.
97-
* @return int
9895
*/
99-
public function getSize()
96+
public function getSize(): int
10097
{
10198
return $this->size;
10299
}
103100

104101

105102
/**
106103
* Returns the path to an uploaded file.
107-
* @return string
108104
*/
109-
public function getTemporaryFile()
105+
public function getTemporaryFile(): string
110106
{
111107
return $this->tmpName;
112108
}
113109

114110

115111
/**
116112
* Returns the path to an uploaded file.
117-
* @return string
118113
*/
119-
public function __toString()
114+
public function __toString(): string
120115
{
121116
return (string) $this->tmpName;
122117
}
123118

124119

125120
/**
126121
* Returns the error code. {@link http://php.net/manual/en/features.file-upload.errors.php}
127-
* @return int
128122
*/
129-
public function getError()
123+
public function getError(): int
130124
{
131125
return $this->error;
132126
}
133127

134128

135129
/**
136130
* Is there any error?
137-
* @return bool
138131
*/
139-
public function isOk()
132+
public function isOk(): bool
140133
{
141134
return $this->error === UPLOAD_ERR_OK;
142135
}
143136

144137

145-
/**
146-
* @return bool
147-
*/
148-
public function hasFile()
138+
public function hasFile(): bool
149139
{
150140
return $this->error !== UPLOAD_ERR_NO_FILE;
151141
}
152142

153143

154144
/**
155145
* Move uploaded file to new location.
156-
* @param string
157146
* @return static
158147
*/
159-
public function move($dest)
148+
public function move(string $dest)
160149
{
161150
$dir = dirname($dest);
162151
@mkdir($dir, 0777, TRUE); // @ - dir may already exist
@@ -179,20 +168,18 @@ function ($message) use ($dest) {
179168

180169
/**
181170
* Is uploaded file GIF, PNG or JPEG?
182-
* @return bool
183171
*/
184-
public function isImage()
172+
public function isImage(): bool
185173
{
186174
return in_array($this->getContentType(), ['image/gif', 'image/png', 'image/jpeg'], TRUE);
187175
}
188176

189177

190178
/**
191179
* Returns the image.
192-
* @return Nette\Utils\Image
193180
* @throws Nette\Utils\ImageException
194181
*/
195-
public function toImage()
182+
public function toImage(): Nette\Utils\Image
196183
{
197184
return Nette\Utils\Image::fromFile($this->tmpName);
198185
}

src/Http/Helpers.php

Lines changed: 2 additions & 4 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
list($mask, $size) = explode('/', $mask . '/');
4341
$tmp = function ($n) { return sprintf('%032b', $n); };

src/Http/IRequest.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,94 +27,80 @@ 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
9786
* @return string|NULL
9887
*/
99-
function getHeader($header);
88+
function getHeader(string $header);
10089

10190
/**
10291
* Returns all HTTP headers.
103-
* @return array
10492
*/
105-
function getHeaders();
93+
function getHeaders(): array;
10694

10795
/**
10896
* Is the request is sent via secure channel (https).
109-
* @return bool
11097
*/
111-
function isSecured();
98+
function isSecured(): bool;
11299

113100
/**
114101
* Is AJAX request?
115-
* @return bool
116102
*/
117-
function isAjax();
103+
function isAjax(): bool;
118104

119105
/**
120106
* Returns the IP address of the remote client.

0 commit comments

Comments
 (0)