Completed
Push — master ( 0eab77...b2f729 )
by Paul
05:35
created

ParameterConverter::setBusinessPropertyInstance()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A ParameterConverter::convertFromEntity() 0 15 2
1
<?php
2
3
namespace Victoire\Bundle\BusinessEntityBundle\Converter;
4
5
use Symfony\Component\PropertyAccess\PropertyAccessor;
6
use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessProperty;
7
8
/**
9
 * Parameter Converter
10
 * ref: victoire_business_entity.converter.parameter_converter.
11
 */
12
class ParameterConverter
13
{
14
    /**
15
     * Replace the code string with the value of the entity attribute.
16
     *
17
     * @param string           $string
0 ignored issues
show
Bug introduced by
There is no parameter named $string. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
18
     * @param BusinessProperty $businessProperty
19
     * @param object           $entity
20
     *
21
     * @throws \Exception
22
     *
23
     * @return string The updated string
24
     */
25
    public function convertFromEntity($url, BusinessProperty $businessProperty, $entity)
26
    {
27
        //test parameters
28
        if ($entity === null) {
29
            throw new \Exception('The parameter entity can not be null');
30
        }
31
        //the attribute to set
32
        $entityProperty = $businessProperty->getName();
33
34
        //the value of the attribute
35
        $accessor = new PropertyAccessor();
36
        $attributeValue = $accessor->getValue($entity, $entityProperty);
37
38
        return $this->convert($url, 'item.'.$entityProperty, $attributeValue);
39
    }
40
41
    /**
42
     * Replace the code string with the value of the entity attribute.
43
     *
44
     * @param string $string
0 ignored issues
show
Bug introduced by
There is no parameter named $string. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     * @param string $entityProperty
46
     * @param string $attributeValue
47
     *
48
     * @throws \Exception
49
     *
50
     * @return string The updated string
51
     */
52
    public function convert($url, $entityProperty, $attributeValue)
53
    {
54
        //the string to replace
55
        $stringToReplace = '{{'.$entityProperty.'}}';
56
57
        //we provide a default value
58
        if ($attributeValue === null) {
59
            $attributeValue = '';
60
        }
61
62
        //we replace the string
63
        return str_replace($stringToReplace, $attributeValue, $url);
64
    }
65
}
66