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

ObjectDataRow::extractCellValue()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 36
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 3 Features 2
Metric Value
c 5
b 3
f 2
dl 0
loc 36
rs 6.7272
cc 7
eloc 26
nc 8
nop 1
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