Completed
Pull Request — master (#148)
by
unknown
05:55 queued 02:58
created

ObjectDataRow   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 3 Features 2
Metric Value
wmc 7
c 5
b 3
f 2
lcom 1
cbo 1
dl 0
loc 46
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C extractCellValue() 0 36 7
1
<?php
2
3
namespace Nayjest\Grids;
4
5
use Exception;
6
use RuntimeException;
7
8
class ObjectDataRow extends DataRow
9
{
10
    /**
11
     * @param string $fieldName
12
     *
13
     * @throws Exception
14
     *
15
     * @return mixed
16
     */
17
    protected function extractCellValue($fieldName)
18
    {
19
        if (strpos($fieldName, '.') !== false) {
20
            $parts = explode('.', $fieldName);
21
            $parts = array_reverse($parts);
22
            $res = $this->src;
23
            try {
24
                foreach ($parts as $part) {
25
                    $res = is_object($res) ? $res->{$part} : $res[$part];
26
                    if ($res !== null) {
27
                        return $res;
28
                    }
29
                }
30
            } catch (Exception $e) {
31
                throw new RuntimeException(
32
                    "Can't read '$fieldName' as '$part' property from DataRow",
33
                    0,
34
                    $e
35
                );
36
            }
37
            throw new RuntimeException(
38
                "Can't read '$fieldName' property from DataRow",
39
                0
40
            );
41
        } else {
42
            try {
43
                return $this->src->{$fieldName};
44
            } catch (Exception $e) {
0 ignored issues
show
Unused Code introduced by
catch (\Exception $e) { ...rom DataRow", 0, $e); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
45
                throw new RuntimeException(
46
                    "Can't read '$fieldName' property from DataRow",
47
                    0,
48
                    $e
49
                );
50
            }
51
        }
52
    }
53
}
54