EntityContext   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A val() 0 15 3
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Core
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Core".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\View\Form;
17
18
use JBZoo\Data\Data;
19
use Cake\View\Form\EntityContext as CakeEntityContext;
20
21
/**
22
 * Class EntityContext
23
 *
24
 * @package Core\View\Form
25
 */
26
class EntityContext extends CakeEntityContext
27
{
28
29
    /**
30
     * Get the value for a given path.
31
     *
32
     * @param string $field
33
     * @param array $options
34
     * @return mixed
35
     */
36
    public function val($field, $options = [])
37
    {
38
        $val = parent::val($field, $options);
39
        if ($val === null) {
40
            $parts  = explode('.', $field);
41
            $entity = $this->entity($parts);
42
43
            if ($entity instanceof Data) {
44
                $key = array_pop($parts);
45
                $val = $entity->get($key);
46
            }
47
        }
48
49
        return $val;
50
    }
51
}
52