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

ConfiguratorimportInsertTrait::executeInsert()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 2
dl 0
loc 20
ccs 14
cts 14
cp 1
crap 4
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Cdf\BiCoreBundle\Utils\Command;
4
5
use Cdf\BiCoreBundle\Utils\FieldType\FieldTypeUtils;
6
7
trait ConfiguratorimportInsertTrait
8
{
9
10 2
    private function executeInsert($entityclass, $record)
11
    {
12 2
        $objrecord = new $entityclass();
13 2
        foreach ($record as $key => $value) {
14 2
            if ('id' !== $key) {
15 2
                if (!$this->insert($objrecord, $key, $value, $record['id'], $entityclass)) {
16 2
                    $propertyEntity = $this->entityutility->getEntityProperties($key, $objrecord);
17 2
                    $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...
18 2
                    $objrecord->$setfieldname($value);
19
                }
20
            }
21
        }
22 2
        $this->em->persist($objrecord);
23 2
        $this->em->flush();
24
25 2
        $infomsg = '<info>' . $entityclass . ' con id ' . $objrecord->getId() . ' aggiunta</info>';
26 2
        $this->output->writeln($infomsg);
27 2
        $checkid = $this->changeRecordId($entityclass, $record, $objrecord);
28
29 2
        return $checkid;
30
    }
31
32 2
    private function insert(&$objrecord, $key, $value, $recordid, $entityclass)
33
    {
34 2
        $propertyEntity = $this->entityutility->getEntityProperties($key, $objrecord);
35 2
        $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...
36 2
        $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...
37 2
        if ('discr' == $key) {
38 1
            return true;
39
        }
40 2
        $fieldtype = $this->dbutility->getFieldType($objrecord, $key);
41 2
        if ('boolean' === $fieldtype) {
42 2
            $newval = FieldTypeUtils::getBooleanValue($value);
43 2
            $msgok = '<info>Inserimento ' . $entityclass . ' con id ' . $recordid
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...
44 2
                    . ' per campo ' . $key . ' con valore '
45 2
                    . var_export($newval, true) . ' in formato Boolean</info>';
46 2
            $this->output->writeln($msgok);
47 2
            $objrecord->$setfieldname($newval);
48 2
            return true;
49
        }
50
        //Si prende in considerazione solo il null del boolean, gli altri non si toccano
51 2
        if (!$value) {
52 2
            return true;
53
        }
54 2
        if ('datetime' === $fieldtype || 'date' === $fieldtype) {
55 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...
56 1
            $msgok = '<info>Inserimento ' . $entityclass . ' con id ' . $recordid
57 1
                    . ' per campo ' . $key . ' cambio valore da '
58 1
                    . ($objrecord->$getfieldname() ? $objrecord->$getfieldname()->format('Y-m-d H:i:s') : 'NULL')
59 1
                    . ' a ' . $date->format('Y-m-d H:i:s') . ' in formato DateTime</info>';
60 1
            $this->output->writeln($msgok);
61 1
            $objrecord->$setfieldname($date);
62 1
            return true;
63
        }
64 2
        if (is_array($value)) {
65 2
            $msgarray = '<info>Inserimento ' . $entityclass . ' con id ' . $recordid
66 2
                    . ' per campo ' . $key . ' cambio valore da '
67 2
                    . json_encode($objrecord->$getfieldname()) . ' a '
68 2
                    . json_encode($value) . ' in formato array' . '</info>';
69 2
            $this->output->writeln($msgarray);
70 2
            $objrecord->$setfieldname($value);
71 2
            return true;
72
        }
73
74 2
        $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...
75 2
        $joincolumnproperty = $this->entityutility->getJoinTableFieldProperty($entityclass, $key);
76 2
        if ($joincolumn && $joincolumnproperty) {
77 2
            $joincolumnobj = $this->em->getRepository($joincolumn)->find($value);
78 2
            $msgok = '<info>Inserimento ' . $entityclass . ' con id ' . $recordid
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...
79 2
                    . ' per campo ' . $key
80 2
                    . ' con valore ' . print_r($value, true) . ' tramite entity find</info>';
81 2
            $this->output->writeln($msgok);
82 2
            $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...
83 2
            $setfieldname = $joinobj['set'];
84 2
            $objrecord->$setfieldname($joincolumnobj);
85 2
            return true;
86
        }
87 2
        return false;
88
    }
89
90 2
    private function changeRecordId($entityclass, $record, $objrecord)
91
    {
92 2
        if ($record['id'] !== $objrecord->getId()) {
93
            try {
94 1
                $qb = $this->em->createQueryBuilder();
95 1
                $q = $qb->update($entityclass, 'u')
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...
96 1
                        ->set('u.id', ':newid')
97 1
                        ->where('u.id = :oldid')
98 1
                        ->setParameter('newid', $record['id'])
99 1
                        ->setParameter('oldid', $objrecord->getId())
100 1
                        ->getQuery();
101 1
                $q->execute();
102 1
                $msgok = '<info>' . $entityclass . ' con id ' . $objrecord->getId() . ' sistemata</info>';
103 1
                $this->output->writeln($msgok);
104
            } catch (\Exception $exc) {
105
                echo $exc->getMessage();
106
107
                return 1;
108
            }
109 1
            $this->em->flush();
110
        }
111
112 2
        return 0;
113
    }
114
}
115