Conditions | 5 |
Paths | 7 |
Total Lines | 62 |
Lines | 16 |
Ratio | 25.81 % |
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 |
||
32 | public function __construct($options = array()) |
||
33 | { |
||
34 | View Code Duplication | if (isset($options['allowed_file_extensions'])) { |
|
35 | if (!is_array($options['allowed_file_extensions'])) { |
||
36 | throw new InvalidArgumentException(esc_html__('A valid allowed_file_extensions array was not provided to EE_File_Input', 'event_espresso')); |
||
37 | } |
||
38 | $this->allowed_file_extensions = $options['allowed_file_extensions']; |
||
39 | } else { |
||
40 | $this->allowed_file_extensions = ['csv']; |
||
41 | } |
||
42 | View Code Duplication | if (isset($options['allowed_mime_types'])) { |
|
43 | if (!is_array($options['allowed_mime_types'])) { |
||
44 | throw new InvalidArgumentException(esc_html__('A valid allowed_mime_types array was not provided to EE_File_Input', 'event_espresso')); |
||
45 | } |
||
46 | $this->allowed_mime_types = $options['allowed_file_extensions']; |
||
47 | } else { |
||
48 | $this->allowed_mime_types = ['text/csv']; |
||
49 | } |
||
50 | |||
51 | $this->_set_display_strategy(new EE_File_Input_Display_Strategy()); |
||
52 | $this->_set_normalization_strategy(new EE_File_Normalization()); |
||
53 | $this->add_validation_strategy( |
||
54 | new EE_Text_Validation_Strategy( |
||
55 | sprintf( |
||
56 | // translators: %1$s is a list of allowed file extensions. |
||
57 | esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
||
58 | implode(', ', $this->allowed_file_extensions) |
||
59 | ), |
||
60 | '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
||
61 | ) |
||
62 | ); |
||
63 | parent::__construct($options); |
||
64 | |||
65 | // It would be great to add this HTML attribute, but jQuery validate chokes on it. |
||
66 | $this->set_other_html_attributes( |
||
67 | $this->other_html_attributes() |
||
68 | . ' extension="' |
||
69 | . implode( |
||
70 | ',', |
||
71 | // array_merge( |
||
72 | // array_map( |
||
73 | // function ($mime_type) { |
||
74 | // if(strpos($mime_type, '/') === false) { |
||
75 | // return $mime_type . '/*'; |
||
76 | // } else { |
||
77 | // return $mime_type; |
||
78 | // } |
||
79 | // |
||
80 | // }, |
||
81 | // $this->allowed_mime_types |
||
82 | // ) |
||
83 | array_map( |
||
84 | function ($file_extension) { |
||
85 | return $file_extension; |
||
86 | }, |
||
87 | $this->allowed_file_extensions |
||
88 | ) |
||
89 | // ) |
||
90 | ) |
||
91 | . '"' |
||
92 | ); |
||
93 | } |
||
94 | |||
166 |