Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Conversation Block. |
||
| 4 | * |
||
| 5 | * @since 9.3.0 |
||
| 6 | * |
||
| 7 | * @package Jetpack |
||
| 8 | */ |
||
| 9 | |||
| 10 | namespace Automattic\Jetpack\Extensions\Conversation; |
||
| 11 | |||
| 12 | use Automattic\Jetpack\Blocks; |
||
| 13 | use Jetpack_Gutenberg; |
||
| 14 | |||
| 15 | const FEATURE_NAME = 'conversation'; |
||
| 16 | const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Registers the block for use in Gutenberg |
||
| 20 | * This is done via an action so that we can disable |
||
| 21 | * registration if we need to. |
||
| 22 | */ |
||
| 23 | View Code Duplication | function register_block() { |
|
|
0 ignored issues
–
show
|
|||
| 24 | $deprecated = function_exists( 'gutenberg_get_post_from_context' ); |
||
| 25 | $provides = $deprecated ? 'providesContext' : 'provides_context'; |
||
| 26 | |||
| 27 | Blocks::jetpack_register_block( |
||
| 28 | BLOCK_NAME, |
||
| 29 | array( |
||
| 30 | 'render_callback' => __NAMESPACE__ . '\render_block', |
||
| 31 | $provides => array( |
||
| 32 | 'jetpack/conversation-participants' => 'participants', |
||
| 33 | 'jetpack/conversation-showTimestamps' => 'showTimestamps', |
||
| 34 | ), |
||
| 35 | ) |
||
| 36 | ); |
||
| 37 | } |
||
| 38 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Conversation block registration/dependency declaration. |
||
| 42 | * |
||
| 43 | * @param array $attr Array containing the Conversation block attributes. |
||
| 44 | * @param string $content String containing the Conversation block content. |
||
| 45 | * |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | function render_block( $attr, $content ) { |
||
| 49 | Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); |
||
| 50 | return $content; |
||
| 51 | } |
||
| 52 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.