| Conditions | 10 |
| Paths | 36 |
| Total Lines | 62 |
| Code Lines | 37 |
| 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 |
||
| 24 | protected function loadMetadataFromFile(\ReflectionClass $class, $file) |
||
| 25 | { |
||
| 26 | $previous = libxml_use_internal_errors(true); |
||
| 27 | $root = simplexml_load_file($file); |
||
| 28 | libxml_use_internal_errors($previous); |
||
| 29 | |||
| 30 | if (false === $root) { |
||
| 31 | throw new XmlErrorException(libxml_get_last_error()); |
||
| 32 | } |
||
| 33 | |||
| 34 | $name = $class->getName(); |
||
| 35 | if (!$exists = $root->xpath("./class[@name = '" . $name . "']")) { |
||
| 36 | throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $name, $file)); |
||
| 37 | } |
||
| 38 | |||
| 39 | $classMetadata = new ClassMetadata($name); |
||
| 40 | $classMetadata->fileResources[] = $file; |
||
| 41 | $classMetadata->fileResources[] = $class->getFileName(); |
||
| 42 | |||
| 43 | if ($exists[0]->attributes(self::NAMESPACE_URI)->providers) { |
||
| 44 | $providers = preg_split('/\s*,\s*/', (string) $exists[0]->attributes(self::NAMESPACE_URI)->providers); |
||
| 45 | |||
| 46 | foreach ($providers as $relationProvider) { |
||
| 47 | $classMetadata->addRelationProvider(new RelationProvider($relationProvider)); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | $elements = $exists[0]->children(self::NAMESPACE_URI); |
||
| 52 | |||
| 53 | foreach ($elements->relation as $relation) { |
||
| 54 | $name = (string) $relation->attributes('')->rel; |
||
| 55 | |||
| 56 | $href = null; |
||
| 57 | if (isset($relation->href)) { |
||
| 58 | $href = $this->createHref($relation->href, $name); |
||
| 59 | } |
||
| 60 | |||
| 61 | $embedded = null; |
||
| 62 | if (isset($relation->embedded)) { |
||
| 63 | $embedded = $this->createEmbedded($relation->embedded); |
||
| 64 | } |
||
| 65 | |||
| 66 | $attributes = array(); |
||
| 67 | foreach ($relation->attribute as $attribute) { |
||
| 68 | $attributes[(string) $attribute->attributes('')->name] = (string) $attribute->attributes('')->value; |
||
| 69 | } |
||
| 70 | |||
| 71 | $exclusion = isset($relation->exclusion) ? $this->parseExclusion($relation->exclusion) : null; |
||
| 72 | |||
| 73 | $classMetadata->addRelation( |
||
| 74 | new Relation( |
||
| 75 | $name, |
||
| 76 | $href, |
||
| 77 | $embedded, |
||
| 78 | $attributes, |
||
| 79 | $exclusion |
||
| 80 | ) |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | return $classMetadata; |
||
| 85 | } |
||
| 86 | |||
| 144 |