-
Notifications
You must be signed in to change notification settings - Fork 114
Update the class-directories-check.php #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| <?php | ||
| /** | ||
| * Check if directories only intended for development are included | ||
| * Check if disallowed directories are included | ||
| * | ||
| * @package Theme Check | ||
| */ | ||
|
|
||
| /** | ||
| * Check if directories only intended for development are included. | ||
| * Check if disallowed directories are included. | ||
| * | ||
| * Check if directories only intended for development are included. If they are, require them to be removed. | ||
| * Checks each file path for disallowed directory names such as .git or __MACOSX. | ||
| * Empty disallowed directories will not be detected as they contain no files. | ||
| */ | ||
| class Directories_Check implements themecheck { | ||
| /** | ||
|
|
@@ -21,13 +22,14 @@ class Directories_Check implements themecheck { | |
| /** | ||
| * Check that return true for good/okay/acceptable, false for bad/not-okay/unacceptable. | ||
| * | ||
| * @param array $php_files File paths and content for PHP files. | ||
| * @param array $css_files File paths and content for CSS files. | ||
| * @param array $php_files File paths and content for PHP files. | ||
| * @param array $css_files File paths and content for CSS files. | ||
| * @param array $other_files Folder names, file paths and content for other files. | ||
| */ | ||
| public function check( $php_files, $css_files, $other_files ) { | ||
|
|
||
| $excluded_directories = array( | ||
| '__MACOSX', | ||
| '.git', | ||
| '.svn', | ||
| '.hg', | ||
|
|
@@ -45,15 +47,16 @@ public function check( $php_files, $css_files, $other_files ) { | |
| foreach ( $all_filenames as $path ) { | ||
| checkcount(); | ||
|
|
||
| $filename = basename( $path ); | ||
| $path_segments = explode( '/', str_replace( '\\', '/', $path ) ); | ||
|
|
||
| if ( in_array( $filename, $excluded_directories, true ) ) { | ||
| if ( array_intersect( $path_segments, $excluded_directories ) ) { | ||
| $this->error[] = sprintf( | ||
| '<span class="tc-lead tc-required">%s</span>: %s', | ||
| __( 'REQUIRED', 'theme-check' ), | ||
| __( 'Please remove any extraneous directories like .git or .svn from the ZIP file before uploading it.', 'theme-check' ) | ||
| __( 'Please remove any extraneous directories like <strong>.git</strong>, <strong>.svn</strong> or <strong>__MACOSX</strong> from the ZIP file before uploading it.', 'theme-check' ) | ||
|
||
| ); | ||
| $ret = false; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array_intersect()returns an array; relying on its truthiness is a bit implicit. For readability, consider checking it explicitly (e.g., assign to a variable and/or use! empty(...)) so it’s clear the condition is “any disallowed segment matched”.