Failed Conditions
Pull Request — master (#321)
by Anton
23:35 queued 08:33
created

modules/system/controllers/rest/get.php (6 issues)

Labels
Severity
1
<?php
2
/**
3
 * REST controller for GET method
4
 *
5
 * @category Application
6
 *
7
 * @author   Anton Shevchuk
8
 * @created  19.02.15 16:27
9
 */
10
11
namespace Application;
12
13
use Bluz\Crud\Table;
0 ignored issues
show
The type Bluz\Crud\Table was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Bluz\Db\Exception\TableNotFoundException;
0 ignored issues
show
The type Bluz\Db\Exception\TableNotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Bluz\Http\Exception\NotFoundException;
0 ignored issues
show
The type Bluz\Http\Exception\NotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Bluz\Http\StatusCode;
0 ignored issues
show
The type Bluz\Http\StatusCode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Bluz\Proxy\Request;
0 ignored issues
show
The type Bluz\Proxy\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Bluz\Proxy\Response;
0 ignored issues
show
The type Bluz\Proxy\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
/**
21
 * @accept HTML
22
 * @accept JSON
23
 * @method GET
24
 *
25
 * @param Table $crud
26
 * @param mixed $primary
27
 *
28
 * @return array
29
 * @throws TableNotFoundException
30
 * @throws NotFoundException
31
 */
32
return function (Table $crud, $primary) {
33
    if (!empty($primary)) {
34
        // @throws NotFoundException
35
        return [$crud->readOne($primary)];
36
    }
37
    $params = Request::getParams();
38
39
    // setup default offset and limit - safe way
40
    $offset = Request::getParam('offset', 0);
41
    $limit = Request::getParam('limit', 10);
42
43
    if ($range = Request::getHeader('Range')) {
44
        list(, $offset, $last) = preg_split('/[-=]/', $range);
45
        // for better compatibility
46
        $limit = $last - $offset;
47
    }
48
49
    list($data, $total) = $crud->readSet($offset, $limit, $params);
50
51
    if (count($data) < $total) {
52
        Response::setStatusCode(StatusCode::PARTIAL_CONTENT);
53
        Response::setHeader(
54
            'Content-Range',
55 1
            'items ' . $offset . '-' . ($offset + count($data)) . '/' . $total
56
        );
57
    }
58
59
    return $data;
60
};
61