Skip to content

Commit

Permalink
Phpstan level 4
Browse files Browse the repository at this point in the history
  • Loading branch information
stephywells committed Jun 25, 2024
1 parent cf03997 commit 1aeb950
Show file tree
Hide file tree
Showing 94 changed files with 248 additions and 618 deletions.
2 changes: 1 addition & 1 deletion admin/admin-panel-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function custom_column($value, $column, $user_id) {
public function ajax_edit_balance($user_id, $action) {
$user = get_user_by('id', $user_id);

if (is_null($user)) {
if ( ! $user ) {
$message = __("The specified User doesn't exists.", 'another-wordpress-classifieds-plugin');
$response = array('status' => 'error', 'message' => $message);
}
Expand Down
6 changes: 3 additions & 3 deletions admin/admin-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@ private function load_notice_for_non_blocking_manual_uprades() {
/**
* Add settings link on plugins page
*
* @author Aman Saini
* @since 3.6.5
* @param Array $links
* @param String $file
*
* @param array $links
* @param string $file
*/
public function add_settings_link( $links, $file ) {
if ( $this->upgrade_tasks->has_pending_tasks( array( 'context' => 'plugin', 'blocking' => true ) ) ) {
Expand Down
2 changes: 1 addition & 1 deletion admin/class-csv-exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function get_file_url() {
}

/**
* @return bool|string
* @return string
*/
private function header() {
$out = '';
Expand Down
3 changes: 2 additions & 1 deletion admin/class-import-listings-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ private function upload_files() {
} elseif ( $form_data['images_source'] == 'local' ) {
$local_directory = realpath( $uploads_dir . DIRECTORY_SEPARATOR . str_replace( '..', '', $form_data['local_path'] ) );

if ( strpos( $local_directory, $uploads_dir ) !== 0 || strpos( $local_directory, $uploads_dir ) === false ) {
$in_uploads = strpos( $local_directory, $uploads_dir );
if ( absint( $in_uploads ) > 0 || $in_uploads === false ) {
$form_errors['local_path'] = __( 'The specified directory is not a valid path.', 'another-wordpress-classifieds-plugin' );
} elseif ( ! is_dir( $local_directory ) ) {
$form_errors['local_path'] = __( 'The specified directory does not exists.', 'another-wordpress-classifieds-plugin' );
Expand Down
32 changes: 8 additions & 24 deletions admin/class-import-settings-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
* Constructor function for AWPCP_Import_Settings_Admin_Page class
*/
function awpcp_import_settings_admin_page() {
return new AWPCP_Import_Settings_Admin_Page(
awpcp_settings_json_writer(),
awpcp_roles_and_capabilities(),
awpcp_template_renderer(),
awpcp_request()
);
return new AWPCP_Import_Settings_Admin_Page();
}

/**
Expand All @@ -26,38 +21,27 @@ class AWPCP_Import_Settings_Admin_Page {
private $nonce_action = 'awpcp-import-settings';

/**
* @var object
* @var AWPCP_Settings_JSON_Writer
*/
private $settings_writer;

/**
* @var object
*/
private $capabilities;

/**
* @var object
* @var AWPCP_Template_Renderer
*/
private $template_renderer;

/**
* @var object
* @var AWPCP_Request
*/
private $request;

/**
* Constructor.
*
* @param object $settings_writer An instance of Settings Writer.
* @param object $capabilities An instance of RolesAndCapabilities.
* @param object $template_renderer An instance of Template_Renderer.
* @param object $request An instance of Request.
*/
public function __construct( $settings_writer, $capabilities, $template_renderer, $request ) {
$this->settings_writer = $settings_writer;
$this->capabilities = $capabilities;
$this->template_renderer = $template_renderer;
$this->request = $request;
public function __construct() {
$this->settings_writer = awpcp_settings_json_writer();
$this->template_renderer = awpcp_template_renderer();
$this->request = awpcp_request();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/class-settings-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ public function dispatch() {
case 'display_settings':
default:
return $this->display_settings();
break;
}
}

Expand All @@ -240,6 +239,7 @@ private function display_settings( $errors=array() ) {
$error_msg = '';
$error_msg .= '<strong>' . __( 'Facebook Config Diagnostics', 'another-wordpress-classifieds-plugin' ) . '</strong><br />';

// @phpstan-ignore-next-line
if ( $diagnostics_errors ) {
foreach ( $diagnostics_errors as &$e ) {
$error_msg .= '&#149; ' . $e . '<br />';
Expand Down
14 changes: 4 additions & 10 deletions admin/fees/class-delete-fee-action-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@

function awpcp_delete_fee_ajax_handler() {
return new AWPCP_TableEntryActionAjaxHandler(
new AWPCP_Delete_Fee_Action_Handler(
awpcp_fees_admin_page(),
awpcp_template_renderer(),
awpcp_request()
),
new AWPCP_Delete_Fee_Action_Handler(),
awpcp_ajax_response()
);
}

class AWPCP_Delete_Fee_Action_Handler implements AWPCP_Table_Entry_Action_Handler {

private $page;
private $template_renderer;
private $request;

public function __construct( $page, $template_renderer, $request ) {
$this->page = $page;
$this->template_renderer = $template_renderer;
$this->request = $request;
public function __construct() {
$this->page = awpcp_fees_admin_page();
$this->request = awpcp_request();
}

public function process_entry_action( $ajax_handler ) {
Expand Down
3 changes: 2 additions & 1 deletion admin/fees/class-fees-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public function transfer() {
$message = __( 'All Ads associated to Fee %1$s have been associated with Fee %2$s.', 'another-wordpress-classifieds-plugin' );
$message = sprintf( $message, '<strong>' . $fee->name . '</strong>', '<strong>' . $recipient->name . '</strong>' );
awpcp_flash( $message );
} else {
/** @phpstan-ignore-next-line */
} elseif ( ! empty( $errors ) ) {
foreach ( $errors as $error ) {
awpcp_flash( $error, 'error' );
}
Expand Down
23 changes: 7 additions & 16 deletions admin/form-fields/class-form-fields-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
* Constructor function for AWPCP_FormFieldsAdminPage.
*/
function awpcp_form_fields_admin_page() {
return new AWPCP_FormFieldsAdminPage(
'awpcp-form-fields',
awpcp_admin_page_title( __( 'Form Fields', 'another-wordpress-classifieds-plugin' ) ),
awpcp_listing_form_fields(),
awpcp_form_fields_table_factory()
);
return new AWPCP_FormFieldsAdminPage();
}

/**
Expand All @@ -25,27 +20,23 @@ class AWPCP_FormFieldsAdminPage extends AWPCP_AdminPageWithTable {
*/
private $form_fields;

/**
* @var AWPCP_FormFieldsTableFactory
*/
private $table_factory;

/**
* Constructor.
*/
public function __construct( $page, $title, $form_fields, $table_factory ) {
public function __construct() {
$page = 'awpcp-form-fields';
$title = awpcp_admin_page_title( __( 'Form Fields', 'another-wordpress-classifieds-plugin' ) );
parent::__construct( $page, $title, _x( 'Form Fields', 'sub menu title', 'another-wordpress-classifieds-plugin' ) );

$this->form_fields = $form_fields;
$this->table_factory = $table_factory;
$this->form_fields = awpcp_listing_form_fields();
}

/**
* Creates an instance of table used to render form fields rows.
*/
public function get_table() {
if ( ! isset( $this->table ) || is_null( $this->table ) ) {
$this->table = $this->table_factory->create_table( $this );
if ( empty( $this->table ) ) {
$this->table = new AWPCP_FormFieldsTable();
}

return $this->table;
Expand Down
15 changes: 3 additions & 12 deletions admin/form-fields/class-form-fields-table-factory.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
<?php

function awpcp_form_fields_table_factory() {
return new AWPCP_FormFieldsTableFactory( awpcp_request() );
}

class AWPCP_FormFieldsTableFactory {

private $request;

public function __construct( $request ) {
$this->request = $request;
}

public function create_table( $page ) {
return new AWPCP_FormFieldsTable( $page, $this->request );
public function create_table() {
_deprecated_function( __METHOD__, '4.3.4', 'AWPCP_FormFieldsTable' );
return new AWPCP_FormFieldsTable();
}
}
8 changes: 1 addition & 7 deletions admin/form-fields/class-form-fields-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@
*/
class AWPCP_FormFieldsTable extends WP_List_Table {

private $page;
private $request;

public function __construct( $page, $request ) {
public function __construct() {
parent::__construct( array( 'plural' => 'awpcp-form-fields-table' ) );

$this->page = $page;
$this->request = $request;
}

public function prepare( $items, $total_items ) {
Expand Down
4 changes: 1 addition & 3 deletions admin/import/class-csv-import-session.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
class AWPCP_CSV_Import_Session {

private $settings = array();
private $csv_importer = null;

public function __construct( $settings, $csv_importer ) {
public function __construct( $settings ) {
$this->settings = $settings;
$this->csv_importer = $csv_importer;
}

public function get_settings() {
Expand Down
12 changes: 1 addition & 11 deletions admin/import/class-csv-import-sessions-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@

class AWPCP_CSV_Import_Sessions_Manager {

private $csv_importer_factory;
private $csv_importer_delegate_factory;
private $csv_reader_factory;

public $settings;

private $wordpress;

public function __construct() {
$this->csv_importer_factory = new AWPCP_CSV_Importer_Factory();
$this->csv_importer_delegate_factory = awpcp()->container['ImporterDelegateFactory'];
$this->csv_reader_factory = new AWPCP_CSV_Reader_Factory();
$this->settings = awpcp()->settings;
$this->wordpress = new AWPCP_WordPress();
}

public function get_current_import_session() {
Expand Down Expand Up @@ -53,7 +43,7 @@ public function create_import_session( $settings = array() ) {

$settings['working_directory'] = $this->make_absolute_path( $settings['working_directory'] );

return new AWPCP_CSV_Import_Session( $settings, null );
return new AWPCP_CSV_Import_Session( $settings );
}

private function make_absolute_path( $relative_path ) {
Expand Down
16 changes: 0 additions & 16 deletions admin/import/class-csv-importer-delegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,22 +646,6 @@ private function create_empty_listing() {

return $this->listings_logic->create_listing( $listing_data );
}

private function get_extra_fields() {
if ( is_array( $this->extra_fields ) ) {
return $this->extra_fields;
}

$this->extra_fields = array();

if ( function_exists( 'awpcp_get_extra_fields' ) ) {
foreach ( awpcp_get_extra_fields() as $field ) {
$this->extra_fields[ $field->field_name ] = $field;
}
}

return $this->extra_fields;
}
}

/**
Expand Down
8 changes: 1 addition & 7 deletions admin/pointers/class-drip-autoresponder.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<?php

function awpcp_drip_autoresponder() {
return new AWPCP_DripAutoresponder( awpcp()->settings );
return new AWPCP_DripAutoresponder();
}

class AWPCP_DripAutoresponder {

private $settings;

public function __construct( $settings ) {
$this->settings = $settings;
}

public function register_pointer( $pointers ) {
$nonce = wp_create_nonce( 'drip-autoresponder' );

Expand Down
11 changes: 5 additions & 6 deletions admin/pointers/class-pointers-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @since 3.4
*/
function awpcp_pointers_manager() {
return new AWPCP_PointersManager( awpcp()->js, awpcp()->settings, awpcp_request() );
return new AWPCP_PointersManager();
}

/**
Expand All @@ -14,13 +14,12 @@ class AWPCP_PointersManager {

private $javascript;
private $settings;
private $request;

public function __construct( $javascript, $settings, $request ) {
$this->javascript = $javascript;
$this->settings = $settings;
$this->request = $request;
public function __construct() {
$this->javascript = awpcp()->js;
$this->settings = awpcp()->settings;
}

public function register_pointers() {
if ( $this->settings->get_option( 'show-drip-autoresponder' ) ) {
$drip_autoresponder = awpcp_drip_autoresponder();
Expand Down
Loading

0 comments on commit 1aeb950

Please sign in to comment.