| Conditions | 11 |
| Paths | 16 |
| Total Lines | 59 |
| 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 |
||
| 88 | public function onPreSerialize(PreSerializeEvent $event): void |
||
| 89 | { |
||
| 90 | $object = $event->getObject(); |
||
| 91 | |||
| 92 | if ($object instanceof Proxy && !$object->__isInitialized()) { |
||
| 93 | $object->__load(); |
||
| 94 | } |
||
| 95 | |||
| 96 | $objectUid = \spl_object_hash($object); |
||
| 97 | if (\array_key_exists($objectUid, $this->serializedObjects)) { |
||
| 98 | return; |
||
| 99 | } |
||
| 100 | |||
| 101 | $classAnnotation = $this->annotationReader->getClassAnnotation( |
||
| 102 | new \ReflectionClass(ClassUtils::getClass($object)), |
||
| 103 | VichSerializableClass::class |
||
| 104 | ); |
||
| 105 | |||
| 106 | if ($classAnnotation instanceof VichSerializableClass) { |
||
| 107 | $reflectionClass = ClassUtils::newReflectionClass(\get_class($object)); |
||
| 108 | $this->logger->debug(\sprintf( |
||
| 109 | 'Found @VichSerializableClass annotation for the class "%s"', |
||
| 110 | $reflectionClass->getName() |
||
|
|
|||
| 111 | )); |
||
| 112 | |||
| 113 | foreach ($reflectionClass->getProperties() as $property) { |
||
| 114 | $vichSerializableAnnotation = $this->annotationReader->getPropertyAnnotation($property, VichSerializableField::class); |
||
| 115 | |||
| 116 | if ($vichSerializableAnnotation instanceof VichSerializableField) { |
||
| 117 | $vichUploadableFileAnnotation = $this->annotationReader->getPropertyAnnotation($property, UploadableField::class); |
||
| 118 | |||
| 119 | if ($vichUploadableFileAnnotation instanceof UploadableField) { |
||
| 120 | throw new IncompatibleUploadableAndSerializableFieldAnnotationException(\sprintf( |
||
| 121 | 'The field "%s" in the class "%s" cannot have @UploadableField and @VichSerializableField annotations at the same moment.', |
||
| 122 | $property->getName(), |
||
| 123 | $reflectionClass->getName() |
||
| 124 | )); |
||
| 125 | } |
||
| 126 | $this->logger->debug(\sprintf( |
||
| 127 | 'Found @VichSerializableField annotation for the field "%s" in the class "%s"', |
||
| 128 | $property->getName(), |
||
| 129 | $reflectionClass->getName() |
||
| 130 | )); |
||
| 131 | |||
| 132 | $uri = null; |
||
| 133 | $property->setAccessible(true); |
||
| 134 | |||
| 135 | if ($property->getValue($event->getObject())) { |
||
| 136 | $uri = $this->storage->resolveUri($object, $vichSerializableAnnotation->getField()); |
||
| 137 | if ($vichSerializableAnnotation->isIncludeHost() && false === \filter_var($uri, FILTER_VALIDATE_URL)) { |
||
| 138 | $uri = $this->getHostUrl().$uri; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | $this->serializedObjects[$objectUid][$property->getName()] = $property->getValue($event->getObject()); |
||
| 142 | $property->setValue($object, $uri); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 193 |