Conditions | 24 |
Paths | 25 |
Total Lines | 72 |
Code Lines | 50 |
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 declare(strict_types = 1); |
||
84 | public function applyAtResource(\EasyRdf_Resource $rdf, Resource $jskos) |
||
85 | { |
||
86 | #error_log($rdf->getGraph()->dump('text')); |
||
87 | #error_log(print_r($this->rules,1)); |
||
88 | |||
89 | foreach ($this->rules as $property => $mapping) { |
||
90 | $type = $mapping['type']; |
||
91 | if (isset($mapping['jskos']) && in_array($mapping['jskos'], static::$JSKOSClasses)) { |
||
92 | $class = '\JSKOS\\'.$mapping['jskos']; |
||
93 | } else { |
||
94 | $class = null; |
||
95 | } |
||
96 | |||
97 | foreach ($mapping['properties'] as $rdfProperty) { |
||
98 | if ($type == 'URI') { |
||
99 | foreach (static::getURIs($rdf, $rdfProperty) as $uri) { |
||
100 | if (isset($class)) { |
||
101 | $uri = new $class(['uri'=>$uri]); |
||
102 | } |
||
103 | if (isset($mapping['unique'])) { |
||
104 | $jskos->$property = $uri; |
||
105 | } else { |
||
106 | if (empty($jskos->$property)) { |
||
107 | $jskos->$property = []; |
||
108 | } |
||
109 | $jskos->$property[] = $uri; |
||
110 | } |
||
111 | } |
||
112 | } elseif ($type == 'literal') { |
||
113 | foreach ($rdf->allLiterals($rdfProperty) as $literal) { |
||
114 | $value = static::cleanString($literal); |
||
115 | if (!isset($value)) { |
||
116 | continue; |
||
117 | } |
||
118 | |||
119 | if ($literal->getLang()) { |
||
120 | $language = $literal->getLang(); |
||
121 | } elseif (isset($mapping['_defaultLanguage'])) { |
||
122 | $language = $mapping['_defaultLanguage']; |
||
123 | } else { |
||
124 | $language = $this->defaultLanguage; |
||
125 | } |
||
126 | |||
127 | $languageMap = isset($jskos->$property) ? $jskos->$property : []; |
||
128 | |||
129 | if (isset($mapping['unique'])) { |
||
130 | $languageMap[$language] = $value; |
||
131 | } else { |
||
132 | $list = $languageMap[$language] ?? []; |
||
133 | $list[] = $value; |
||
134 | $languageMap[$language] = $list; |
||
135 | } |
||
136 | |||
137 | $jskos->$property = $languageMap; |
||
138 | } |
||
139 | } elseif ($type == 'plain') { |
||
140 | foreach ($rdf->allLiterals($rdfProperty) as $literal) { |
||
141 | $value = static::cleanString($literal); |
||
142 | if (!isset($value)) { |
||
143 | continue; |
||
144 | } |
||
145 | |||
146 | if (isset($mapping['pattern']) && !preg_match($mapping['pattern'], $value)) { |
||
147 | continue; |
||
148 | } |
||
149 | if (isset($mapping['unique'])) { |
||
150 | $jskos->$property = $value; |
||
151 | } else { |
||
152 | if (empty($jskos->$property)) { |
||
153 | $jskos->$property = [$value]; |
||
154 | } else { |
||
155 | $jskos->$property[] = $value; |
||
156 | } |
||
211 |