Completed
Branch FET/11400/gutenberg-block-mana... (002e7d)
by
unknown
13:10
created

TicketSelector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 81
loc 81
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 5 5 1
A registerBlock() 15 15 1
A getEditorContainer() 7 7 1
A registerScripts() 3 3 1
A registerStyles() 3 3 1
A renderBlock() 4 4 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
3
namespace EventEspresso\core\domain\entities\editor\blocks;
4
5
use EventEspresso\core\domain\entities\editor\EditorBlock;
6
use WP_Block_Type;
7
8
defined('EVENT_ESPRESSO_VERSION') || exit;
9
10
11
12
/**
13
 * Class TicketSelector
14
 * Description
15
 *
16
 * @package EventEspresso\core\domain\entities\editor\blocks
17
 * @author  Brent Christensen
18
 * @since   $VID:$
19
 */
20 View Code Duplication
class TicketSelector extends EditorBlock
21
{
22
23
    const EDITOR_BLOCK_TYPE = 'ee-event-editor/ticket-editor-container';
24
25
26
    /**
27
     * Perform any early setup required by the block
28
     * including setting the block type and supported post types
29
     *
30
     * @return void
31
     */
32
    public function initialize()
33
    {
34
        $this->setEditorBlockType(TicketSelector::EDITOR_BLOCK_TYPE);
35
        $this->setSupportedPostTypes(array('espresso_events'));
36
    }
37
38
39
    /**
40
     * Registers the Editor Block with WP core;
41
     * Returns the registered block type on success, or false on failure.
42
     *
43
     * @return WP_Block_Type|false
44
     */
45
    public function registerBlock()
46
    {
47
        $wp_block_type = register_block_type(
48
            new WP_Block_Type(
49
                $this->editorBlockType(),
50
                array(
51
                    'editor_script' => 'ee-event-editor-blocks',
52
                    'editor_style'  => 'ee-block-styles',
53
                    'attributes'    => array(),
54
                )
55
            )
56
        );
57
        $this->setWpBlockType($wp_block_type);
58
        return $wp_block_type;
59
    }
60
61
62
    /**
63
     * @return array
64
     */
65
    public function getEditorContainer()
66
    {
67
        return array(
68
            $this->editorBlockType(),
69
            array()
70
        );
71
    }
72
73
74
    /**
75
     * @return  void
76
     */
77
    public function registerScripts()
78
    {
79
    }
80
81
82
    /**
83
     * @return void
84
     */
85
    public function registerStyles()
86
    {
87
    }
88
89
90
    /**
91
     * returns the rendered HTML for the block
92
     *
93
     * @param array $attributes
94
     * @return string
95
     */
96
    public function renderBlock(array $attributes = array())
97
    {
98
        return '';
99
    }
100
}
101