| Conditions | 26 |
| Paths | > 20000 |
| Total Lines | 118 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 51 |
| CRAP Score | 29.774 |
| 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 |
||
| 33 | 32 | public function loadMetadataForClass(\ReflectionClass $class) |
|
| 34 | { |
||
| 35 | /** @var ClassMetadata $ddrRestClassMetadata */ |
||
| 36 | 32 | $ddrRestClassMetadata = $this->doctrineDriver->loadMetadataForClass($class); |
|
| 37 | 32 | if (null === $ddrRestClassMetadata) { |
|
| 38 | $ddrRestClassMetadata = new ClassMetadata($class->getName()); |
||
|
1 ignored issue
–
show
|
|||
| 39 | } |
||
| 40 | |||
| 41 | /** @var RootResource $restResourceAnnotation */ |
||
| 42 | 32 | $restResourceAnnotation = $this->reader->getClassAnnotation($class, RootResource::class); |
|
| 43 | 32 | if (null !== $restResourceAnnotation) { |
|
| 44 | |||
| 45 | 32 | $ddrRestClassMetadata->setRestResource(true); |
|
| 46 | |||
| 47 | 32 | if (null !== $restResourceAnnotation->namePrefix) { |
|
| 48 | $ddrRestClassMetadata->setNamePrefix($restResourceAnnotation->namePrefix); |
||
| 49 | } |
||
| 50 | |||
| 51 | 32 | if (null !== $restResourceAnnotation->pathPrefix) { |
|
| 52 | 20 | $ddrRestClassMetadata->setPathPrefix($restResourceAnnotation->pathPrefix); |
|
| 53 | } |
||
| 54 | |||
| 55 | 32 | if (null !== $restResourceAnnotation->service) { |
|
| 56 | $ddrRestClassMetadata->setService($restResourceAnnotation->service); |
||
| 57 | } |
||
| 58 | |||
| 59 | 32 | if (null !== $restResourceAnnotation->controller) { |
|
| 60 | $ddrRestClassMetadata->setController($restResourceAnnotation->controller); |
||
| 61 | } |
||
| 62 | |||
| 63 | 32 | if (null !== $restResourceAnnotation->listRight) { |
|
| 64 | 20 | $ddrRestClassMetadata->setListRight($restResourceAnnotation->listRight); |
|
| 65 | } |
||
| 66 | |||
| 67 | 32 | if (null !== $restResourceAnnotation->postRight) { |
|
| 68 | $ddrRestClassMetadata->setPostRight($restResourceAnnotation->postRight); |
||
| 69 | } |
||
| 70 | |||
| 71 | 32 | if (null !== $restResourceAnnotation->getRight) { |
|
| 72 | 20 | $ddrRestClassMetadata->setGetRight($restResourceAnnotation->getRight); |
|
| 73 | } |
||
| 74 | |||
| 75 | 32 | if (null !== $restResourceAnnotation->putRight) { |
|
| 76 | 20 | $ddrRestClassMetadata->setPutRight($restResourceAnnotation->putRight); |
|
| 77 | } |
||
| 78 | |||
| 79 | 32 | if (null !== $restResourceAnnotation->deleteRight) { |
|
| 80 | $ddrRestClassMetadata->setDeleteRight($restResourceAnnotation->deleteRight); |
||
| 81 | } |
||
| 82 | |||
| 83 | 32 | if (null !== $restResourceAnnotation->methods) { |
|
| 84 | $ddrRestClassMetadata->setMethods($restResourceAnnotation->methods); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | 32 | foreach ($class->getProperties() as $reflectionProperty) { |
|
| 89 | |||
| 90 | 32 | $propertyMetadata = $ddrRestClassMetadata->getPropertyMetadata($reflectionProperty->getName()); |
|
| 91 | 32 | if (null === $propertyMetadata) { |
|
| 92 | 20 | $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName()); |
|
|
1 ignored issue
–
show
|
|||
| 93 | } |
||
| 94 | |||
| 95 | 32 | $puttableAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, Puttable::class); |
|
| 96 | 32 | if (null !== $puttableAnnotation) { |
|
| 97 | 20 | $propertyMetadata->setPuttable(true); |
|
| 98 | } |
||
| 99 | |||
| 100 | 32 | $postableAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, Postable::class); |
|
| 101 | 32 | if (null !== $postableAnnotation) { |
|
| 102 | $propertyMetadata->setPostable(true); |
||
| 103 | } |
||
| 104 | |||
| 105 | 32 | $includableAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, Includable::class); |
|
| 106 | 32 | if (null !== $includableAnnotation) { |
|
| 107 | 20 | $paths = $includableAnnotation->paths; |
|
| 108 | 20 | if (null === $paths) { |
|
| 109 | 20 | $paths = [$reflectionProperty->name]; |
|
| 110 | } |
||
| 111 | 20 | $propertyMetadata->setIncludable(true); |
|
| 112 | 20 | $propertyMetadata->setIncludablePaths($paths); |
|
| 113 | } |
||
| 114 | |||
| 115 | 32 | $excludedAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, Excluded::class); |
|
| 116 | 32 | if (null !== $excludedAnnotation) { |
|
| 117 | 20 | $propertyMetadata->setExcluded(true); |
|
| 118 | } |
||
| 119 | |||
| 120 | /** @var SubResource $subResourceAnnotation */ |
||
| 121 | 32 | $subResourceAnnotation = $this->reader->getPropertyAnnotation($reflectionProperty, SubResource::class); |
|
| 122 | 32 | if (null !== $subResourceAnnotation) { |
|
| 123 | |||
| 124 | 20 | $propertyMetadata->setSubResource(true); |
|
| 125 | 20 | if (null !== $subResourceAnnotation->listRight) { |
|
| 126 | $propertyMetadata->setSubResourceListRight($subResourceAnnotation->listRight); |
||
| 127 | } |
||
| 128 | |||
| 129 | 20 | if (null !== $subResourceAnnotation->path) { |
|
| 130 | $propertyMetadata->setSubResourcePath($subResourceAnnotation->path); |
||
| 131 | } |
||
| 132 | |||
| 133 | 20 | if (null !== $subResourceAnnotation->postRight) { |
|
| 134 | $propertyMetadata->setSubResourcePostRight($subResourceAnnotation->postRight); |
||
| 135 | } |
||
| 136 | |||
| 137 | 20 | if (null !== $subResourceAnnotation->putRight) { |
|
| 138 | 20 | $propertyMetadata->setSubResourcePutRight($subResourceAnnotation->putRight); |
|
| 139 | } |
||
| 140 | |||
| 141 | 20 | if (null !== $subResourceAnnotation->deleteRight) { |
|
| 142 | 20 | $propertyMetadata->setSubResourceDeleteRight($subResourceAnnotation->deleteRight); |
|
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | 32 | $ddrRestClassMetadata->addPropertyMetadata($propertyMetadata); |
|
| 147 | } |
||
| 148 | |||
| 149 | 32 | return $ddrRestClassMetadata; |
|
| 150 | } |
||
| 151 | } |
||
| 152 |