Skip to content

Commit 0d7b79b

Browse files
authored
Merge pull request #528 from flightphp/add-typehint
Replaced some docblocks to native PHP 7.4 typehint
2 parents d1c47c2 + 751f17b commit 0d7b79b

File tree

12 files changed

+113
-144
lines changed

12 files changed

+113
-144
lines changed

composer.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
]
3434
},
3535
"require-dev": {
36-
"ext-pdo_sqlite": "*",
36+
"ext-pdo_sqlite": "*",
3737
"phpunit/phpunit": "^9.5",
3838
"phpstan/phpstan": "^1.10",
3939
"phpstan/extension-installer": "^1.3",
@@ -46,14 +46,15 @@
4646
},
4747
"scripts": {
4848
"test": "phpunit",
49-
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage --coverage-clover=clover.xml && vendor/bin/coverage-check clover.xml 100",
49+
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage --coverage-clover=clover.xml && vendor/bin/coverage-check clover.xml 100",
5050
"lint": "phpstan --no-progress -cphpstan.neon"
5151
},
5252
"suggest": {
53-
"latte/latte": "Latte template engine",
54-
"tracy/tracy": "Tracy debugger"
53+
"latte/latte": "Latte template engine",
54+
"tracy/tracy": "Tracy debugger",
55+
"phpstan": "PHP Static Analyzer"
5556
},
56-
"replace": {
57-
"mikecao/flight": "2.0.2"
58-
}
57+
"replace": {
58+
"mikecao/flight": "2.0.2"
59+
}
5960
}

flight.sublime-project

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"folders": [
33
{
44
"path": ".",
5+
"name": "FlightPHP/Core",
56
}
67
],
78
"settings": {
@@ -12,10 +13,29 @@
1213
"intelephense.format.braces": "psr12",
1314
},
1415
},
15-
"formatters":
16-
{
17-
"embedding.php": "LSP-intelephense"
18-
},
16+
"formatters": {
17+
"embedding.php": "LSP-intelephense",
18+
"source.json.composer": "LSP-json",
19+
"source.json.sublime": "LSP-json",
20+
},
21+
"LSP-html": {
22+
"enabled": false
23+
},
24+
"LSP-tailwindcss": {
25+
"enabled": false
26+
},
1927
},
2028
},
29+
"build_systems": [
30+
{
31+
"name": "Linter - HARD",
32+
"quiet": true,
33+
"shell_cmd": "composer lint -- --no-ansi -lmax"
34+
},
35+
{
36+
"name": "Linter - Default",
37+
"quiet": true,
38+
"shell_cmd": "composer lint -- --no-ansi"
39+
}
40+
],
2141
}

flight/core/Dispatcher.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Dispatcher
4141
*
4242
* @throws Exception
4343
*
44-
* @return mixed|null Output of callback
44+
* @return mixed Output of callback
4545
*/
4646
public function run(string $name, array $params = [])
4747
{
@@ -80,7 +80,7 @@ public function set(string $name, callable $callback): void
8080
*
8181
* @param string $name Event name
8282
*
83-
* @return callable $callback Callback function
83+
* @return ?callable $callback Callback function
8484
*/
8585
public function get(string $name): ?callable
8686
{
@@ -100,10 +100,9 @@ public function has(string $name): bool
100100
}
101101

102102
/**
103-
* Clears an event. If no name is given,
104-
* all events are removed.
103+
* Clears an event. If no name is given, all events are removed.
105104
*
106-
* @param string|null $name Event name
105+
* @param ?string $name Event name
107106
*/
108107
public function clear(?string $name = null): void
109108
{

flight/core/Loader.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
use Closure;
1414
use Exception;
15-
use ReflectionClass;
16-
use ReflectionException;
1715

1816
/**
1917
* The Loader class is responsible for loading objects. It maintains
@@ -25,7 +23,7 @@ class Loader
2523
{
2624
/**
2725
* Registered classes.
28-
* @var array<string, array{class-string, array<int, mixed>, ?callable}> $classes
26+
* @var array<string, array{class-string|Closure(): object, array<int, mixed>, ?callable}> $classes
2927
*/
3028
protected array $classes = [];
3129

@@ -46,7 +44,7 @@ class Loader
4644
* @template T of object
4745
*
4846
* @param string $name Registry name
49-
* @param class-string<T> $class Class name or function to instantiate class
47+
* @param class-string<T>|Closure(): T $class Class name or function to instantiate class
5048
* @param array<int, mixed> $params Class initialization parameters
5149
* @param ?callable(T $instance): void $callback $callback Function to call after object instantiation
5250
*/
@@ -75,7 +73,7 @@ public function unregister(string $name): void
7573
*
7674
* @throws Exception
7775
*
78-
* @return object Class instance
76+
* @return ?object Class instance
7977
*/
8078
public function load(string $name, bool $shared = true): ?object
8179
{
@@ -112,7 +110,7 @@ public function load(string $name, bool $shared = true): ?object
112110
*
113111
* @param string $name Instance name
114112
*
115-
* @return object Class instance
113+
* @return ?object Class instance
116114
*/
117115
public function getInstance(string $name): ?object
118116
{

flight/net/Request.php

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,104 +40,102 @@
4040
class Request
4141
{
4242
/**
43-
* @var string URL being requested
43+
* URL being requested
4444
*/
4545
public string $url;
4646

4747
/**
48-
* @var string Parent subdirectory of the URL
48+
* Parent subdirectory of the URL
4949
*/
5050
public string $base;
5151

5252
/**
53-
* @var string Request method (GET, POST, PUT, DELETE)
53+
* Request method (GET, POST, PUT, DELETE)
5454
*/
5555
public string $method;
5656

5757
/**
58-
* @var string Referrer URL
58+
* Referrer URL
5959
*/
6060
public string $referrer;
6161

6262
/**
63-
* @var string IP address of the client
63+
* IP address of the client
6464
*/
6565
public string $ip;
6666

6767
/**
68-
* @var bool Whether the request is an AJAX request
68+
* Whether the request is an AJAX request
6969
*/
7070
public bool $ajax;
7171

7272
/**
73-
* @var string Server protocol (http, https)
73+
* Server protocol (http, https)
7474
*/
7575
public string $scheme;
7676

7777
/**
78-
* @var string Browser information
78+
* Browser information
7979
*/
8080
public string $user_agent;
8181

8282
/**
83-
* @var string Content type
83+
* Content type
8484
*/
8585
public string $type;
8686

8787
/**
88-
* @var int Content length
88+
* Content length
8989
*/
9090
public int $length;
9191

9292
/**
93-
* @var Collection Query string parameters
93+
* Query string parameters
9494
*/
9595
public Collection $query;
9696

9797
/**
98-
* @var Collection Post parameters
98+
* Post parameters
9999
*/
100100
public Collection $data;
101101

102102
/**
103-
* @var Collection Cookie parameters
103+
* Cookie parameters
104104
*/
105105
public Collection $cookies;
106106

107107
/**
108-
* @var Collection Uploaded files
108+
* Uploaded files
109109
*/
110110
public Collection $files;
111111

112112
/**
113-
* @var bool Whether the connection is secure
113+
* Whether the connection is secure
114114
*/
115115
public bool $secure;
116116

117117
/**
118-
* @var string HTTP accept parameters
118+
* HTTP accept parameters
119119
*/
120120
public string $accept;
121121

122122
/**
123-
* @var string Proxy IP address of the client
123+
* Proxy IP address of the client
124124
*/
125125
public string $proxy_ip;
126126

127127
/**
128-
* @var string HTTP host name
128+
* HTTP host name
129129
*/
130130
public string $host;
131131

132132
/**
133133
* Stream path for where to pull the request body from
134-
*
135-
* @var string
136134
*/
137135
private string $stream_path = 'php://input';
138136

139137
/**
140-
* @var string Raw HTTP request body
138+
* Raw HTTP request body
141139
*/
142140
public string $body = '';
143141

@@ -146,7 +144,7 @@ class Request
146144
*
147145
* @param array<string, mixed> $config Request configuration
148146
*/
149-
public function __construct($config = [])
147+
public function __construct(array $config = [])
150148
{
151149
// Default properties
152150
if (empty($config)) {
@@ -179,9 +177,9 @@ public function __construct($config = [])
179177
* Initialize request properties.
180178
*
181179
* @param array<string, mixed> $properties Array of request properties
182-
* @return self
180+
* @return $this
183181
*/
184-
public function init(array $properties = [])
182+
public function init(array $properties = []): self
185183
{
186184
// Set all the defined properties
187185
foreach ($properties as $name => $value) {
@@ -322,6 +320,7 @@ public static function parseQuery(string $url): array
322320
return $params;
323321
}
324322

323+
/** @return 'http'|'https' */
325324
public static function getScheme(): string
326325
{
327326
if (

0 commit comments

Comments
 (0)