| Conditions | 12 |
| Paths | 17 |
| Total Lines | 67 |
| 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 |
||
| 90 | public function onPreSerialize(PreSerializeEvent $event): void |
||
| 91 | { |
||
| 92 | $object = $event->getObject(); |
||
| 93 | if (!\is_object($object)) { |
||
| 94 | return; |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($object instanceof Proxy && !$object->__isInitialized()) { |
||
| 98 | $object->__load(); |
||
| 99 | } |
||
| 100 | |||
| 101 | $objectUid = \spl_object_hash($object); |
||
| 102 | if (\array_key_exists($objectUid, $this->serializedObjects)) { |
||
| 103 | return; |
||
| 104 | } |
||
| 105 | |||
| 106 | /** @var class-string<object> $className */ |
||
|
|
|||
| 107 | $className = ClassUtils::getClass($object); |
||
| 108 | |||
| 109 | $classAnnotation = $this->annotationReader->getClassAnnotation( |
||
| 110 | new \ReflectionClass($className), |
||
| 111 | VichSerializableClass::class |
||
| 112 | ); |
||
| 113 | |||
| 114 | if ($classAnnotation instanceof VichSerializableClass) { |
||
| 115 | $reflectionClass = ClassUtils::newReflectionClass(\get_class($object)); |
||
| 116 | $this->logger->debug(\sprintf( |
||
| 117 | 'Found @VichSerializableClass annotation for the class "%s"', |
||
| 118 | $reflectionClass->getName() |
||
| 119 | )); |
||
| 120 | |||
| 121 | foreach ($reflectionClass->getProperties() as $property) { |
||
| 122 | $vichSerializableAnnotation = $this->annotationReader->getPropertyAnnotation($property, VichSerializableField::class); |
||
| 123 | |||
| 124 | if ($vichSerializableAnnotation instanceof VichSerializableField) { |
||
| 125 | $vichUploadableFileAnnotation = $this->annotationReader->getPropertyAnnotation($property, UploadableField::class); |
||
| 126 | |||
| 127 | if ($vichUploadableFileAnnotation instanceof UploadableField) { |
||
| 128 | $exceptionMessage = \sprintf( |
||
| 129 | 'The field "%s" in the class "%s" cannot have @UploadableField and @VichSerializableField annotations at the same moment.', |
||
| 130 | $property->getName(), |
||
| 131 | $reflectionClass->getName() |
||
| 132 | ); |
||
| 133 | |||
| 134 | throw new IncompatibleUploadableAndSerializableFieldAnnotationException($exceptionMessage); |
||
| 135 | } |
||
| 136 | $this->logger->debug(\sprintf( |
||
| 137 | 'Found @VichSerializableField annotation for the field "%s" in the class "%s"', |
||
| 138 | $property->getName(), |
||
| 139 | $reflectionClass->getName() |
||
| 140 | )); |
||
| 141 | |||
| 142 | $uri = null; |
||
| 143 | $property->setAccessible(true); |
||
| 144 | |||
| 145 | if ($property->getValue($event->getObject())) { |
||
| 146 | $uri = $this->storage->resolveUri($object, $vichSerializableAnnotation->getField()); |
||
| 147 | if ($vichSerializableAnnotation->isIncludeHost() && false === \filter_var($uri, FILTER_VALIDATE_URL)) { |
||
| 148 | $uri = $this->getHostUrl().$uri; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | $this->serializedObjects[$objectUid][$property->getName()] = $property->getValue($event->getObject()); |
||
| 152 | $property->setValue($object, $uri); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 206 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.