Conditions | 26 |
Paths | 46 |
Total Lines | 81 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | 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 |
||
88 | |||
89 | switch(mb_strtolower($key)) |
||
90 | { |
||
91 | case 'title': |
||
92 | $this->title = $value; |
||
93 | break; |
||
94 | |||
95 | case 'comments': |
||
96 | $this->description = $value; |
||
97 | break; |
||
98 | |||
99 | case 'keyword': |
||
100 | case 'keywords': |
||
101 | $keywords = preg_split(preg_match('/,/', $value) ? '/\s*,\s*/' : '/\s+/', $value); |
||
102 | $this->keywords = array_unique($keywords ?: []); |
||
103 | break; |
||
104 | |||
105 | case 'language': |
||
106 | $this->language = mb_substr($value, 0, 2); |
||
107 | break; |
||
108 | |||
109 | case 'author': |
||
110 | case 'initial-creator': |
||
111 | $this->author = $value; |
||
112 | break; |
||
113 | |||
114 | case 'application-name': |
||
115 | case 'generator': |
||
116 | case 'producer': |
||
117 | $value = preg_replace('/\$.+/', '', $value); |
||
118 | $this->generator = trim($value); |
||
119 | break; |
||
120 | |||
121 | case 'nbpage': |
||
122 | case 'page-count': |
||
123 | case 'xmptpg:npages': |
||
124 | $this->pages = (int) $value; |
||
125 | break; |
||
126 | |||
127 | case 'nbword': |
||
128 | case 'word-count': |
||
129 | $this->words = (int) $value; |
||
130 | break; |
||
131 | |||
132 | case 'content-encoding': |
||
133 | $this->encoding = $value; |
||
134 | break; |
||
135 | |||
136 | case 'x-tika:content': |
||
137 | $this->content = $value; |
||
138 | break; |
||
139 | } |
||
140 | |||
141 | return $this; |
||
142 | } |
||
143 | } |
||
144 |