Skip to content

Commit

Permalink
Fix issues found by Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Feb 25, 2023
1 parent 787b47f commit eee1547
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inc/class-inputfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static function get_attributes( array $params ): string {
}

/**
* @psalm-param HelpArgs $args
* @psalm-param HelpArgs&mixed[] $args
*/
private static function render_help( array $args ): void {
if ( ! empty( $args['help'] ) ) {
Expand Down
10 changes: 10 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
resolveFromConfigFile="true"
phpVersion="7.4"
findUnusedPsalmSuppress="true"
findUnusedCode="true"
findUnusedBaselineEntry="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -13,7 +15,15 @@
<directory name="inc"/>
<directory name="views"/>
</projectFiles>
<issueHandlers>
<PossiblyUnusedReturnValue errorLevel="suppress"/>
<PossiblyUnusedMethod errorLevel="suppress"/>
<RedundantCast errorLevel="suppress"/>
<RedundantCastGivenDocblockType errorLevel="suppress"/>
<UnusedClass errorLevel="suppress"/>
</issueHandlers>
<stubs>
<file name="vendor/php-stubs/wordpress-stubs/wordpress-stubs.php"/>
<file name="wordpress.stubs"/>
</stubs>
</psalm>
50 changes: 50 additions & 0 deletions wordpress.stubs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace {
define( 'OBJECT', 'OBJECT' );
define( 'object', 'OBJECT' );
define( 'OBJECT_K', 'OBJECT_K' );
define( 'ARRAY_A', 'ARRAY_A' );
define( 'ARRAY_N', 'ARRAY_N' );

class wpdb {

/** @var string */
public $login_log_table = '';

/**
* @param string $query
* @param mixed $args
* @return string|null
*/
public function prepare( $query, ...$args ) {}
}

/**
* @param mixed $data Optional. Data to encode as JSON, then print and die. Default null.
* @param int $status_code Optional. The HTTP status code to output. Default null.
* @param int $options Optional. Options to be passed to json_encode(). Default 0.
* @psalm-return never-returns
*/
function wp_send_json_error( $data = null, $status_code = null, $options = 0 ) {}

/**
* @param mixed $response Variable (usually an array or object) to encode as JSON,
* then print and die.
* @param int $status_code Optional. The HTTP status code to output. Default null.
* @param int $options Optional. Options to be passed to json_encode(). Default 0.
* @psalm-return never-returns
*/
function wp_send_json( $response, $status_code = null, $options = 0 ) {}

/**
* @param string $id
* @param string $title
* @param callable $callback
* @param string $page
* @param string $section
* @psalm-param array{class?: string, label_for?: string, ...} $args
* @return void
*/
function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {}
}

0 comments on commit eee1547

Please sign in to comment.