| Conditions | 16 |
| Paths | 36 |
| Total Lines | 60 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 2 | Features | 2 |
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 |
||
| 65 | public function getMetadataForClass($className) |
||
| 66 | { |
||
| 67 | if (isset($this->loadedMetadata[$className])) { |
||
| 68 | return $this->filterNullMetadata($this->loadedMetadata[$className]); |
||
| 69 | } |
||
| 70 | |||
| 71 | $metadata = null; |
||
| 72 | foreach ($this->getClassHierarchy($className) as $class) { |
||
| 73 | if (isset($this->loadedClassMetadata[$name = $class->getName()])) { |
||
| 74 | if (null !== $classMetadata = $this->filterNullMetadata($this->loadedClassMetadata[$name])) { |
||
| 75 | $this->addClassMetadata($metadata, $classMetadata); |
||
| 76 | } |
||
| 77 | continue; |
||
| 78 | } |
||
| 79 | |||
| 80 | // check the cache |
||
| 81 | if (null !== $this->cache) { |
||
| 82 | if (($classMetadata = $this->cache->loadClassMetadataFromCache($class)) instanceof NullMetadata) { |
||
| 83 | $this->loadedClassMetadata[$name] = $classMetadata; |
||
| 84 | continue; |
||
| 85 | } |
||
| 86 | |||
| 87 | if (null !== $classMetadata) { |
||
| 88 | if ( ! $classMetadata instanceof ClassMetadata) { |
||
| 89 | throw new \LogicException(sprintf('The cache must return instances of ClassMetadata, but got %s.', var_export($classMetadata, true))); |
||
| 90 | } |
||
| 91 | |||
| 92 | if ($this->debug && !$classMetadata->isFresh()) { |
||
| 93 | $this->cache->evictClassMetadataFromCache($classMetadata->reflection); |
||
| 94 | } else { |
||
| 95 | $this->loadedClassMetadata[$name] = $classMetadata; |
||
| 96 | $this->addClassMetadata($metadata, $classMetadata); |
||
| 97 | continue; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | // load from source |
||
| 103 | if (null !== $classMetadata = $this->driver->loadMetadataForClass($class)) { |
||
| 104 | $this->loadedClassMetadata[$name] = $classMetadata; |
||
| 105 | $this->addClassMetadata($metadata, $classMetadata); |
||
| 106 | |||
| 107 | if (null !== $this->cache) { |
||
| 108 | $this->cache->putClassMetadataInCache($classMetadata); |
||
| 109 | } |
||
| 110 | |||
| 111 | continue; |
||
| 112 | } |
||
| 113 | |||
| 114 | if (null !== $this->cache && !$this->debug) { |
||
| 115 | $this->cache->putClassMetadataInCache(new NullMetadata($class->getName())); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | if (null === $metadata) { |
||
| 120 | $metadata = new NullMetadata($className); |
||
| 121 | } |
||
| 122 | |||
| 123 | return $this->filterNullMetadata($this->loadedMetadata[$className] = $metadata); |
||
| 124 | } |
||
| 125 | |||
| 209 |