Skip to content

Commit

Permalink
Merge pull request Getbeans#341 from lrobi2014/fix/wpcs-110
Browse files Browse the repository at this point in the history
* Fix errors and warnings in src directory.

* Fix code sniffer erros in tests

* Update getRemoteContent integration test

* Revert getRemoteContent file

* Remove g character

* Remove g character

* Rename PHP silenced errors sniffer function.

* Fix spelling mistake

* Revert change to array_replace sniff

* Style fixes.

* Style fixes
  • Loading branch information
lrobi2014 authored and christophherr committed Oct 18, 2018
1 parent 5f94284 commit c550d23
Show file tree
Hide file tree
Showing 158 changed files with 3,235 additions and 2,154 deletions.
14 changes: 10 additions & 4 deletions lib/admin/wp-customize.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
* @return void
*/
function beans_do_enqueue_wp_customize_assets() {
wp_enqueue_script( 'beans-wp-customize-preview', BEANS_ADMIN_JS_URL . 'wp-customize-preview.js', array(
'jquery',
'customize-preview',
), BEANS_VERSION, true );
wp_enqueue_script(
'beans-wp-customize-preview',
BEANS_ADMIN_JS_URL . 'wp-customize-preview.js',
array(
'jquery',
'customize-preview',
),
BEANS_VERSION,
true
);
}

beans_add_smart_action( 'customize_register', 'beans_do_register_wp_customize_options' );
Expand Down
58 changes: 35 additions & 23 deletions lib/api/compiler/class-beans-compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private function is_wp_filesystem_direct() {
*/
private function maybe_make_dir() {

if ( ! @is_dir( $this->dir ) ) { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- This is a valid use case.
if ( ! @is_dir( $this->dir ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- This is a valid use case.
wp_mkdir_p( $this->dir );
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public function set_filename() {
* @return string
*/
public function hash( array $given_array ) {
return substr( md5( @serialize( $given_array ) ), 0, 7 ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Valid use case.
return substr( md5( @serialize( $given_array ) ), 0, 7 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Valid use case.
}

/**
Expand Down Expand Up @@ -432,7 +432,7 @@ public function get_internal_content() {
$fragment = beans_url_to_path( $fragment );

// Stop here if it isn't a valid file.
if ( ! file_exists( $fragment ) || 0 === @filesize( $fragment ) ) { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.
if ( ! file_exists( $fragment ) || 0 === @filesize( $fragment ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Valid use case.
return false;
}
}
Expand Down Expand Up @@ -686,7 +686,7 @@ private function get_fragments_filemtime() {
}

if ( file_exists( $fragment ) ) {
$fragments_filemtime[ $index ] = @filemtime( $fragment ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.
$fragments_filemtime[ $index ] = @filemtime( $fragment ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Valid use case.
}
}

Expand Down Expand Up @@ -742,7 +742,7 @@ private function remove_modified_files( $hash, $filemtime_hash ) {
foreach ( $items as $item ) {

// Skip this one if it's a directory.
if ( @is_dir( $item ) ) { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.
if ( @is_dir( $item ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Valid use case.
continue;
}

Expand All @@ -769,7 +769,7 @@ private function remove_modified_files( $hash, $filemtime_hash ) {
}

// Clean up other modified files.
@unlink( $this->dir . '/' . $item ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.
@unlink( $this->dir . '/' . $item ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Valid use case.
}
}

Expand Down Expand Up @@ -844,26 +844,38 @@ private function kill() {
$this->report();
}

$html = beans_output( 'beans_compiler_error_title_text', sprintf(
'<h2>%s</h2>',
__( 'Not cool, Beans cannot work its magic :(', 'tm-beans' )
) );
$html = beans_output(
'beans_compiler_error_title_text',
sprintf(
'<h2>%s</h2>',
__( 'Not cool, Beans cannot work its magic :(', 'tm-beans' )
)
);

$html .= beans_output( 'beans_compiler_error_message_text', sprintf(
'<p>%s</p>',
__( 'Your current install or file permission prevents Beans from working its magic. Please get in touch with Beans support. We will gladly get you started within 24 - 48 hours (working days).', 'tm-beans' )
) );
$html .= beans_output(
'beans_compiler_error_message_text',
sprintf(
'<p>%s</p>',
__( 'Your current install or file permission prevents Beans from working its magic. Please get in touch with Beans support. We will gladly get you started within 24 - 48 hours (working days).', 'tm-beans' )
)
);

$html .= beans_output( 'beans_compiler_error_contact_text', sprintf(
'<a class="button" href="https://www.getbeans.io/contact/?compiler_report=1" target="_blanc">%s</a>',
__( 'Contact Beans Support', 'tm-beans' )
) );
$html .= beans_output(
'beans_compiler_error_contact_text',
sprintf(
'<a class="button" href="https://www.getbeans.io/contact/?compiler_report=1" target="_blanc">%s</a>',
__( 'Contact Beans Support', 'tm-beans' )
)
);

$html .= beans_output( 'beans_compiler_error_report_text', sprintf(
'<p style="margin-top: 12px; font-size: 12px;"><a href="' . add_query_arg( 'beans_send_compiler_report', true ) . '">%1$s</a>. %2$s</p>',
__( 'Send us an automatic report', 'tm-beans' ),
__( 'We respect your time and understand you might not be able to contact us.', 'tm-beans' )
) );
$html .= beans_output(
'beans_compiler_error_report_text',
sprintf(
'<p style="margin-top: 12px; font-size: 12px;"><a href="' . add_query_arg( 'beans_send_compiler_report', true ) . '">%1$s</a>. %2$s</p>',
__( 'Send us an automatic report', 'tm-beans' ),
__( 'We respect your time and understand you might not be able to contact us.', 'tm-beans' )
)
);

wp_die( wp_kses_post( $html ) );
}
Expand Down
12 changes: 8 additions & 4 deletions lib/api/compiler/class-beans-page-compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,14 @@ public function compile_page_scripts() {
$this->dequeued_scripts = $scripts;
add_action( 'wp_print_scripts', array( $this, 'dequeue_scripts' ), 9999 );

beans_compile_js_fragments( 'beans', $scripts, array(
'in_footer' => 'aggressive' === get_option( 'beans_compile_all_scripts_mode', 'aggressive' ),
'version' => null,
) );
beans_compile_js_fragments(
'beans',
$scripts,
array(
'in_footer' => 'aggressive' === get_option( 'beans_compile_all_scripts_mode', 'aggressive' ),
'version' => null,
)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/api/compiler/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function beans_flush_compiler( $id, $file_format = false, $admin = false ) {
foreach ( beans_scandir( $dir ) as $item ) {

if ( beans_str_ends_with( $item, ".{$file_format}" ) ) {
@unlink( trailingslashit( $dir ) . $item ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.
@unlink( trailingslashit( $dir ) . $item ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Valid use case.
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions lib/api/fields/class-beans-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,17 @@ private function add() {
* @return array
*/
private function standardize_field( array $field ) {
$field = array_merge( array(
'label' => false,
'description' => false,
'default' => false,
'context' => $this->context,
'attributes' => array(),
'db_group' => false,
), $field );
$field = array_merge(
array(
'label' => false,
'description' => false,
'default' => false,
'context' => $this->context,
'attributes' => array(),
'db_group' => false,
),
$field
);

// Set the field's name.
$field['name'] = 'wp_customize' === $this->context ? $field['id'] : 'beans_fields[' . $field['id'] . ']';
Expand Down
55 changes: 40 additions & 15 deletions lib/api/fields/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@ function beans_field( array $field ) {

$group_field_type = 'group' === $field['type'];

beans_open_markup_e( 'beans_field_wrap', 'div', array(
'class' => 'bs-field-wrap bs-' . $field['type'] . ' ' . $field['context'],
), $field );
beans_open_markup_e(
'beans_field_wrap',
'div',
array(
'class' => 'bs-field-wrap bs-' . $field['type'] . ' ' . $field['context'],
),
$field
);

// Set fields loop to cater for groups.
if ( $group_field_type ) {
Expand All @@ -109,26 +114,46 @@ function beans_field( array $field ) {
$fields = array( $field );
}

beans_open_markup_e( 'beans_field_inside', 'div', array(
'class' => 'bs-field-inside',
), $fields );
beans_open_markup_e(
'beans_field_inside',
'div',
array(
'class' => 'bs-field-inside',
),
$fields
);

if ( $group_field_type ) {
beans_open_markup_e( 'beans_field_group_fieldset', 'fieldset', array(
'class' => 'bs-field-fieldset',
), $field );
beans_open_markup_e( 'beans_field_group_legend', 'legend', array(
'class' => 'bs-field-legend',
), $field );
beans_open_markup_e(
'beans_field_group_fieldset',
'fieldset',
array(
'class' => 'bs-field-fieldset',
),
$field
);
beans_open_markup_e(
'beans_field_group_legend',
'legend',
array(
'class' => 'bs-field-legend',
),
$field
);
echo esc_html( $field['label'] );
beans_close_markup_e( 'beans_field_group_legend', 'legend', $field );
}

// Loop through fields.
foreach ( $fields as $single_field ) {
beans_open_markup_e( 'beans_field[_' . $single_field['id'] . ']', 'div', array(
'class' => 'bs-field bs-' . $single_field['type'],
), $single_field );
beans_open_markup_e(
'beans_field[_' . $single_field['id'] . ']',
'div',
array(
'class' => 'bs-field bs-' . $single_field['type'],
),
$single_field
);

if ( $group_field_type ) {
/**
Expand Down
15 changes: 9 additions & 6 deletions lib/api/fields/types/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ function beans_field_image( array $field ) {
* @return array
*/
function _beans_get_image_id_attributes( $id, array $field, $is_multiple ) {
$attributes = array_merge( array(
'class' => 'image-id',
'type' => 'hidden',
'name' => $is_multiple ? $field['name'] . '[]' : $field['name'], // Return single value if not multiple.
'value' => $id,
), $field['attributes'] );
$attributes = array_merge(
array(
'class' => 'image-id',
'type' => 'hidden',
'name' => $is_multiple ? $field['name'] . '[]' : $field['name'], // Return single value if not multiple.
'value' => $id,
),
$field['attributes']
);

if ( 'placeholder' === $id ) {
$attributes = array_merge(
Expand Down
13 changes: 8 additions & 5 deletions lib/api/fields/types/radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ function _beans_standardize_radio_image( $value, $radio ) {
);
}

$radio = array_merge( array(
'src' => '',
'alt' => '',
'screen_reader_text' => '',
), $radio );
$radio = array_merge(
array(
'src' => '',
'alt' => '',
'screen_reader_text' => '',
),
$radio
);

if ( $radio['screen_reader_text'] && $radio['alt'] ) {
return $radio;
Expand Down
3 changes: 2 additions & 1 deletion lib/api/fields/types/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* }
*/
function beans_field_text( array $field ) {
printf( '<input id="%s" type="text" name="%s" value="%s" %s>',
printf(
'<input id="%s" type="text" name="%s" value="%s" %s>',
esc_attr( $field['id'] ),
esc_attr( $field['name'] ),
esc_attr( $field['value'] ),
Expand Down
6 changes: 4 additions & 2 deletions lib/api/fields/types/textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
* }
*/
function beans_field_textarea( array $field ) {
printf( '<textarea id="%s" name="%s" %s>%s</textarea>',
printf(
'<textarea id="%s" name="%s" %s>%s</textarea>',
esc_attr( $field['id'] ),
esc_attr( $field['name'] ),
beans_esc_attributes( $field['attributes'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping is handled in the function.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping is handled in the function.
beans_esc_attributes( $field['attributes'] ),
esc_textarea( $field['value'] )
);
}
4 changes: 2 additions & 2 deletions lib/api/image/class-beans-image-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function get_image_info( $src, $edited_image_exists = false ) {
}

if ( $edited_image_exists ) {
list( $width, $height ) = @getimagesize( $this->rebuilt_path ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.
list( $width, $height ) = @getimagesize( $this->rebuilt_path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Valid use case.
} else {
$width = null;
$height = null;
Expand Down Expand Up @@ -165,7 +165,7 @@ private function get_image_info( $src, $edited_image_exists = false ) {
private function rebuild_image_path() {
$upload_dir = beans_get_images_dir();
$info = pathinfo( preg_replace( '#\?.*#', '', $this->src ) );
$query = substr( md5( @serialize( $this->args ) ), 0, 7 ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Valid use case.
$query = substr( md5( @serialize( $this->args ) ), 0, 7 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Valid use case.
$extension = $info['extension'];
$filename = str_replace( '.' . $extension, '', $info['basename'] );

Expand Down
3 changes: 2 additions & 1 deletion lib/api/image/class-beans-image-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function register() {
return beans_register_options(
$this->get_fields_to_register(),
'beans_settings',
'images_options', array(
'images_options',
array(
'title' => __( 'Images options', 'tm-beans' ),
'context' => $this->has_metaboxes() ? 'column' : 'normal',
)
Expand Down
Loading

0 comments on commit c550d23

Please sign in to comment.