Conditions | 17 |
Paths | 42 |
Total Lines | 78 |
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 // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
66 | private function get_plugins( $plugin_folder = '' ) { |
||
67 | $cache_plugins = wp_cache_get( 'monorepo_plugins', 'monorepo_plugins' ); // Updated cache values to not conflict. |
||
68 | if ( ! $cache_plugins ) { |
||
69 | $cache_plugins = array(); |
||
70 | } |
||
71 | |||
72 | if ( isset( $cache_plugins[ $plugin_folder ] ) ) { |
||
73 | return $cache_plugins[ $plugin_folder ]; |
||
74 | } |
||
75 | |||
76 | $wp_plugins = array(); |
||
77 | $plugin_root = WP_PLUGIN_DIR; |
||
78 | if ( ! empty( $plugin_folder ) ) { |
||
79 | $plugin_root = $plugin_folder; // This is what we changed, but it's dangerous. Thus a private function. |
||
80 | } |
||
81 | |||
82 | // Files in wp-content/plugins directory. |
||
83 | $plugins_dir = @opendir( $plugin_root ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
||
84 | $plugin_files = array(); |
||
85 | |||
86 | if ( $plugins_dir ) { |
||
87 | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition |
||
88 | if ( '.' === substr( $file, 0, 1 ) ) { |
||
89 | continue; |
||
90 | } |
||
91 | |||
92 | if ( is_dir( $plugin_root . '/' . $file ) ) { |
||
93 | $plugins_subdir = @opendir( $plugin_root . '/' . $file ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
||
94 | |||
95 | if ( $plugins_subdir ) { |
||
96 | while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition |
||
97 | if ( '.' === substr( $subfile, 0, 1 ) ) { |
||
98 | continue; |
||
99 | } |
||
100 | |||
101 | if ( '.php' === substr( $subfile, -4 ) ) { |
||
102 | $plugin_files[] = "$file/$subfile"; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | closedir( $plugins_subdir ); |
||
107 | } |
||
108 | } else { |
||
109 | if ( '.php' === substr( $file, -4 ) ) { |
||
110 | $plugin_files[] = $file; |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | |||
115 | closedir( $plugins_dir ); |
||
116 | } |
||
117 | |||
118 | if ( empty( $plugin_files ) ) { |
||
119 | return $wp_plugins; |
||
120 | } |
||
121 | |||
122 | foreach ( $plugin_files as $plugin_file ) { |
||
123 | if ( ! is_readable( "$plugin_root/$plugin_file" ) ) { |
||
124 | continue; |
||
125 | } |
||
126 | |||
127 | // Do not apply markup/translate as it will be cached. |
||
128 | $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); |
||
129 | |||
130 | if ( empty( $plugin_data['Name'] ) ) { |
||
131 | continue; |
||
132 | } |
||
133 | |||
134 | $wp_plugins[ plugin_basename( $plugin_file ) ] = $plugin_data; |
||
135 | } |
||
136 | |||
137 | uasort( $wp_plugins, '_sort_uname_callback' ); |
||
138 | |||
139 | $cache_plugins[ $plugin_folder ] = $wp_plugins; |
||
140 | wp_cache_set( 'monorepo_plugins', $cache_plugins, 'monorepo_plugins' ); // Updated cache values to not conflict. |
||
141 | |||
142 | return $wp_plugins; |
||
143 | } |
||
144 | |||
154 |