Passed
Push — develop ( f93097...9bdd78 )
by Andrea
18:04
created

ConfiguratorimportUpdateTrait   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 81.33%

Importance

Changes 0
Metric Value
eloc 76
dl 0
loc 103
ccs 61
cts 75
cp 0.8133
rs 10
c 0
b 0
f 0
wmc 15

2 Methods

Rating   Name   Duplication   Size   Complexity  
B update() 0 64 9
B executeUpdate() 0 34 6
1
<?php
2
3
namespace Cdf\BiCoreBundle\Utils\Command;
4
5
use Cdf\BiCoreBundle\Utils\FieldType\FieldTypeUtils;
6
7
trait ConfiguratorimportUpdateTrait
8
{
9
10 1
    private function executeUpdate($entityclass, $record, $objrecord)
11
    {
12 1
        unset($record['id']);
13 1
        foreach ($record as $key => $value) {
14 1
            if ('discr' == $key) {
15 1
                continue;
16
            }
17 1
            $propertyEntity = $this->entityutility->getEntityProperties($key, $objrecord);
18 1
            $getfieldname = $propertyEntity['get'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
19 1
            $cambiato = $this->dbutility->isRecordChanged($entityclass, $key, $objrecord->$getfieldname(), $value);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
20 1
            if (!$cambiato) {
21 1
                if ($this->verboso) {
22 1
                    $msginfo = '<info>' . $entityclass . ' con id ' . $objrecord->getId()
23 1
                            . ' per campo ' . $key . ' non modificato perchè già '
24 1
                            . var_export($value, true) . '</info>';
25 1
                    $this->output->writeln($msginfo);
26
                }
27
            } else {
28
                try {
29 1
                    $this->update($objrecord, $key, $value, $entityclass);
30
                } catch (\Exception $exc) {
31
                    $msgerr = '<error>Modifica ' . $entityclass . ' con id ' . $objrecord->getId()
32
                            . ' per campo ' . $key . ', ERRORE: ' . $exc->getMessage()
33
                            . ' alla riga ' . $exc->getLine() . '</error>';
34
                    $this->output->writeln($msgerr);
35
                    //dump($exc);
36
                    return 1;
37
                }
38
            }
39
        }
40 1
        $this->em->persist($objrecord);
41 1
        $this->em->flush();
42
43 1
        return 0;
44
    }
45
46 1
    private function update(&$objrecord, $key, $value, $entityclass)
47
    {
48 1
        $fieldtype = $this->dbutility->getFieldType($objrecord, $key);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
49 1
        $propertyEntity = $this->entityutility->getEntityProperties($key, $objrecord);
50 1
        $getfieldname = $propertyEntity['get'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
51 1
        $setfieldname = $propertyEntity['set'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52
53 1
        if ('boolean' === $fieldtype) {
54
            $newval = FieldTypeUtils::getBooleanValue($value);
55
56
            $msgok = '<info>Modifica ' . $entityclass . ' con id ' . $objrecord->getId()
57
                    . ' per campo ' . $key . ' cambio valore da '
58
                    . var_export($objrecord->$getfieldname(), true)
59
                    . ' a ' . var_export($newval, true) . ' in formato Boolean</info>';
60
            $this->output->writeln($msgok);
61
            $objrecord->$setfieldname($newval);
62
            return true;
63
        }
64
        //Si prende in considerazione solo il null del boolean, gli altri non si toccano
65 1
        if (!$value) {
66 1
            return true;
67
        }
68
69 1
        if ('datetime' === $fieldtype || 'date' === $fieldtype) {
70 1
            $date = FieldTypeUtils::getDateTimeValueFromTimestamp($value);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
71 1
            $msgok = '<info>Modifica ' . $entityclass . ' con id ' . $objrecord->getId()
72 1
                    . ' per campo ' . $key . ' cambio valore da '
73
                    //. (!is_null($objrecord->$getfieldname())) ? $objrecord->$getfieldname()->format("Y-m-d H:i:s") : "(null)"
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% 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...
74 1
                    . ($objrecord->$getfieldname() ? $objrecord->$getfieldname()->format('Y-m-d H:i:s') : 'NULL')
75 1
                    . ' a ' . $date->format('Y-m-d H:i:s') . ' in formato DateTime</info>';
76 1
            $this->output->writeln($msgok);
77 1
            $objrecord->$setfieldname($date);
78 1
            return true;
79
        }
80 1
        if (is_array($value)) {
81 1
            $msgarray = '<info>Modifica ' . $entityclass . ' con id ' . $objrecord->getId()
82 1
                    . ' per campo ' . $key . ' cambio valore da '
83 1
                    . json_encode($objrecord->$getfieldname()) . ' a '
84 1
                    . json_encode($value) . ' in formato array' . '</info>';
85 1
            $this->output->writeln($msgarray);
86 1
            $objrecord->$setfieldname($value);
87 1
            return true;
88
        }
89
90 1
        $joincolumn = $this->entityutility->getJoinTableField($entityclass, $key);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
91 1
        $joincolumnproperty = $this->entityutility->getJoinTableFieldProperty($entityclass, $key);
92 1
        if ($joincolumn && $joincolumnproperty) {
93 1
            $joincolumnobj = $this->em->getRepository($joincolumn)->find($value);
94 1
            $msgok = '<info>Modifica ' . $entityclass . ' con id ' . $objrecord->getId()
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
95 1
                    . ' per campo ' . $key . ' cambio valore da ' . print_r($objrecord->$getfieldname(), true)
96 1
                    . ' a ' . print_r($value, true) . ' tramite entity find</info>';
97 1
            $this->output->writeln($msgok);
98 1
            $joinobj = $this->entityutility->getEntityProperties($joincolumnproperty, new $entityclass());
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
99 1
            $setfieldname = $joinobj['set'];
100 1
            $objrecord->$setfieldname($joincolumnobj);
101 1
            return true;
102
        }
103
104 1
        $msgok = '<info>Modifica ' . $entityclass . ' con id ' . $objrecord->getId()
105 1
                . ' per campo ' . $key . ' cambio valore da ' . print_r($objrecord->$getfieldname(), true)
106 1
                . ' a ' . print_r($value, true) . '</info>';
107 1
        $this->output->writeln($msgok);
108 1
        $objrecord->$setfieldname($value);
109 1
        return false;
110
    }
111
}
112