Passed
Pull Request — master (#236)
by Patrik
03:27
created

WPInv_Receipt_Widget   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 61
loc 61
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 31 31 1
A output() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
    exit;
4
}
5
6
/**
7
 * Invoice receipt widget.
8
 */
9 View Code Duplication
class WPInv_Receipt_Widget extends WP_Super_Duper {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
10
11
    /**
12
     * Register the widget with WordPress.
13
     *
14
     */
15
    public function __construct() {
16
17
18
        $options = array(
19
            'textdomain'    => 'invoicing',
20
            'block-icon'    => 'admin-site',
21
            'block-category'=> 'widgets',
22
            'block-keywords'=> "['invoicing','receipt']",
23
            'class_name'     => __CLASS__,
24
            'base_id'       => 'wpinv_receipt',
25
            'name'          => __('Invoicing > Invoice Receipt','invoicing'),
26
            'widget_ops'    => array(
27
                'classname'   => 'wpinv-receipt-class',
28
                'description' => esc_html__('Displays invoice receipt after checkout.','invoicing'),
29
            ),
30
            'arguments'     => array(
31
                'title'  => array(
32
                    'title'       => __( 'Widget title', 'invoicing' ),
33
                    'desc'        => __( 'Enter widget title.', 'invoicing' ),
34
                    'type'        => 'text',
35
                    'desc_tip'    => true,
36
                    'default'     => '',
37
                    'advanced'    => false
38
                ),
39
            )
40
41
        );
42
43
44
        parent::__construct( $options );
45
    }
46
47
	/**
48
	 * The Super block output function.
49
	 *
50
	 * @param array $args
51
	 * @param array $widget_args
52
	 * @param string $content
53
	 *
54
	 * @return mixed|string|bool
55
	 */
56
    public function output( $args = array(), $widget_args = array(), $content = '' ) {
57
58
	    ob_start();
59
60
	    do_action( 'wpinv_success_content_before' );
61
	    echo wpinv_payment_receipt( $args );
62
	    do_action( 'wpinv_success_content_after' );
63
64
	    $output = ob_get_clean();
65
	    return trim($output);
66
67
    }
68
69
}