Passed
Branch dev (3fd540)
by Michael
22:28
created

AdminPageFramework_Message::___doDummy()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 103
Code Lines 91

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 91
dl 0
loc 103
rs 8.1963
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
 * Admin Page Framework
4
 *
5
 * http://admin-page-framework.michaeluno.jp/
6
 * Copyright (c) 2013-2021, Michael Uno; Licensed MIT
7
 *
8
 */
9
10
/**
11
 * Provides methods for text messages.
12
 *
13
 * @since       2.0.0
14
 * @since       2.1.6       Multiple instances of this class are disallowed.
15
 * @since       3.2.0       Multiple instances of this class are allowed but the instantiation is restricted to per text domain basis.
16
 * @package     AdminPageFramework/Common/Factory/Property
17
 * @internal
18
 *
19
 * @remark      When adding a new framework translation item,
20
 * Step 1: add a key and the default value to the `$aDefaults` property array.
21
 * Step 2: add a dummy function call in the `___doDummy()` method so that parser programs can catch it.
22
 */
23
class AdminPageFramework_Message {
24
25
    /**
26
     * Stores the framework's messages.
27
     *
28
     * @since       2.0.0
29
     * @since       3.1.3       No item is defined by default but done on the fly per request. The below array structure is kept for backward compatibility.
30
     * @remark      The user may modify this property directly.
31
     */
32
    public $aMessages = array();
33
34
    /**
35
     * Stores default translated items.
36
     *
37
     * @remark      These items should be accessed only when its label needs to be displayed.
38
     * So the translation method `__()` only gets executed for one file.
39
     *
40
     * Consider the difference between the two.
41
     * <code>
42
     * $_aTranslations = array(
43
     *      'foo'  => __( 'Foo', 'admin-page-framework' ),
44
     *      'bar'  => __( 'Bar', 'admin-page-framework' ),
45
     *       ... more 100 items
46
     * )
47
     * return isset( $_aTranslations[ $sKey ] ) ? $_aTranslations[ $sKey ] : '';
48
     * </code>
49
     *
50
     * <code>
51
     * $_aTranslations = array(
52
     *      'foo'  => 'Foo',
53
     *      'bar'  => 'Bar',
54
     *       ... more 100 items
55
     * )
56
     * return isset( $_aTranslations[ $sKey ] )
57
     *      ? __( $_aTranslations[ $sKey ], $sUserSetTextdomain )
58
     *      : '';
59
     * </code>
60
     * @since       3.5.3
61
     */
62
    public $aDefaults = array(
63
64
        // AdminPageFramework
65
        'option_updated'                        => 'The options have been updated.',
66
        'option_cleared'                        => 'The options have been cleared.',
67
        'export'                                => 'Export',
68
        'export_options'                        => 'Export Options',
69
        'import'                                => 'Import',
70
        'import_options'                        => 'Import Options',
71
        'submit'                                => 'Submit',
72
        'import_error'                          => 'An error occurred while uploading the import file.',
73
        'uploaded_file_type_not_supported'      => 'The uploaded file type is not supported: %1$s',
74
        'could_not_load_importing_data'         => 'Could not load the importing data.',
75
        'imported_data'                         => 'The uploaded file has been imported.',
76
        'not_imported_data'                     => 'No data could be imported.',
77
        'upload_image'                          => 'Upload Image',
78
        'use_this_image'                        => 'Use This Image',
79
        'insert_from_url'                       => 'Insert from URL',
80
        'reset_options'                         => 'Are you sure you want to reset the options?',
81
        'confirm_perform_task'                  => 'Please confirm your action.',
82
        'specified_option_been_deleted'         => 'The specified options have been deleted.',
83
        'nonce_verification_failed'             => 'A problem occurred while processing the form data. Please try again.',
84
        'check_max_input_vars'                  => 'Not all form fields could not be sent. '
85
            . 'Please check your server settings of PHP <code>max_input_vars</code> and consult the server administrator to increase the value. '
86
            . '<code>max input vars</code>: %1$s. <code>$_POST</code> count: %2$s',  // 3.5.11+ // sanitization unnecessary as it is just a literal string
87
        'send_email'                            => 'Is it okay to send the email?',     // 3.3.0+
88
        'email_sent'                            => 'The email has been sent.',  // 3.3.0+, 3.3.5+ deprecated, 3.8.32 Re-added
89
        'email_scheduled'                       => 'The email has been scheduled.', // 3.3.5+, 3.8.32 deprecated
90
        'email_could_not_send'                  => 'There was a problem sending the email',     // 3.3.0+
91
92
        // AdminPageFramework_PostType
93
        'title'                                 => 'Title',
94
        'author'                                => 'Author',
95
        'categories'                            => 'Categories',
96
        'tags'                                  => 'Tags',
97
        'comments'                              => 'Comments',
98
        'date'                                  => 'Date',
99
        'show_all'                              => 'Show All',
100
        'show_all_authors'                      => 'Show all Authors', // 3.5.10+
101
102
        // AdminPageFramework_Link_Base
103
        'powered_by'                            => 'Thank you for creating with',
104
        'and'                                   => 'and',
105
106
        // AdminPageFramework_Link_admin_page
107
        'settings'                              => 'Settings',
108
109
        // AdminPageFramework_Link_post_type
110
        'manage'                                => 'Manage',
111
112
        // AdminPageFramework_FieldType_{...}
113
        'select_image'                          => 'Select Image',
114
        'upload_file'                           => 'Upload File',
115
        'use_this_file'                         => 'Use This File',
116
        'select_file'                           => 'Select File',
117
        'remove_value'                          => 'Remove Value',  // 3.2.0+
118
        'select_all'                            => 'Select All',    // 3.3.0+
119
        'select_none'                           => 'Select None',   // 3.3.0+
120
        'no_term_found'                         => 'No term found.', // 3.3.2+
121
122
        // AdminPageFramework_Form_View___Script_{...}
123
        'select'                                => 'Select', // 3.4.2+
124
        'insert'                                => 'Insert',  // 3.4.2+
125
        'use_this'                              => 'Use This', // 3.4.2+
126
        'return_to_library'                     => 'Return to Library', // 3.4.2+
127
128
        // AdminPageFramework_PageLoadInfo_Base
129
        'queries_in_seconds'                    => '%1$s queries in %2$s seconds.',
130
        'out_of_x_memory_used'                  => '%1$s out of %2$s (%3$s) memory used.',
131
        'peak_memory_usage'                     => 'Peak memory usage %1$s.',
132
        'initial_memory_usage'                  => 'Initial memory usage  %1$s.',
133
134
        // Repeatable sections & fields
135
        'repeatable_section_is_disabled'        => 'The ability to repeat sections is disabled.', // 3.8.13+
136
        'repeatable_field_is_disabled'          => 'The ability to repeat fields is disabled.',   // 3.8.13+
137
        'warning_caption'                       => 'Warning',   // 3.8.13+
138
139
        // AdminPageFramework_FormField
140
        'allowed_maximum_number_of_fields'      => 'The allowed maximum number of fields is {0}.',
141
        'allowed_minimum_number_of_fields'      => 'The allowed minimum number of fields is {0}.',
142
        'add'                                   => 'Add',
143
        'remove'                                => 'Remove',
144
145
        // AdminPageFramework_FormPart_Table
146
        'allowed_maximum_number_of_sections'    => 'The allowed maximum number of sections is {0}',
147
        'allowed_minimum_number_of_sections'    => 'The allowed minimum number of sections is {0}',
148
        'add_section'                           => 'Add Section',
149
        'remove_section'                        => 'Remove Section',
150
        'toggle_all'                            => 'Toggle All',
151
        'toggle_all_collapsible_sections'       => 'Toggle all collapsible sections',
152
153
        // AdminPageFramework_FieldType_reset 3.3.0+
154
        'reset'                                 => 'Reset',
155
156
        // AdminPageFramework_FieldType_system 3.5.3+
157
        'yes'                                   => 'Yes',
158
        'no'                                    => 'No',
159
        'on'                                    => 'On',
160
        'off'                                   => 'Off',
161
        'enabled'                               => 'Enabled',
162
        'disabled'                              => 'Disabled',
163
        'supported'                             => 'Supported',
164
        'not_supported'                         => 'Not Supported',
165
        'functional'                            => 'Functional',
166
        'not_functional'                        => 'Not Functional',
167
        'too_long'                              => 'Too Long',
168
        'acceptable'                            => 'Acceptable',
169
        'no_log_found'                          => 'No log found.',
170
171
        // 3.7.0+ - accessed from `AdminPageFramework_Form`
172
        'method_called_too_early'               => 'The method is called too early.',
173
174
        // 3.7.0+  - accessed from `AdminPageFramework_Form_View___DebugInfo`
175
        'debug_info'                            => 'Debug Info',
176
        // 3.8.5+
177
        'debug'                                 => 'Debug',
178
        // 'field_arguments'                       => 'Field Arguments', // @deprecated 3.8.22
179
        'debug_info_will_be_disabled'           => 'This information will be disabled when <code>WP_DEBUG</code> is set to <code>false</code> in <code>wp-config.php</code>.',
180
181
        // 'section_arguments'                     => 'Section Arguments', // 3.8.8+   // @deprecated 3.8.22
182
183
        'click_to_expand'                       => 'Click here to expand to view the contents.',
184
        'click_to_collapse'                     => 'Click here to collapse the contents.',
185
186
        // 3.7.0+ - displayed while the page laods
187
        'loading'                               => 'Loading...',
188
        'please_enable_javascript'              => 'Please enable JavaScript for better user experience.',
189
190
        'submit_confirmation_label'             => 'Submit the form.',
191
        'submit_confirmation_error'             => 'Please check this box if you want to proceed.',
192
        'import_no_file'                        => 'No file is selected.',
193
194
        // 3.9.0
195
        'please_fill_out_this_field'            => 'Please fill out this field.',
196
197
    );
198
199
    /**
200
     * Stores the text domain.
201
     * @since       3.x
202
     * @since       3.5.0       Declared as a default property.
203
     */
204
    protected $_sTextDomain = 'admin-page-framework';
205
206
    /**
207
     * Stores the self instance by text domain.
208
     * @internal
209
     * @since       3.2.0
210
     */
211
    static private $_aInstancesByTextDomain = array();
212
213
    /**
214
     * Ensures that only one instance of this class object exists. ( no multiple instances of this object )
215
     *
216
     * @since       2.1.6
217
     * @since       3.2.0       Changed it to create an instance per text domain basis.
218
     * @param       string      $sTextDomain
219
     * @remark      This class should be instantiated via this method.
220
     * @return      AdminPageFramework_Message
221
     */
222
    public static function getInstance( $sTextDomain='admin-page-framework' ) {
223
224
        $_oInstance = isset( self::$_aInstancesByTextDomain[ $sTextDomain ] ) && ( self::$_aInstancesByTextDomain[ $sTextDomain ] instanceof AdminPageFramework_Message )
225
            ? self::$_aInstancesByTextDomain[ $sTextDomain ]
226
            : new AdminPageFramework_Message( $sTextDomain );
227
        self::$_aInstancesByTextDomain[ $sTextDomain ] = $_oInstance;
228
        return self::$_aInstancesByTextDomain[ $sTextDomain ];
229
230
    }
231
        /**
232
         * Ensures that only one instance of this class object exists. ( no multiple instances of this object )
233
         * @deprecated  3.2.0
234
         */
235
        public static function instantiate( $sTextDomain='admin-page-framework' ) {
236
            return self::getInstance( $sTextDomain );
237
        }
238
239
    /**
240
     * Sets up properties.
241
     * @param string $sTextDomain
242
     */
243
    public function __construct( $sTextDomain='admin-page-framework' ) {
244
245
        $this->_sTextDomain = $sTextDomain;
246
247
        // Fill the $aMessages property with the keys extracted from the $aDefaults property
248
        // with the value of null.  The null is set to let it trigger the __get() method
249
        // so that each translation item gets processed individually.
250
        $this->aMessages    = array_fill_keys(
251
            array_keys( $this->aDefaults ),
252
            null
253
        );
254
255
    }
256
257
    /**
258
     * Returns the set text domain string.
259
     *
260
     * This is used from field type and input classes to display deprecated admin errors/
261
     *
262
     * @since       3.3.3
263
     */
264
    public function getTextDomain() {
265
        return $this->_sTextDomain;
266
    }
267
268
    /**
269
     * Sets a message for the given key.
270
     * @since       3.7.0
271
     */
272
    public function set( $sKey, $sValue ) {
273
        $this->aMessages[ $sKey ] = $sValue;
274
    }
275
276
    /**
277
     * Returns the framework system message by key.
278
     *
279
     * @remark      An alias of the __() method.
280
     * @since       3.2.0
281
     * @since       3.7.0        If no key is specified, return the entire mesage array.
282
     * @param       string       $sKey
283
     * @return      string|array
284
     */
285
    public function get( $sKey='' ) {
286
        if ( ! $sKey ) {
287
            return $this->_getAllMessages();
288
        }
289
        return isset( $this->aMessages[ $sKey ] )
290
            ? __( $this->aMessages[ $sKey ], $this->_sTextDomain )
291
            : __( $this->{$sKey}, $this->_sTextDomain );     // triggers __get()
292
    }
293
        /**
294
         * Returns the all registered messag items.
295
         * By default, no item is set for a performance reason; the message is retuned on the fly.
296
         * So all the keys must be iterated to get all the values.
297
         * @since       3.7.0
298
         * @return      array
299
         */
300
        private function _getAllMessages() {
301
            $_aMessages = array();
302
            foreach ( $this->aMessages as $_sLabel => $_sTranslation ) {
303
                $_aMessages[ $_sLabel ] = $this->get( $_sLabel );
304
            }
305
            return $_aMessages;
306
        }
307
308
    /**
309
     * Echoes the framework system message by key.
310
     * @remark  An alias of the _e() method.
311
     * @since   3.2.0
312
     */
313
    public function output( $sKey ) {
314
        echo $this->get( $sKey );
0 ignored issues
show
Bug introduced by
Are you sure $this->get($sKey) of type array|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

314
        echo /** @scrutinizer ignore-type */ $this->get( $sKey );
Loading history...
315
    }
316
317
        /**
318
         * Returns the framework system message by key.
319
         * @since       2.x
320
         * @deprecated  3.2.0
321
         */
322
        public function __( $sKey ) {
323
            return $this->get( $sKey );
324
        }
325
        /**
326
         * Echoes the framework system message by key.
327
         * @since       2.x
328
         * @deprecated  3.2.0
329
         */
330
        public function _e( $sKey ) {
331
            $this->output( $sKey );
332
        }
333
334
    /**
335
     * Responds to a request to an undefined property.
336
     *
337
     * @since       3.1.3
338
     * @return      string
339
     */
340
    public function __get( $sPropertyName ) {
341
        return isset( $this->aDefaults[ $sPropertyName ] ) ? $this->aDefaults[ $sPropertyName ] : $sPropertyName;
342
    }
343
344
345
    /**
346
     * A dummy method just lists translation items to be parsed by translation programs such as POEdit.
347
     *
348
     * @since       3.5.3
349
     * @since       3.8.19  Changed the name to avoid false-positives of PHP 7.2 incompatibility by third party tools.
350
     */
351
    private function ___doDummy() {
352
353
        __( 'The options have been updated.', 'admin-page-framework' );
354
        __( 'The options have been cleared.', 'admin-page-framework' );
355
        __( 'Export', 'admin-page-framework' );
356
        __( 'Export Options', 'admin-page-framework' );
357
        __( 'Import', 'admin-page-framework' );
358
        __( 'Import Options', 'admin-page-framework' );
359
        __( 'Submit', 'admin-page-framework' );
360
        __( 'An error occurred while uploading the import file.', 'admin-page-framework' );
361
        __( 'The uploaded file type is not supported: %1$s', 'admin-page-framework' );
362
        __( 'Could not load the importing data.', 'admin-page-framework' );
363
        __( 'The uploaded file has been imported.', 'admin-page-framework' );
364
        __( 'No data could be imported.', 'admin-page-framework' );
365
        __( 'Upload Image', 'admin-page-framework' );
366
        __( 'Use This Image', 'admin-page-framework' );
367
        __( 'Insert from URL', 'admin-page-framework' );
368
        __( 'Are you sure you want to reset the options?', 'admin-page-framework' );
369
        __( 'Please confirm your action.', 'admin-page-framework' );
370
        __( 'The specified options have been deleted.', 'admin-page-framework' );
371
        __( 'A problem occurred while processing the form data. Please try again.', 'admin-page-framework' );
372
        __( 'Not all form fields could not be sent. Please check your server settings of PHP <code>max_input_vars</code> and consult the server administrator to increase the value. <code>max input vars</code>: %1$s. <code>$_POST</code> count: %2$s', 'admin-page-framework' ); // sanitization unnecessary as a literal string
373
        __( 'Is it okay to send the email?', 'admin-page-framework' );
374
        __( 'The email has been sent.', 'admin-page-framework' );
375
        __( 'The email has been scheduled.', 'admin-page-framework' );
376
        __( 'There was a problem sending the email', 'admin-page-framework' );
377
        __( 'Title', 'admin-page-framework' );
378
        __( 'Author', 'admin-page-framework' );
379
        __( 'Categories', 'admin-page-framework' );
380
        __( 'Tags', 'admin-page-framework' );
381
        __( 'Comments', 'admin-page-framework' );
382
        __( 'Date', 'admin-page-framework' );
383
        __( 'Show All', 'admin-page-framework' );
384
        __( 'Show All Authors', 'admin-page-framework' );
385
        __( 'Thank you for creating with', 'admin-page-framework' );
386
        __( 'and', 'admin-page-framework' );
387
        __( 'Settings', 'admin-page-framework' );
388
        __( 'Manage', 'admin-page-framework' );
389
        __( 'Select Image', 'admin-page-framework' );
390
        __( 'Upload File', 'admin-page-framework' );
391
        __( 'Use This File', 'admin-page-framework' );
392
        __( 'Select File', 'admin-page-framework' );
393
        __( 'Remove Value', 'admin-page-framework' );
394
        __( 'Select All', 'admin-page-framework' );
395
        __( 'Select None', 'admin-page-framework' );
396
        __( 'No term found.', 'admin-page-framework' );
397
        __( 'Select', 'admin-page-framework' );
398
        __( 'Insert', 'admin-page-framework' );
399
        __( 'Use This', 'admin-page-framework' );
400
        __( 'Return to Library', 'admin-page-framework' );
401
        __( '%1$s queries in %2$s seconds.', 'admin-page-framework' );
402
        __( '%1$s out of %2$s MB (%3$s) memory used.', 'admin-page-framework' );
403
        __( 'Peak memory usage %1$s MB.', 'admin-page-framework' );
404
        __( 'Initial memory usage  %1$s MB.', 'admin-page-framework' );
405
        __( 'The allowed maximum number of fields is {0}.', 'admin-page-framework' );
406
        __( 'The allowed minimum number of fields is {0}.', 'admin-page-framework' );
407
        __( 'Add', 'admin-page-framework' );
408
        __( 'Remove', 'admin-page-framework' );
409
        __( 'The allowed maximum number of sections is {0}', 'admin-page-framework' );
410
        __( 'The allowed minimum number of sections is {0}', 'admin-page-framework' );
411
        __( 'Add Section', 'admin-page-framework' );
412
        __( 'Remove Section', 'admin-page-framework' );
413
        __( 'Toggle All', 'admin-page-framework' );
414
        __( 'Toggle all collapsible sections', 'admin-page-framework' );
415
        __( 'Reset', 'admin-page-framework' );
416
        __( 'Yes', 'admin-page-framework' );
417
        __( 'No', 'admin-page-framework' );
418
        __( 'On', 'admin-page-framework' );
419
        __( 'Off', 'admin-page-framework' );
420
        __( 'Enabled', 'admin-page-framework' );
421
        __( 'Disabled', 'admin-page-framework' );
422
        __( 'Supported', 'admin-page-framework' );
423
        __( 'Not Supported', 'admin-page-framework' );
424
        __( 'Functional', 'admin-page-framework' );
425
        __( 'Not Functional', 'admin-page-framework' );
426
        __( 'Too Long', 'admin-page-framework' );
427
        __( 'Acceptable', 'admin-page-framework' );
428
        __( 'No log found.', 'admin-page-framework' );
429
430
        __( 'The method is called too early: %1$s', 'admin-page-framework' );
431
        __( 'Debug Info', 'admin-page-framework' );
432
433
        __( 'Click here to expand to view the contents.', 'admin-page-framework' );
434
        __( 'Click here to collapse the contents.', 'admin-page-framework' );
435
436
        __( 'Loading...', 'admin-page-framework' );
437
        __( 'Please enable JavaScript for better user experience.', 'admin-page-framework' );
438
439
        __( 'Debug', 'admin-page-framework' );
440
        // __( 'Field Arguments', 'admin-page-framework' ); @deprecated 3.8.22
441
        __( 'This information will be disabled when <code>WP_DEBUG</code> is set to <code>false</code> in <code>wp-config.php</code>.', 'admin-page-framework' );
442
443
        // __( 'Section Arguments', 'admin-page-framework' ); // 3.8.8+ @deprecated 3.8.22
444
445
        __( 'The ability to repeat sections is disabled.', 'admin-page-framework' ); // 3.8.13+
446
        __( 'The ability to repeat fields is disabled.', 'admin-page-framework' ); // 3.8.13+
447
        __( 'Warning.', 'admin-page-framework' ); // 3.8.13+
448
449
        __( 'Submit the form.', 'admin-page-framework' ); // 3.8.24
450
        __( 'Please check this box if you want to proceed.', 'admin-page-framework' ); // 3.8.24
451
        __( 'No file is selected.', 'admin-page-framework' ); // 3.8.24
452
453
        __( 'Please fill out this field.', 'admin-page-framework' ); // 3.9.0
454
455
    }
456
457
}