Conditions | 5 |
Paths | 5 |
Total Lines | 58 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
16 | public function loadMetadataFromFile(\ReflectionClass $class, $path) |
||
17 | { |
||
18 | $classMetadata = new ClassMetadata($class->getName()); |
||
19 | |||
20 | $use = libxml_use_internal_errors(true); |
||
21 | $dom = new \DOMDocument('1.0'); |
||
22 | $dom->load($path); |
||
23 | |||
24 | if (!$dom->schemaValidate(__DIR__ . '/../../../schema/mapping.xsd')) { |
||
25 | $message = array_reduce(libxml_get_errors(), function ($foo, $error) { |
||
26 | return $error->message; |
||
27 | }); |
||
28 | throw new \InvalidArgumentException(sprintf( |
||
29 | 'Could not validate XML mapping at "%s": %s', |
||
30 | $path, $message |
||
31 | )); |
||
32 | } |
||
33 | libxml_use_internal_errors($use); |
||
34 | |||
35 | $xpath = new \DOMXpath($dom); |
||
36 | $xpath->registerNamespace('psict', self::XML_NAMESPACE); |
||
37 | |||
38 | foreach ($xpath->query('//psict:class') as $classEl) { |
||
39 | $classAttr = $classEl->getAttribute('name'); |
||
40 | |||
41 | if ($classAttr !== $class->getName()) { |
||
42 | throw new \InvalidArgumentException(sprintf( |
||
43 | 'Expected class name to be "%s" but it is mapped as "%s"', |
||
44 | $class->getName(), $classAttr |
||
45 | )); |
||
46 | } |
||
47 | |||
48 | foreach ($xpath->query('./psict:field', $classEl) as $fieldEl) { |
||
49 | $shared = $this->extractOptionSet($xpath, $fieldEl, 'shared-options'); |
||
50 | $form = $this->extractOptionSet($xpath, $fieldEl, 'form-options'); |
||
51 | $view = $this->extractOptionSet($xpath, $fieldEl, 'view-options'); |
||
52 | $storage = $this->extractOptionSet($xpath, $fieldEl, 'storage-options'); |
||
53 | |||
54 | $propertyMetadata = new PropertyMetadata( |
||
55 | $class->getName(), |
||
56 | $fieldEl->getAttribute('name'), |
||
57 | $fieldEl->getAttribute('type'), |
||
58 | $fieldEl->getAttribute('role'), |
||
59 | $fieldEl->getAttribute('group'), |
||
60 | [ |
||
61 | 'shared' => $shared, |
||
62 | 'form' => $form, |
||
63 | 'view' => $view, |
||
64 | 'storage' => $storage, |
||
65 | ] |
||
66 | ); |
||
67 | |||
68 | $classMetadata->addPropertyMetadata($propertyMetadata); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | return $classMetadata; |
||
73 | } |
||
74 | |||
106 |