Skip to content

Commit 804688d

Browse files
committed
added PHP 7.1 scalar and return type hints
1 parent 2051e3d commit 804688d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+250
-586
lines changed

src/Application/Application.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ public function __construct(IPresenterFactory $presenterFactory, IRouter $router
7676

7777
/**
7878
* Dispatch a HTTP request to a front controller.
79-
* @return void
8079
*/
81-
public function run()
80+
public function run(): void
8281
{
8382
try {
8483
$this->onStartup($this);
@@ -103,10 +102,7 @@ public function run()
103102
}
104103

105104

106-
/**
107-
* @return Request
108-
*/
109-
public function createInitialRequest()
105+
public function createInitialRequest(): Request
110106
{
111107
$request = $this->router->match($this->httpRequest);
112108
if (!$request instanceof Request) {
@@ -116,10 +112,7 @@ public function createInitialRequest()
116112
}
117113

118114

119-
/**
120-
* @return void
121-
*/
122-
public function processRequest(Request $request)
115+
public function processRequest(Request $request): void
123116
{
124117
process:
125118
if (count($this->requests) > self::$maxLoop) {
@@ -152,10 +145,7 @@ public function processRequest(Request $request)
152145
}
153146

154147

155-
/**
156-
* @return void
157-
*/
158-
public function processException($e)
148+
public function processException(\Throwable $e): void
159149
{
160150
if (!$e instanceof BadRequestException && $this->httpResponse instanceof Nette\Http\Response) {
161151
$this->httpResponse->warnOnBuffer = FALSE;
@@ -181,17 +171,16 @@ public function processException($e)
181171
* Returns all processed requests.
182172
* @return Request[]
183173
*/
184-
public function getRequests()
174+
public function getRequests(): array
185175
{
186176
return $this->requests;
187177
}
188178

189179

190180
/**
191181
* Returns current presenter.
192-
* @return IPresenter
193182
*/
194-
public function getPresenter()
183+
public function getPresenter(): IPresenter
195184
{
196185
return $this->presenter;
197186
}
@@ -202,19 +191,17 @@ public function getPresenter()
202191

203192
/**
204193
* Returns router.
205-
* @return IRouter
206194
*/
207-
public function getRouter()
195+
public function getRouter(): IRouter
208196
{
209197
return $this->router;
210198
}
211199

212200

213201
/**
214202
* Returns presenter factory.
215-
* @return IPresenterFactory
216203
*/
217-
public function getPresenterFactory()
204+
public function getPresenterFactory(): IPresenterFactory
218205
{
219206
return $this->presenterFactory;
220207
}

src/Application/ErrorPresenter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public function __construct(ILogger $logger = NULL)
3131
}
3232

3333

34-
/**
35-
* @return Application\IResponse
36-
*/
37-
public function run(Application\Request $request)
34+
public function run(Application\Request $request): Application\IResponse
3835
{
3936
$e = $request->getParameter('exception');
4037
if ($e instanceof Application\BadRequestException) {

src/Application/Helpers.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ class Helpers
2121

2222
/**
2323
* Splits name into [module, presenter] or [presenter, action]
24-
* @return array
2524
*/
26-
public static function splitName($name)
25+
public static function splitName(string $name): array
2726
{
2827
$pos = strrpos($name, ':');
2928
return $pos === FALSE

src/Application/IPresenter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
interface IPresenter
1717
{
1818

19-
/**
20-
* @return IResponse
21-
*/
22-
function run(Request $request);
19+
function run(Request $request): IResponse;
2320

2421
}

src/Application/IPresenterFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ interface IPresenterFactory
2222
* @return string class name
2323
* @throws InvalidPresenterException
2424
*/
25-
function getPresenterClass(&$name);
25+
function getPresenterClass(string &$name): string;
2626

2727
/**
2828
* Creates new presenter instance.
2929
* @param string presenter name
30-
* @return IPresenter
3130
*/
32-
function createPresenter($name);
31+
function createPresenter(string $name): IPresenter;
3332

3433
}

src/Application/IResponse.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ interface IResponse
2020

2121
/**
2222
* Sends response to output.
23-
* @return void
2423
*/
25-
function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse);
24+
function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse): void;
2625

2726
}

src/Application/IRouter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ interface IRouter
2222

2323
/**
2424
* Maps HTTP request to a Request object.
25-
* @return Request|NULL
2625
*/
27-
function match(Nette\Http\IRequest $httpRequest);
26+
function match(Nette\Http\IRequest $httpRequest): ?Request;
2827

2928
/**
3029
* Constructs absolute URL from Request object.
31-
* @return string|NULL
3230
*/
33-
function constructUrl(Request $appRequest, Nette\Http\Url $refUrl);
31+
function constructUrl(Request $appRequest, Nette\Http\Url $refUrl): ?string;
3432

3533
}

src/Application/LinkGenerator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ public function __construct(IRouter $router, Nette\Http\Url $refUrl, IPresenterF
4040
/**
4141
* Generates URL to presenter.
4242
* @param string destination in format "[[[module:]presenter:]action] [#fragment]"
43-
* @return string
4443
* @throws UI\InvalidLinkException
4544
*/
46-
public function link($dest, array $params = [])
45+
public function link(string $dest, array $params = []): string
4746
{
4847
if (!preg_match('~^([\w:]+):(\w*+)(#.*)?()\z~', $dest, $m)) {
4948
throw new UI\InvalidLinkException("Invalid link destination '$dest'.");

src/Application/MicroPresenter.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,14 @@ public function __construct(Nette\DI\Container $context = NULL, Http\IRequest $h
4646

4747
/**
4848
* Gets the context.
49-
* @return Nette\DI\Container
5049
*/
51-
public function getContext()
50+
public function getContext(): Nette\DI\Container
5251
{
5352
return $this->context;
5453
}
5554

5655

57-
/**
58-
* @return Nette\Application\IResponse
59-
*/
60-
public function run(Application\Request $request)
56+
public function run(Application\Request $request): Nette\Application\IResponse
6157
{
6258
$this->request = $request;
6359

@@ -109,10 +105,8 @@ public function run(Application\Request $request)
109105

110106
/**
111107
* Template factory.
112-
* @param string
113-
* @return Application\UI\ITemplate
114108
*/
115-
public function createTemplate($class = NULL, callable $latteFactory = NULL)
109+
public function createTemplate(string $class = NULL, callable $latteFactory = NULL): Application\UI\ITemplate
116110
{
117111
$latte = $latteFactory ? $latteFactory() : $this->getContext()->getByType(Nette\Bridges\ApplicationLatte\ILatteFactory::class)->create();
118112
$template = $class ? new $class : new Nette\Bridges\ApplicationLatte\Template($latte);
@@ -131,33 +125,26 @@ public function createTemplate($class = NULL, callable $latteFactory = NULL)
131125

132126
/**
133127
* Redirects to another URL.
134-
* @param string
135-
* @param int HTTP code
136-
* @return Nette\Application\Responses\RedirectResponse
128+
* @param int $code HTTP code
137129
*/
138-
public function redirectUrl($url, $code = Http\IResponse::S302_FOUND)
130+
public function redirectUrl(string $url, int $code = Http\IResponse::S302_FOUND): Nette\Application\Responses\RedirectResponse
139131
{
140132
return new Responses\RedirectResponse($url, $code);
141133
}
142134

143135

144136
/**
145137
* Throws HTTP error.
146-
* @param string
147-
* @param int HTTP error code
148-
* @return void
138+
* @param int $code HTTP error code
149139
* @throws Nette\Application\BadRequestException
150140
*/
151-
public function error($message = NULL, $code = Http\IResponse::S404_NOT_FOUND)
141+
public function error(string $message = NULL, int $code = Http\IResponse::S404_NOT_FOUND): void
152142
{
153143
throw new Application\BadRequestException($message, $code);
154144
}
155145

156146

157-
/**
158-
* @return Nette\Application\Request
159-
*/
160-
public function getRequest()
147+
public function getRequest(): Nette\Application\Request
161148
{
162149
return $this->request;
163150
}

src/Application/PresenterFactory.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ public function __construct(callable $factory = NULL)
4444
/**
4545
* Creates new presenter instance.
4646
* @param string presenter name
47-
* @return IPresenter
4847
*/
49-
public function createPresenter($name)
48+
public function createPresenter(string $name): IPresenter
5049
{
5150
return ($this->factory)($this->getPresenterClass($name));
5251
}
@@ -58,7 +57,7 @@ public function createPresenter($name)
5857
* @return string class name
5958
* @throws InvalidPresenterException
6059
*/
61-
public function getPresenterClass(&$name)
60+
public function getPresenterClass(string &$name): string
6261
{
6362
if (isset($this->cache[$name])) {
6463
return $this->cache[$name];
@@ -117,11 +116,9 @@ public function setMapping(array $mapping)
117116

118117
/**
119118
* Formats presenter class name from its name.
120-
* @param string
121-
* @return string
122119
* @internal
123120
*/
124-
public function formatPresenterClass($presenter)
121+
public function formatPresenterClass(string $presenter): string
125122
{
126123
$parts = explode(':', $presenter);
127124
$mapping = isset($parts[1], $this->mapping[$parts[0]])
@@ -137,11 +134,9 @@ public function formatPresenterClass($presenter)
137134

138135
/**
139136
* Formats presenter name from class name.
140-
* @param string
141-
* @return string|NULL
142137
* @internal
143138
*/
144-
public function unformatPresenterClass($class)
139+
public function unformatPresenterClass(string $class): ?string
145140
{
146141
foreach ($this->mapping as $module => $mapping) {
147142
$mapping = str_replace(['\\', '*'], ['\\\\', '(\w+)'], $mapping);

0 commit comments

Comments
 (0)