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