Skip to content

Commit 8755f42

Browse files
committed
Update code standards
1 parent b7ea1ff commit 8755f42

File tree

4 files changed

+29
-35
lines changed

4 files changed

+29
-35
lines changed

tests/data/app/controllers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ function GET($matches) {
130130
}
131131

132132
function POST() {
133-
setcookie('f', 'b', time() + 60, null, null, false, true);
134-
setcookie('foo', 'bar1', time() + 60, null, 'sub.localhost', false, true);
135-
setcookie('baz', 'bar2', time() + 60, null, 'sub.localhost', false, true);
133+
setcookie('f', 'b', ['expires' => time() + 60, 'path' => null, 'domain' => null, 'secure' => false, 'httponly' => true]);
134+
setcookie('foo', 'bar1', ['expires' => time() + 60, 'path' => null, 'domain' => 'sub.localhost', 'secure' => false, 'httponly' => true]);
135+
setcookie('baz', 'bar2', ['expires' => time() + 60, 'path' => null, 'domain' => 'sub.localhost', 'secure' => false, 'httponly' => true]);
136136
data::set('form', $_POST);
137137
include __DIR__.'/view/cookies.php';
138138
}

tests/data/app/data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
class data {
33

4-
public static $filename = '/db';
4+
public static string $filename = '/db';
55

66
public static function get($key) {
77
$data = self::load();

tests/data/rest/index.php

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,26 @@
55
$GLOBALS['RESTmap'] = [];
66

77
$GLOBALS['RESTmap']['GET'] = [
8-
'user' => function() {
9-
return [
10-
'name' => 'davert',
11-
'email' => 'davert@mail.ua',
12-
'aliases' => [
13-
'DavertMik',
14-
'davert.ua'
15-
],
16-
'address' => [
17-
'city' => 'Kyiv',
18-
'country' => 'Ukraine',
19-
]];
20-
},
21-
'zeroes' => function() {
22-
return [
23-
'responseCode' => 0,
24-
'message' => 'OK',
25-
'data' => [
26-
9,
27-
0,
28-
0
29-
],
30-
];
31-
},
8+
'user' => fn() => [
9+
'name' => 'davert',
10+
'email' => 'davert@mail.ua',
11+
'aliases' => [
12+
'DavertMik',
13+
'davert.ua'
14+
],
15+
'address' => [
16+
'city' => 'Kyiv',
17+
'country' => 'Ukraine',
18+
]],
19+
'zeroes' => fn() => [
20+
'responseCode' => 0,
21+
'message' => 'OK',
22+
'data' => [
23+
9,
24+
0,
25+
0
26+
],
27+
],
3228
'foo' => function() {
3329
if (isset($_SERVER['HTTP_FOO'])) {
3430
return 'foo: "' . $_SERVER['HTTP_FOO'] . '"';
@@ -43,11 +39,9 @@
4339
$name = $_POST['name'];
4440
return ['name' => $name];
4541
},
46-
'file-upload' => function() {
47-
return [
48-
'uploaded' => isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name']),
49-
];
50-
}
42+
'file-upload' => fn() => [
43+
'uploaded' => isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name']),
44+
]
5145
];
5246

5347
$GLOBALS['RESTmap']['PUT'] = [

tests/data/rest/server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ function RESTServer()
1717
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
1818
$data = $_GET;
1919
} else if ($tmp = file_get_contents('php://input')) {
20-
$data = json_decode($tmp);
20+
$data = json_decode($tmp, null, 512, JSON_THROW_ON_ERROR);
2121
}
2222

2323
$response = call_user_func($callback, $data);
2424
if (is_scalar($response)) {
2525
print $response;
2626
return;
2727
}
28-
print json_encode($response);
28+
print json_encode($response, JSON_THROW_ON_ERROR);
2929
}
3030
}

0 commit comments

Comments
 (0)