AbstractRepresentation::getEntityClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace TonicForHealth\PagerDutyClient\RepresentProcessor\Representation;
4
5
use stdClass;
6
use TonicForHealth\PagerDutyClient\Entity\PagerDutyEntityInterface;
7
8
/**
9
 * Class AbstractRepresentation.
10
 */
11
abstract class AbstractRepresentation implements RepresentationInterface
12
{
13
    /**
14
     * @return string
15
     */
16 4
    public static function getEntityClassName()
17
    {
18 4
        return preg_replace('#Representation$#', '', static::class);
19
    }
20
21
    /**
22
     * @param PagerDutyEntityInterface $pagerDutyEntity
23
     *
24
     * @return stdClass
25
     */
26
    public function persistRepresentObj(PagerDutyEntityInterface $pagerDutyEntity)
27
    {
28
        $representObject = new stdClass();
29
30
        $objArray = (array) $pagerDutyEntity;
31
        foreach ($objArray as $key => $value) {
32
            $representObject->$key = $value;
33
        }
34
35
        return $representObject;
36
    }
37
38
    /**
39
     * @param stdClass                      $obj
40
     * @param PagerDutyEntityInterface|null $pagerDutyEntity
41
     */
42 View Code Duplication
    public function loadRepresentObj(stdClass $obj, PagerDutyEntityInterface $pagerDutyEntity = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        if (null === $pagerDutyEntity) {
45
            $entityClassName = static::getEntityClassName();
46
            $pagerDutyEntity = new $entityClassName();
0 ignored issues
show
Unused Code introduced by
$pagerDutyEntity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
        }
48
        $objArray = (array) $obj;
49
        foreach ($objArray as $key => $value) {
50
            echo $representObject->$key = $value;
0 ignored issues
show
Bug introduced by
The variable $representObject does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
51
        }
52
    }
53
}
54