CrudEditAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validates() 0 10 2
A execute() 0 7 1
1
<?php
2
/**
3
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Service\Action;
13
14
use CakeDC\Api\Exception\ValidationException;
15
16
/**
17
 * Class CrudEditAction
18
 *
19
 * @package CakeDC\Api\Service\Action
20
 */
21
class CrudEditAction extends CrudAction
22
{
23
24
    /**
25
     * Apply validation process.
26
     *
27
     * @return bool
28
     */
29 3
    public function validates()
30
    {
31 3
        $validator = $this->getTable()->getValidator();
32 3
        $errors = $validator->errors($this->getData(), false);
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Validation\Validator::errors() has been deprecated with message: 3.9.0 Renamed to validate()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
33 3
        if (!empty($errors)) {
34
            throw new ValidationException(__('Validation failed'), 0, null, $errors);
35
        }
36
37 3
        return true;
38
    }
39
40
    /**
41
     * Execute action.
42
     *
43
     * @return mixed
44
     */
45 6
    public function execute()
46
    {
47 6
        $entity = $this->_getEntity($this->_id);
48 4
        $entity = $this->_patchEntity($entity, $this->getData());
0 ignored issues
show
Documentation introduced by
$entity is of type object<Cake\Collection\Collection>, but the function expects a object<Cake\Datasource\EntityInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
50 4
        return $this->_save($entity);
51
    }
52
}
53