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