Conditions | 12 |
Paths | 8 |
Total Lines | 40 |
Code Lines | 23 |
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 |
||
35 | public function onPreSerialize(ObjectEvent $event) |
||
36 | { |
||
37 | $object = $this->getObject($event); |
||
38 | $objectUid = spl_object_hash($object); |
||
39 | |||
40 | if (in_array($objectUid, $this->preSerializedObjects, true)) { |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | $classAnnotation = $this->annotationReader->getClassAnnotation( |
||
45 | new \ReflectionClass(ClassUtils::getClass($object)), |
||
46 | LiipImagineSerializableClass::class |
||
47 | ); |
||
48 | |||
49 | if ($classAnnotation instanceof LiipImagineSerializableClass) { |
||
50 | $reflectionClass = ClassUtils::newReflectionClass(get_class($object)); |
||
51 | |||
52 | foreach ($reflectionClass->getProperties() as $property) { |
||
53 | $liipAnnotation = $this->annotationReader->getPropertyAnnotation($property, LiipImagineSerializableField::class); |
||
54 | $property->setAccessible(true); |
||
55 | |||
56 | if ($liipAnnotation instanceof LiipImagineSerializableField && $value = $property->getValue($object)) { |
||
57 | $vichField = $liipAnnotation->getVichUploaderField(); |
||
58 | |||
59 | if (!$liipAnnotation->getVirtualField()) { |
||
60 | $property->setValue($object, $this->serializeValue($liipAnnotation, $object, $value)); |
||
61 | } elseif ($vichField && array_key_exists('vichUploaderSerialize', $this->config) && $this->config['vichUploaderSerialize']) { |
||
62 | $originalImageUri = $this->vichStorage->resolveUri($object, $vichField); |
||
63 | |||
64 | if (array_key_exists('includeHost', $this->config) && $this->config['includeHost']) { |
||
65 | $originalImageUri = $this->getHostUrl().$originalImageUri; |
||
66 | } |
||
67 | $property->setValue($object, $originalImageUri); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | $this->preSerializedObjects[$objectUid] = $objectUid; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 |