Skip to content

Commit

Permalink
FIX: phpcs & enable workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
girafffee committed Aug 9, 2023
1 parent ab57541 commit 839a038
Show file tree
Hide file tree
Showing 73 changed files with 256 additions and 133 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/php.lint.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ name: PHP Lint & Test
on:
# allow to manually run this workflow from the UI
workflow_dispatch:
# push:
# paths:
# - '**.php'
# branches:
# - main
# pull_request:
# paths:
# - '**.php'
# branches:
# - main
push:
paths:
- '**.php'
branches:
- main
pull_request:
paths:
- '**.php'
branches:
- main

env:
DB_HOST: 127.0.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public function query_source() {
$item = jet_engine()->options_pages->registered_pages[ $this->page ] ?? false;

if ( ! $item ) {
throw new Preset_Exception( "Undefined option page: {$this->page}" );
throw new Preset_Exception(
sprintf(
'Undefined option page: %s',
esc_html( $this->page )
)
);
}

return $item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function get_value( Abstract_Modifier $modifier ) {
try {
$product->set_catalog_visibility( $this->value );
} catch ( \WC_Data_Exception $exception ) {
throw new Action_Exception( $exception->getMessage() );
throw new Action_Exception( esc_html( $exception->getMessage() ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function do_before( string $key, $value, Abstract_Modifier $modifier ) {
try {
$this->value = new \WC_Product( $value );
} catch ( \Exception $exception ) {
throw new Action_Exception( $exception->getMessage() );
throw new Action_Exception( esc_html( $exception->getMessage() ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function get_value( Abstract_Modifier $modifier ) {
try {
$product->set_sku( $this->value );
} catch ( \WC_Data_Exception $exception ) {
throw new Action_Exception( $exception->getMessage() );
throw new Action_Exception( esc_html( $exception->getMessage() ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function get_value( Abstract_Modifier $modifier ) {
try {
$product->set_tax_status( $this->value );
} catch ( \WC_Data_Exception $exception ) {
throw new Action_Exception( $exception->getMessage() );
throw new Action_Exception( esc_html( $exception->getMessage() ) );
}
}

Expand Down
9 changes: 5 additions & 4 deletions components/repository/repository-aborts-trait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

<?php // phpcs:ignore Internal.Exception

namespace JFB_Components\Repository;

Expand All @@ -10,10 +9,10 @@
die;
}

// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore

trait Repository_Aborts_Trait {

// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore

/**
* @throws Repository_Exception
*/
Expand Down Expand Up @@ -47,4 +46,6 @@ final public function _rep_abort_and_die_code() {
return 3;
}

// phpcs:enable PSR2.Methods.MethodDeclaration.Underscore

}
5 changes: 2 additions & 3 deletions components/repository/repository-pattern-trait.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php

<?php // phpcs:ignore Internal.Exception

namespace JFB_Components\Repository;

use Jet_Form_Builder\Exceptions\Handler_Exception;
use Jet_Form_Builder\Exceptions\Repository_Exception;

// If this file is called directly, abort.
Expand Down Expand Up @@ -47,6 +45,7 @@ public function rep_install( $instances = array() ) {
esc_html( $exception->getMessage() ),
'2.0.0'
);
break;
}
}

Expand Down
14 changes: 10 additions & 4 deletions includes/actions/conditions/condition-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,17 @@ public function check_all() {
return;
case self::THROW_IF_ONE_WRONG:
default:
throw new Condition_Exception( $exception->getMessage(), ...$exception->get_additional() );
throw new Condition_Exception(
esc_html( $exception->getMessage() ),
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
...$exception->get_additional()
);
}
}
}

if ( 'or' === $this->operator ) {
throw new Condition_Exception( 'None of the conditions are met' );
throw new Condition_Exception( esc_html__( 'None of the conditions are met', 'jet-form-builder' ) );
}
}

Expand Down Expand Up @@ -168,16 +172,18 @@ public function throw_by_method( $is_success, ...$additional ) {
case 'or':
if ( $is_success ) {
throw new Condition_Silence_Exception(
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
self::THROW_IF_ONE_MATCH,
...$additional
...$additional // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
break;
case 'and':
if ( ! $is_success ) {
throw new Condition_Silence_Exception(
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
self::THROW_IF_ONE_WRONG,
...$additional
...$additional // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
<?php // phpcs:ignore Internal.Exception


namespace Jet_Form_Builder\Actions\Events\Default_Process;

use Jet_Form_Builder\Actions\Types\Base;
use Jet_Form_Builder\Actions\Types\Save_Record;
use JFB_Modules\Form_Record\Action_Types\Save_Record;
use Jet_Form_Builder\Exceptions\Action_Exception;
use Jet_Form_Builder\Exceptions\Gateway_Exception;
use Jet_Form_Builder\Exceptions\Repository_Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function do_action() {

throw new Action_Exception(
'failed',
$this->inserted_id->get_error_message()
esc_html( $this->inserted_id->get_error_message() )
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function can_attach( string $key, $value ): bool {
return false;
}
if ( empty( $value ) ) {
throw new Action_Exception( 'empty_field', $key );
throw new Action_Exception( 'empty_field', esc_html( $key ) );
}

$post = get_post( (int) $value );
Expand All @@ -50,7 +50,7 @@ public function can_attach( string $key, $value ): bool {
throw new Action_Exception(
'failed',
array(
'post' => $post,
'post' => $post, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function do_action() {

throw new Action_Exception(
'failed',
$this->inserted_id->get_error_message()
esc_html( $this->inserted_id->get_error_message() )
);
}
}
4 changes: 2 additions & 2 deletions includes/actions/methods/update-user/update-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function do_action() {

if ( is_wp_error( $response ) ) {
throw new Action_Exception(
$response->get_error_message(),
$response->get_error_data()
esc_html( $response->get_error_message() ),
esc_html( $response->get_error_data() )
);
}
}
Expand Down
1 change: 1 addition & 0 deletions includes/actions/methods/update-user/user-id-property.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function do_before( string $key, $value, Abstract_Modifier $modifier ) {
$this->user = get_user_by( 'ID', $this->value );

if ( ! is_a( $this->user, \WP_User::class ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
throw new Action_Exception( 'internal_error', $this->user, $this->value );
}
}
Expand Down
5 changes: 4 additions & 1 deletion includes/actions/types/call-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public function action_attributes() {
public function do_action( array $request, Action_Handler $handler ) {

if ( empty( $this->settings['hook_name'] ) ) {
throw new Action_Exception( 'failed', $this->settings );
throw new Action_Exception(
'failed',
esc_html__( 'Empty hook name', 'jet-form-builder' )
);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions includes/actions/types/call-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function do_action( array $request, Action_Handler $handler ) {
$webhook_url = ! empty( $this->settings['webhook_url'] ) ? trim( $this->settings['webhook_url'] ) : false;

if ( ! $webhook_url ) {
throw new Action_Exception( 'failed', $this->settings );
throw new Action_Exception(
'failed',
esc_html__( 'Empty webhook url', 'jet-form-builder' )
);
}

$args = array(
Expand Down Expand Up @@ -71,7 +74,11 @@ public function do_action( array $request, Action_Handler $handler ) {
$response = wp_remote_post( $webhook_url, $args );

if ( $response instanceof \WP_Error ) {
throw new Action_Exception( 'failed', $response );
throw new Action_Exception(
'failed',
esc_html__( 'Remote request returned error', 'jet-form-builder' ),
$response // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
/**
* Fires whe webhook response received
Expand Down
8 changes: 6 additions & 2 deletions includes/actions/types/getresponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function do_action( array $request, Action_Handler $handler ) {
throw new Action_Exception(
'empty_field',
array(
'email' => $body_args['email'],
'email' => esc_html( $body_args['email'] ),
)
);
}
Expand All @@ -139,7 +139,11 @@ public function do_action( array $request, Action_Handler $handler ) {

// Error response
if ( isset( $response['httpStatus'] ) && isset( $response['code'] ) ) {
throw new Action_Exception( "derror|{$response['message']}", $response );
throw new Action_Exception(
esc_html( "derror|{$response['message']}" ),
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$response
);
}
}

Expand Down
3 changes: 2 additions & 1 deletion includes/actions/types/mailchimp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore Internal.Exception

namespace Jet_Form_Builder\Actions\Types;

Expand Down Expand Up @@ -299,6 +299,7 @@ private function get_body_args( $fields_map ) {
break;
default:
$body_args['merge_fields'][ $param ] = $this->request[ $field ];
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions includes/actions/types/redirect-to-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function do_action( array $request, Action_Handler $handler ) {
$to_url = $this->get_redirect_url();

if ( ! $to_url ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
throw new Action_Exception( 'failed', $this->settings );
}

Expand Down
1 change: 1 addition & 0 deletions includes/actions/types/register-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public function do_action( array $request, Action_Handler $handler ) {
jet_fb_context()->update_request( $user_id, 'user_id' );
}
} else {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
throw new Action_Exception( 'failed', $userarr );
}
}
Expand Down
10 changes: 5 additions & 5 deletions includes/actions/types/send-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Jet_Form_Builder\Actions\Types;

// If this file is called directly, abort.
use Jet_Form_Builder\Actions\Action_Handler;
use Jet_Form_Builder\Classes\Tools;
use Jet_Form_Builder\Dev_Mode;
use Jet_Form_Builder\Exceptions\Action_Exception;
use Jet_Form_Builder\Request\Request_Tools;

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
Expand Down Expand Up @@ -254,10 +254,10 @@ function ( \WP_Error $wp_error ) {
throw new Action_Exception(
'failed',
array(
'to' => $this->get_mail_to(),
'subject' => $this->get_subject(),
'message' => $message,
'headers' => $this->get_headers(),
'to' => $this->get_mail_to(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'subject' => $this->get_subject(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'message' => $message, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'headers' => $this->get_headers(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
)
);
}
Expand Down
4 changes: 3 additions & 1 deletion includes/admin/single-pages/base-single-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public function query_id(): int {
*/
public function set_id( int $id ): Base_Single_Page {
if ( ! $id ) {
throw new Not_Found_Page_Exception( 'Item id is empty: ' . $id . ' in ' . static::class );
throw new Not_Found_Page_Exception(
esc_html( 'Item id is empty: ' . $id . ' in ' . static::class )
);
}
$this->id = $id;

Expand Down
6 changes: 5 additions & 1 deletion includes/admin/single-pages/meta-boxes/base-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public function to_array(): array {
try {
$this->prepare_dependencies();
} catch ( Sql_Exception $exception ) {
throw new Empty_Box_Exception( $exception->getMessage(), ...$exception->get_additional() );
throw new Empty_Box_Exception(
esc_html( $exception->getMessage() ),
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
...$exception->get_additional()
);
}

return array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function get_box_by_scope( string $scoped_slug ): Base_Meta_Box {
}
}

throw new Repository_Exception( 'Undefined ' . $scoped_slug );
throw new Repository_Exception( esc_html( 'Undefined ' . $scoped_slug ) );
}

public function get_migrations(): \Generator {
Expand Down
Loading

0 comments on commit 839a038

Please sign in to comment.