Conditions | 18 |
Paths | 241 |
Total Lines | 83 |
Code Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
17 | public function treatment() |
||
18 | { |
||
19 | if (preg_match("#prod#", $this->getEnvironment())) { |
||
20 | $this->output->writeln("<error>Command disallow</error>"); |
||
21 | |||
22 | return false; |
||
23 | } |
||
24 | |||
25 | $allMetadata = $this->getEntityManager()->getMetadataFactory()->getAllMetadata(); |
||
26 | // On récupère la liste des entites en fonction des nom de tables supposés. |
||
27 | $namespaces = []; |
||
28 | foreach ($allMetadata as $metadata) { |
||
29 | if ($metadata->isMappedSuperclass) { |
||
30 | continue; |
||
31 | } |
||
32 | if (count($metadata->subClasses)) { |
||
33 | $namespaces[$metadata->getName()] = [ |
||
34 | 'tableName' => $metadata->getTableName(), |
||
35 | ]; |
||
36 | continue; |
||
37 | } |
||
38 | $columns = array_flip($metadata->columnNames); |
||
39 | $fields = []; |
||
40 | foreach ($columns as $column => $field) { |
||
41 | $fields[$column] = [ |
||
42 | 'field' => $field, |
||
43 | 'type' => $metadata->getFieldMapping($field)['type'], |
||
44 | ]; |
||
45 | } |
||
46 | $mapping = $metadata->getAssociationMappings(); |
||
47 | foreach ($mapping as $detail) { |
||
48 | if (!array_key_exists("sourceToTargetKeyColumns", $detail)) { |
||
49 | continue; |
||
50 | } |
||
51 | $column = array_keys($detail['sourceToTargetKeyColumns'])[0]; |
||
52 | $fields[$column] = [ |
||
53 | 'field' => $detail['fieldName'], |
||
54 | 'type' => 'integer', |
||
55 | 'sourceToTargetKeyColumns' => $detail['sourceToTargetKeyColumns'][$column], |
||
56 | 'targetEntity' => $detail['targetEntity'], |
||
57 | ]; |
||
58 | } |
||
59 | $namespaces[$metadata->getName()] = [ |
||
60 | 'tableName' => $metadata->getTableName(), |
||
61 | 'fields' => $fields, |
||
62 | 'discriminatorValue' => $metadata->discriminatorValue, |
||
63 | 'discriminatorColumn' => !empty($metadata->discriminatorValue) ? $metadata->discriminatorColumn['name'] : null, |
||
64 | ]; |
||
65 | } |
||
66 | ksort($namespaces); |
||
67 | $contenu = ""; |
||
68 | foreach ($namespaces as $namespace => $data) { |
||
69 | if (empty($data['fields'])) { |
||
70 | continue; |
||
71 | } |
||
72 | $export = []; |
||
73 | $where = (!empty($data['discriminatorValue']) ? $data['discriminatorColumn']."='".$data['discriminatorValue']."'" : "1=1"); |
||
74 | $query = "SELECT ".implode(",", array_keys($data['fields']))." FROM ".$data['tableName']." WHERE ".$where; |
||
75 | if (!$resultats = $this->getConnection()->fetchAll($query)) { |
||
76 | continue; |
||
77 | |||
78 | } |
||
79 | |||
80 | foreach ($resultats as $key => $row) { |
||
81 | $dataExport = []; |
||
82 | foreach ($row as $element => $value) { |
||
83 | if ($element == 'id') { |
||
84 | continue; |
||
85 | } |
||
86 | $field = $data['fields'][$element]['field']; |
||
87 | if (!empty($data['fields'][$element]['targetEntity'])) { |
||
88 | $value = empty($value) ? null : strtolower("@".$namespaces[$data['fields'][$element]['targetEntity']]['tableName'])."_".$value; |
||
89 | $dataExport[$data['fields'][$element]['field']] = $value; |
||
90 | continue; |
||
91 | } |
||
92 | $dataExport[$field] = $this->formatValue($data['fields'][$element]['type'], $value); |
||
93 | } |
||
94 | $export[strtolower($data['tableName']).'_'.$row['id']] = $dataExport; |
||
95 | } |
||
96 | $contenu .= Yaml::dump([$namespace => $export,], 2, 4)."\n"; |
||
97 | } |
||
98 | echo $contenu; |
||
99 | } |
||
100 | |||
125 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.