| Conditions | 15 |
| Paths | 21 |
| Total Lines | 53 |
| 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 declare(strict_types = 1); |
||
| 37 | public function onPreSerialize(ObjectEvent $event): void |
||
| 38 | { |
||
| 39 | $object = $this->getObject($event); |
||
| 40 | |||
| 41 | $classAnnotation = $this->annotationReader->getClassAnnotation( |
||
| 42 | new \ReflectionClass(ClassUtils::getClass($object)), |
||
| 43 | LiipImagineSerializableClass::class |
||
| 44 | ); |
||
| 45 | |||
| 46 | if ($classAnnotation instanceof LiipImagineSerializableClass) { |
||
| 47 | $reflectionClass = ClassUtils::newReflectionClass(\get_class($object)); |
||
| 48 | |||
| 49 | foreach ($reflectionClass->getProperties() as $property) { |
||
| 50 | $liipAnnotation = $this->annotationReader->getPropertyAnnotation($property, LiipImagineSerializableField::class); |
||
| 51 | $property->setAccessible(true); |
||
| 52 | if ($liipAnnotation instanceof LiipImagineSerializableField) { |
||
| 53 | $value = $property->getValue($object); |
||
| 54 | |||
| 55 | if ($value && !\is_array($value)) { |
||
| 56 | $vichField = $liipAnnotation->getVichUploaderField(); |
||
| 57 | |||
| 58 | $cacheKey = null; |
||
| 59 | if ($vichField) { |
||
| 60 | $uriComponents = \explode('/', $value); |
||
| 61 | $vichProperty = $reflectionClass->getProperty($vichField); |
||
| 62 | $vichAnnotation = $this->annotationReader->getPropertyAnnotation($vichProperty, UploadableField::class); |
||
| 63 | $cacheKey = $vichField.\array_pop($uriComponents).$vichAnnotation->getMapping(); |
||
| 64 | |||
| 65 | if (\array_key_exists($cacheKey, $this->cache)) { |
||
| 66 | $property->setValue($object, $this->cache[$cacheKey]); |
||
| 67 | continue; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | if (!$liipAnnotation->getVirtualField()) { |
||
| 72 | $property->setValue($object, $this->serializeValue($liipAnnotation, $object, $value)); |
||
| 73 | } elseif ($vichField && \array_key_exists('vichUploaderSerialize', $this->config) && $this->config['vichUploaderSerialize']) { |
||
| 74 | $originalImageUri = $this->vichStorage->resolveUri($object, $vichField); |
||
| 75 | |||
| 76 | if (\array_key_exists('includeHost', $this->config) && $this->config['includeHost']) { |
||
| 77 | $originalImageUri = $this->getHostUrl().$originalImageUri; |
||
| 78 | } |
||
| 79 | $property->setValue($object, $this->normalizeUrl($originalImageUri, UrlNormalizerInterface::TYPE_ORIGIN)); |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($vichField) { |
||
| 83 | $this->cache[$cacheKey] = $property->getValue($object); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 |