Skip to content

Commit

Permalink
Add trait for check name
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Jan 9, 2024
1 parent cf35624 commit 728aff3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions includes/Checker/Check_Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function add_message( $error, $message, $args = array() ) {
'line' => 0,
'column' => 0,
'link' => '',
'check' => '',
);

$data = array_merge(
Expand Down
2 changes: 2 additions & 0 deletions includes/Traits/Amend_Check_Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
trait Amend_Check_Result {

use Check_Name;
use File_Editor_URL;

/**
Expand All @@ -41,6 +42,7 @@ protected function add_result_message_for_file( Check_Result $result, $error, $m
'line' => $line,
'column' => $column,
'link' => $this->get_file_editor_url( $result, $file, $line ),
'check' => $this->get_name(),
)
);
}
Expand Down
33 changes: 33 additions & 0 deletions includes/Traits/Check_Name.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Trait WordPress\Plugin_Check\Checker\Check_Name
*
* @package plugin-check
*/

namespace WordPress\Plugin_Check\Traits;

use ReflectionClass;

/**
* Trait for checks name.
*
* @since n.e.x.t
*/
trait Check_Name {
/**
* Returns the checks name.
*
* @since n.e.x.t
*
* @return string Check name.
*/
public function get_name() {
$reflection = new ReflectionClass( $this );

$class_name = strtolower( $reflection->getShortName() );
$class_name = str_replace( '_check', '', $class_name );

return $class_name;
}
}

0 comments on commit 728aff3

Please sign in to comment.