CrudAddAction::validates()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
ccs 5
cts 6
cp 0.8333
crap 2.0185
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