CrudAddAction   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 CrudAddAction
18
 *
19
 * @package CakeDC\Api\Service\Action
20
 */
21
class CrudAddAction extends CrudAction
22
{
23
24
    /**
25
     * Apply validation process.
26
     *
27
     * @return bool
28
     */
29 2
    public function validates()
30
    {
31 2
        $validator = $this->getTable()->getValidator();
32 2
        $errors = $validator->errors($this->getData());
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 2
        if (!empty($errors)) {
34
            throw new ValidationException(__('Validation failed'), 0, null, $errors);
35
        }
36
37 2
        return true;
38
    }
39
40
    /**
41
     * Execute action.
42
     *
43
     * @return mixed
44
     */
45 4
    public function execute()
46
    {
47 4
        $entity = $this->_newEntity();
48 4
        $entity = $this->_patchEntity($entity, $this->getData());
49
50 4
        return $this->_save($entity);
51
    }
52
}
53