Total Lines | 82 |
Code Lines | 36 |
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 // -*- coding: utf-8 -*- |
||
29 | static function() { |
||
30 | /** |
||
31 | * @param string $message |
||
32 | * @param string $noticeType |
||
33 | * @param array $allowedMarkup |
||
34 | */ |
||
35 | function adminNotice($message, $noticeType, array $allowedMarkup = []) |
||
36 | { |
||
37 | \assert(\is_string($message) && \is_string($noticeType)); |
||
38 | |||
39 | add_action( |
||
40 | 'admin_notices', |
||
41 | static function() use ($message, $noticeType, $allowedMarkup) { |
||
42 | ?> |
||
43 | <div class="notice notice-<?= esc_attr($noticeType) ?>"> |
||
|
|||
44 | <p><?= wp_kses($message, $allowedMarkup) ?></p> |
||
45 | </div> |
||
46 | <?php |
||
47 | } |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return bool |
||
53 | */ |
||
54 | function autoload() |
||
55 | { |
||
56 | if (\class_exists(PluginProperties::class)) { |
||
57 | return true; |
||
58 | } |
||
59 | |||
60 | $autoloader = plugin_dir_path(__FILE__).'/vendor/autoload.php'; |
||
61 | |||
62 | if (!\file_exists($autoloader)) { |
||
63 | return false; |
||
64 | } |
||
65 | |||
66 | /** @noinspection PhpIncludeInspection */ |
||
67 | require_once $autoloader; |
||
68 | |||
69 | return true; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Compare PHP Version with our minimum. |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | function isPhpVersionCompatible() |
||
78 | { |
||
79 | return PHP_VERSION_ID >= 70000; |
||
80 | } |
||
81 | |||
82 | if (!isPhpVersionCompatible()) { |
||
83 | adminNotice( |
||
84 | sprintf( |
||
85 | // Translators: %s is the PHP version of the current installation, where is the plugin is active. |
||
86 | __( |
||
87 | 'Multisite Global Media require php version 7.0 at least. Your\'s is %s', |
||
88 | 'multisite-global-media' |
||
89 | ), |
||
90 | PHP_VERSION |
||
91 | ), |
||
92 | 'error' |
||
93 | ); |
||
94 | |||
95 | return; |
||
96 | } |
||
97 | if (!autoload()) { |
||
98 | adminNotice( |
||
99 | __( |
||
100 | 'No suitable autoloader found. Multisite Global Media cannot be loaded correctly.', |
||
101 | 'multisite-global-media' |
||
102 | ), |
||
103 | 'error' |
||
104 | ); |
||
105 | |||
106 | return; |
||
107 | } |
||
108 | |||
109 | $plugin = new Plugin(__FILE__); |
||
110 | $plugin->onLoad(); |
||
111 | }, |
||
115 |