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

modules/system/controllers/crud/put.php (8 issues)

Labels
Severity
1
<?php
2
/**
3
 * CRUD controller for PUT 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\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...
16
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...
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\Proxy\Messages;
0 ignored issues
show
The type Bluz\Proxy\Messages 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\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...
21
22
/**
23
 * @accept HTML
24
 * @accept JSON
25
 * @method PUT
26
 *
27
 * @param Table $crud
28
 * @param mixed $primary
29
 * @param array $data
30
 *
31
 * @return array
32
 * @throws TableNotFoundException
33
 * @throws NotFoundException
34
 */
35
return function (Table $crud, $primary, $data) {
36
    try {
37
        // Result is numbers of affected rows
38
        $crud->updateOne($primary, $data);
39
40
        Messages::addSuccess('The record was successfully updated');
41
42
        return [
43
            'row' => $crud->readOne($primary),
44
            'method' => Request::getMethod()
45
        ];
46
    } catch (ValidatorException $e) {
47
        $row = $crud->readOne($primary);
48
        $row->setFromArray($data);
49
50
        return [
51
            'row' => $row,
52
            'errors' => $e->getErrors(),
53
            'method' => Request::getMethod()
54 1
        ];
55
    }
56
};
57