Issues (5)

index.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
use midorikocak\nano\Api;
6
7
require __DIR__ . '/vendor/autoload.php';
8
9
$api = new Api();
10
11
12
$message = 'Welcome to Nano';
13
14
$api->get('/', function () use ($message) {
0 ignored issues
show
The method get() does not exist on midorikocak\nano\Api. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
$api->/** @scrutinizer ignore-call */ 
15
      get('/', function () use ($message) {
Loading history...
15
    echo json_encode(['message' => $message], JSON_THROW_ON_ERROR, 512);
16
    http_response_code(200);
17
});
18
19
$api->post('/', function () use ($message) {
0 ignored issues
show
The method post() does not exist on midorikocak\nano\Api. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
$api->/** @scrutinizer ignore-call */ 
20
      post('/', function () use ($message) {
Loading history...
The import $message is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
20
    $input = (array)json_decode(file_get_contents('php://input'), true, 512, JSON_THROW_ON_ERROR);
21
    echo json_encode($input, JSON_THROW_ON_ERROR, 512);
22
    http_response_code(201);
23
});
24
25
$api->get('/echo/{$message}', function ($message) {
26
    echo json_encode(['message' => $message], JSON_THROW_ON_ERROR, 512);
27
    http_response_code(200);
28
});
29
30
31
$authFunction = function ($username, $password) {
32
    return ($username == 'username' && $password == 'password');
33
};
34
35
$api->auth(function () use (&$api) {
36
37
    $api->get('/entries/{id}', function ($id) {
38
        echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512);
39
        http_response_code(201);
40
    });
41
42
43
    $api->post('/entries/{id}', function ($id) {
44
        echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512);
45
        http_response_code(201);
46
    });
47
48
    $api->put('/entries/{id}', function ($id) {
49
        echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512);
50
        http_response_code(204);
51
    });
52
53
    $api->delete('/entries/{id}', function ($id) {
0 ignored issues
show
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
    $api->delete('/entries/{id}', function (/** @scrutinizer ignore-unused */ $id) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
        http_response_code(204);
55
    });
56
57
}, $authFunction);
58