Skip to content

Commit

Permalink
Update parser in readme check
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Feb 26, 2025
1 parent ad55d6a commit 1bf67db
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
use WordPress\Plugin_Check\Traits\License_Utils;
use WordPress\Plugin_Check\Traits\Stable_Check;
use WordPress\Plugin_Check\Traits\Version_Utils;
use WordPressdotorg\Plugin_Directory\Readme\Parser;
use WordPress\Plugin_Check\Vendor\WordPressdotorg\Plugin_Directory\Readme\Parser as PrefixedParser;
use WordPressdotorg\Plugin_Directory\Readme\Parser as DotorgParser;

/**
* Check the plugins readme file and contents.
Expand Down Expand Up @@ -83,7 +84,7 @@ protected function check_files( Check_Result $result, array $files ) {

$readme_file = reset( $readme );

$parser = new Parser( $readme_file );
$parser = class_exists( DotorgParser::class ) ? new DotorgParser( $readme_file ) : new PrefixedParser( $readme_file );

// Check the readme file for plugin name.
$this->check_name( $result, $readme_file, $parser );

Check failure on line 90 in includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

View workflow job for this annotation

GitHub Actions / PHP

Parameter #3 $parser of method WordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Plugin_Readme_Check::check_name() expects WordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Parser, WordPress\Plugin_Check\Vendor\WordPressdotorg\Plugin_Directory\Readme\Parser|WordPressdotorg\Plugin_Directory\Readme\Parser given.
Expand Down Expand Up @@ -125,7 +126,7 @@ protected function check_files( Check_Result $result, array $files ) {
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_name( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_name( Check_Result $result, string $readme_file, $parser ) {

Check failure on line 129 in includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

View workflow job for this annotation

GitHub Actions / PHP

Parameter $parser of method WordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Plugin_Readme_Check::check_name() has invalid type WordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Parser.
if ( isset( $parser->warnings['invalid_plugin_name_header'] ) && false === $parser->name ) {
$this->add_result_error_for_file(
$result,
Expand Down Expand Up @@ -192,7 +193,7 @@ private function check_name( Check_Result $result, string $readme_file, Parser $
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_headers( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_headers( Check_Result $result, string $readme_file, $parser ) {
$ignored_warnings = $this->get_ignored_warnings( $parser );

$fields = array(
Expand Down Expand Up @@ -283,7 +284,7 @@ private function check_headers( Check_Result $result, string $readme_file, Parse
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_default_text( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_default_text( Check_Result $result, string $readme_file, $parser ) {
$short_description = $parser->short_description;
$tags = $parser->tags;
$donate_link = $parser->donate_link;
Expand Down Expand Up @@ -315,7 +316,7 @@ private function check_default_text( Check_Result $result, string $readme_file,
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_license( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_license( Check_Result $result, string $readme_file, $parser ) {
$license = $parser->license;
$matches_license = array();
$plugin_main_file = $result->plugin()->main_file();
Expand Down Expand Up @@ -389,7 +390,7 @@ private function check_license( Check_Result $result, string $readme_file, Parse
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_stable_tag( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_stable_tag( Check_Result $result, string $readme_file, $parser ) {
$stable_tag = $parser->stable_tag;

if ( empty( $stable_tag ) ) {
Expand Down Expand Up @@ -468,7 +469,7 @@ private function check_stable_tag( Check_Result $result, string $readme_file, Pa
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_upgrade_notice( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_upgrade_notice( Check_Result $result, string $readme_file, $parser ) {
$notices = $parser->upgrade_notice;

$maximum_characters = 300;
Expand Down Expand Up @@ -504,7 +505,7 @@ private function check_upgrade_notice( Check_Result $result, string $readme_file
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function check_for_warnings( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_for_warnings( Check_Result $result, string $readme_file, $parser ) {
$warnings = $parser->warnings ? $parser->warnings : array();

// This should be ERROR rather than WARNING. So ignoring here to handle separately.
Expand Down Expand Up @@ -646,7 +647,7 @@ private function check_for_warnings( Check_Result $result, string $readme_file,
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_for_donate_link( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_for_donate_link( Check_Result $result, string $readme_file, $parser ) {
$donate_link = $parser->donate_link;

// Bail if empty donate link.
Expand Down Expand Up @@ -800,7 +801,7 @@ function ( $value ) {
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_requires_headers( Check_Result $result, string $readme_file, Parser $parser ) {
private function check_requires_headers( Check_Result $result, string $readme_file, $parser ) {
$ignored_warnings = $this->get_ignored_warnings( $parser );

$found_warnings = $parser->warnings ? $parser->warnings : array();
Expand Down Expand Up @@ -861,7 +862,7 @@ private function check_requires_headers( Check_Result $result, string $readme_fi
* @param Parser $parser The Parser object.
* @return array Ignored warnings.
*/
private function get_ignored_warnings( Parser $parser ) {
private function get_ignored_warnings( $parser ) {
$ignored_warnings = array(
'contributor_ignored',
);
Expand Down

0 comments on commit 1bf67db

Please sign in to comment.