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

modules/system/controllers/rest/post.php (10 issues)

Labels
Severity
1
<?php
2
/**
3
 * REST controller for POST 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\Controller;
0 ignored issues
show
The type Bluz\Controller 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\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...
15
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...
16
use Bluz\Http\Exception\BadRequestException;
0 ignored issues
show
The type Bluz\Http\Exception\BadRequestException 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\Http\Exception\NotImplementedException;
0 ignored issues
show
The type Bluz\Http\Exception\NotImplementedException 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\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...
19
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...
20
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...
21
use Bluz\Proxy\Router;
0 ignored issues
show
The type Bluz\Proxy\Router 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...
22
use Bluz\Validator\Exception\ValidatorException;
0 ignored issues
show
The type Bluz\Validator\Exception\ValidatorException 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...
23
24
/**
25
 * @accept HTML
26
 * @accept JSON
27
 * @method POST
28
 *
29
 * @param Table $crud
30
 * @param mixed $primary
31
 * @param array $data
32
 *
33
 * @return array
34
 * @throws BadRequestException
35
 * @throws NotImplementedException
36
 * @throws TableNotFoundException
37
 */
38
return function (Table $crud, $primary, $data) {
39
    if (!empty(array_filter($primary))) {
40
        // POST + ID is incorrect behaviour
41
        throw new NotImplementedException;
42
    }
43
44
    try {
45
        $result = $crud->createOne($data);
46
        if (!$result) {
47
            // system can't create record with this data
48
            throw new BadRequestException;
49
        }
50
51
        if (is_array($result)) {
52
            $result = implode('-', array_values($result));
53
        }
54
    } catch (ValidatorException $e) {
55
        Response::setStatusCode($e->getCode());
56
        return [
57
            'code' => $e->getCode(),
58
            'error' => $e->getMessage(),
59
            'errors' => $e->getErrors()
60
        ];
61
    }
62
63
    Response::setStatusCode(StatusCode::CREATED);
64
    Response::setHeader(
65
        'Location',
66 1
        Router::getUrl(Request::getModule(), Request::getController()) . '/' . $result
67
    );
68
    return [];
69
};
70