Conditions | 25 |
Paths | 44 |
Total Lines | 64 |
Code Lines | 47 |
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 |
||
83 | protected function setSpecificAttribute(string $key, $value): MetadataInterface |
||
84 | { |
||
85 | if(is_array($value)) |
||
86 | { |
||
87 | $value = array_shift($value); |
||
88 | } |
||
89 | |||
90 | switch(mb_strtolower($key)) |
||
91 | { |
||
92 | case 'dc:title': |
||
93 | case 'title': |
||
94 | $this->title = $value; |
||
95 | break; |
||
96 | |||
97 | case 'comments': |
||
98 | case 'w:Comments': |
||
99 | $this->description = $value; |
||
100 | break; |
||
101 | |||
102 | case 'keyword': |
||
103 | case 'keywords': |
||
104 | case 'meta:keyword': |
||
105 | $keywords = preg_split(preg_match('/,/', $value) ? '/\s*,\s*/' : '/\s+/', $value); |
||
106 | $this->keywords = array_unique($keywords ?: []); |
||
107 | break; |
||
108 | |||
109 | case 'language': |
||
110 | $this->language = mb_substr($value, 0, 2); |
||
111 | break; |
||
112 | |||
113 | case 'author': |
||
114 | case 'dc:creator': |
||
115 | case 'initial-creator': |
||
116 | $this->author = $value; |
||
117 | break; |
||
118 | |||
119 | case 'application-name': |
||
120 | case 'generator': |
||
121 | case 'producer': |
||
122 | $value = preg_replace('/\$.+/', '', $value); |
||
123 | $this->generator = trim($value); |
||
124 | break; |
||
125 | |||
126 | case 'nbpage': |
||
127 | case 'page-count': |
||
128 | case 'xmptpg:npages': |
||
129 | $this->pages = (int) $value; |
||
130 | break; |
||
131 | |||
132 | case 'nbword': |
||
133 | case 'word-count': |
||
134 | $this->words = (int) $value; |
||
135 | break; |
||
136 | |||
137 | case 'content-encoding': |
||
138 | $this->encoding = $value; |
||
139 | break; |
||
140 | |||
141 | case 'x-tika:content': |
||
142 | $this->content = $value; |
||
143 | break; |
||
144 | } |
||
145 | |||
146 | return $this; |
||
147 | } |
||
149 |