Conditions | 9 |
Paths | 16 |
Total Lines | 62 |
Lines | 15 |
Ratio | 24.19 % |
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 |
||
44 | protected function getOptions() |
||
45 | { |
||
46 | $options = array(); |
||
47 | |||
48 | // Initialize some field attributes. |
||
49 | $filter = (string) $this->element['filter']; |
||
50 | $exclude = (string) $this->element['exclude']; |
||
51 | $stripExt = (string) $this->element['stripext']; |
||
52 | $hideNone = (string) $this->element['hide_none']; |
||
53 | $hideDefault = (string) $this->element['hide_default']; |
||
54 | |||
55 | // Get the path in which to search for file options. |
||
56 | $path = (string) $this->element['directory']; |
||
57 | |||
58 | if (!is_dir($path)) |
||
59 | { |
||
60 | $path = JPATH_ROOT . '/' . $path; |
||
61 | } |
||
62 | |||
63 | // Prepend some default options based on field attributes. |
||
64 | View Code Duplication | if (!$hideNone) |
|
65 | { |
||
66 | $options[] = HtmlSelect::option('-1', Text::alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname))); |
||
67 | } |
||
68 | |||
69 | View Code Duplication | if (!$hideDefault) |
|
70 | { |
||
71 | $options[] = HtmlSelect::option('', Text::alt('JOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname))); |
||
72 | } |
||
73 | |||
74 | // Get a list of files in the search path with the given filter. |
||
75 | $files = Folder::files($path, $filter); |
||
76 | |||
77 | // Build the options list from the list of files. |
||
78 | if (is_array($files)) |
||
79 | { |
||
80 | foreach ($files as $file) |
||
81 | { |
||
82 | // Check to see if the file is in the exclude mask. |
||
83 | View Code Duplication | if ($exclude) |
|
84 | { |
||
85 | if (preg_match(chr(1) . $exclude . chr(1), $file)) |
||
86 | { |
||
87 | continue; |
||
88 | } |
||
89 | } |
||
90 | |||
91 | // If the extension is to be stripped, do it. |
||
92 | if ($stripExt) |
||
93 | { |
||
94 | $file = File::stripExt($file); |
||
95 | } |
||
96 | |||
97 | $options[] = HtmlSelect::option($file, $file); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | // Merge any additional options in the XML definition. |
||
102 | $options = array_merge(parent::getOptions(), $options); |
||
103 | |||
104 | return $options; |
||
105 | } |
||
106 | } |
||
107 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.