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