GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#104)
by
unknown
06:19
created

MarathonEntityUtils::convObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author: bthapaliya
6
 * @since: 2016-10-16
7
 *
8
 */
9
namespace Chapi\Entity\Marathon;
10
11
class MarathonEntityUtils
12
{
13 35
    public static function setPropertyIfExist($source, $target, $property)
14
    {
15 35
        if (isset($source[$property]) &&
16 35
            property_exists($target, $property)) {
17 35
            $target->{$property} = $source[$property];
18 35
            return true;
19
        }
20 5
        return false;
21
    }
22
23
    /**
24
     * Sets all possible properties in the class from $data.
25
     * If the type is array or object, then it is ignored if there is no conversion in $conversion_map.
26
     * @param $data
27
     * @param $target
28
     * @param $conversionMap
29
     *
30
     * @return array all fields in $data that weren't stored in $target
31
     */
32 45
    public static function setAllPossibleProperties($data, $target, $conversionMap = [])
33
    {
34 45
        $unknownProperties = [];
35 45
        foreach ($data as $attributeName => $attributeValue) {
36
            // Don't set array or objects if no conversion method is specified.
37
            // Because this would need further type information to properly set.
38
            #if ((is_array($attributeValue) || is_object($attributeValue))
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
            #    && !isset($conversionMap[$attributeName])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40
            #    $unknownProperties[$attributeName] = $attributeValue;
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
            #    continue;
42
            #}
43 35
            if (isset($conversionMap[$attributeName])) {
44 26
                $data[$attributeName] = $conversionMap[$attributeName]($attributeValue);
45
            }
46 35
            if (!self::setPropertyIfExist($data, $target, $attributeName)) {
47 35
                $unknownProperties[$attributeName] = $attributeValue;
48
            }
49
        }
50 45
        return $unknownProperties;
51
    }
52
53
    /**
54
     * This is useful if you don't want an array or object to be skipped by setAllPossibleProperties().
55
     */
56
    public static function noConv() {
57
        return function($data) { return $data; };
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
58
    }
59
60
    public static function convArray() {
61
        return function($data) { return (array) $data; };
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
62
    }
63
64
    public static function convObject() {
65
        return function($data) { return (object) $data; };
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
66
    }
67
68
    /**
69
     * This is usefull for shorter and stable diff output.
70
     */
71 21
    public static function convSortedObject() {
72
        return function($data) {
73 12
            $a = (array) $data; // ksort is inplace, so we need a copy
74 12
            ksort($a);
75 12
            return (object) $a;
76 21
        };
77
    }
78
79
    public static function convClass($class) {
80
        return function($data) use ($class) { return new $class((array) $data); };
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
81
    }
82
83
    public static function convArrayOfClass($class) {
84 27
        return function($data) use ($class) {
85 6
            $return = [];
86 6
            if ($data !== null) {
87 6
                foreach ($data as $item) {
88 2
                    $return[] = new $class((array) $item);
89
                }
90
            }
91 6
            return $return;
92 27
        };
93
    }
94
}
95