Conditions | 17 |
Paths | 16 |
Total Lines | 75 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
48 | public function render() : string |
||
49 | { |
||
50 | $data = $this->arguments['nodeEvent']->getData(); |
||
51 | $old = $data['old']; |
||
52 | $new = $data['new']; |
||
53 | $nodeType = $this->nodeTypeManager->getNodeType($data['nodeType']); |
||
54 | $changeNodePropertiesDefaults = $nodeType->getDefaultValuesForProperties(); |
||
55 | |||
56 | $renderer = new HtmlArrayRenderer(); |
||
57 | $changes = []; |
||
58 | foreach ($new as $propertyName => $changedPropertyValue) { |
||
59 | if (($old === null && empty($changedPropertyValue)) |
||
60 | || (isset($changeNodePropertiesDefaults[$propertyName]) |
||
61 | && $changedPropertyValue === $changeNodePropertiesDefaults[$propertyName] |
||
62 | ) |
||
63 | ) { |
||
64 | continue; |
||
65 | } |
||
66 | |||
67 | $originalPropertyValue = ($old === null ? null : $old[$propertyName]); |
||
68 | |||
69 | if (!is_object($originalPropertyValue) && !is_object($changedPropertyValue)) { |
||
70 | $originalSlimmedDownContent = $this->renderSlimmedDownContent($originalPropertyValue); |
||
71 | $changedSlimmedDownContent = $this->renderSlimmedDownContent($changedPropertyValue); |
||
72 | |||
73 | $diff = new Diff( |
||
74 | explode("\n", $originalSlimmedDownContent), |
||
75 | explode("\n", $changedSlimmedDownContent), |
||
76 | ['context' => 1] |
||
77 | ); |
||
78 | /** @var array $diffArray */ |
||
79 | $diffArray = $diff->render($renderer); |
||
80 | $this->postProcessDiffArray($diffArray); |
||
81 | if ($diffArray !== []) { |
||
82 | $changes[$propertyName] = [ |
||
83 | 'diff' => $diffArray, |
||
84 | 'propertyLabel' => $this->getPropertyLabel($propertyName, $nodeType), |
||
85 | 'type' => 'text', |
||
86 | ]; |
||
87 | } |
||
88 | } elseif ($originalPropertyValue instanceof ImageInterface |
||
89 | || $changedPropertyValue instanceof ImageInterface |
||
90 | ) { |
||
91 | $changes[$propertyName] = [ |
||
92 | 'changed' => $changedPropertyValue, |
||
93 | 'original' => $originalPropertyValue, |
||
94 | 'propertyLabel' => $this->getPropertyLabel($propertyName, $nodeType), |
||
95 | 'type' => 'image', |
||
96 | ]; |
||
97 | } elseif ($originalPropertyValue instanceof AssetInterface |
||
98 | || $changedPropertyValue instanceof AssetInterface |
||
99 | ) { |
||
100 | $changes[$propertyName] = [ |
||
101 | 'changed' => $changedPropertyValue, |
||
102 | 'original' => $originalPropertyValue, |
||
103 | 'propertyLabel' => $this->getPropertyLabel($propertyName, $nodeType), |
||
104 | 'type' => 'asset', |
||
105 | ]; |
||
106 | } elseif ($originalPropertyValue instanceof \DateTimeInterface |
||
107 | && $changedPropertyValue instanceof \DateTimeInterface |
||
108 | ) { |
||
109 | if ($changedPropertyValue->getTimestamp() !== $originalPropertyValue->getTimestamp()) { |
||
110 | $changes[$propertyName] = [ |
||
111 | 'changed' => $changedPropertyValue, |
||
112 | 'original' => $originalPropertyValue, |
||
113 | 'propertyLabel' => $this->getPropertyLabel($propertyName, $nodeType), |
||
114 | 'type' => 'datetime', |
||
115 | ]; |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | $this->templateVariableContainer->add('changes', $changes); |
||
120 | $content = $this->renderChildren(); |
||
121 | $this->templateVariableContainer->remove('changes'); |
||
122 | return $content; |
||
|
|||
123 | } |
||
193 |