UrlBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
ccs 0
cts 11
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get_public_url() 0 4 2
A get_json_resource_url() 0 3 1
1
<?php
2
3
/**
4
 * The dashboard-specific functionality of the plugin.
5
 *
6
 * @link       http://example.com
7
 * @since      1.0.0
8
 *
9
 * @package    PluginName
10
 * @subpackage PluginName/admin
11
 */
12
13
namespace logoscon\WP\RedmineEmbed\Redmine;
14
15
use logoscon\WP\RedmineEmbed\Plugin;
16
17
/**
18
 * The dashboard-specific functionality of the plugin.
19
 *
20
 * Defines the plugin name, version, and two examples hooks for how to
21
 * enqueue the dashboard-specific stylesheet and JavaScript.
22
 *
23
 * @package    PluginName
24
 * @subpackage PluginName/admin
25
 * @author     Your Name <[email protected]>
26
 */
27
class UrlBuilder {
28
29
    /**
30
     * The plugin's instance.
31
     *
32
     * @since  1.0.0
33
     * @access private
34
     * @var    Plugin $plugin This plugin's instance.
35
     */
36
    private $plugin;
37
38
    /**
39
     * Root URL for Redmine.
40
     * @access private
41
     * @var string
42
     */
43
    private $root_url = '';
44
45
    /**
46
     * Initialize the class and set its properties.
47
     *
48
     * @since 1.0.0
49
     *
50
     * @param Plugin $plugin This plugin's instance.
51
     */
52
    public function __construct( Plugin $plugin ) {
53
        $this->plugin   = $plugin;
54
        $this->root_url = \trailingslashit( $plugin->get_option( 'root_url', '' ) );
55
    }
56
57
    /**
58
     * Get a public resource link on Redmine.
59
     * @param  string  $resource Resource type.
60
     * @param  integer $id       Resource ID.
61
     * @param  string  $suffix   Suffix to append to the URL.
62
     * @return string            Public (frontend) resource link.
63
     */
64
    public function get_public_url( $resource = '', $id = 0, $suffix = '' ) {
65
        $path = $id ? sprintf( '%s/%d', $resource, $id ) : $resource;
66
        return $this->root_url . $path . $suffix;
67
    }
68
69
    /**
70
     * Get a REST API resource link on Redmine.
71
     * @param  string  $resource Resource type.
72
     * @param  integer $id       Resource ID.
73
     * @param  string  $suffix   Suffix to append to the URL.
74
     * @return string            REST API resource link.
75
     */
76
    public function get_json_resource_url( $resource = '', $id = 0, $suffix = '' ) {
77
        return $this->get_public_url( $resource, $id, $suffix ) . '.json';
78
    }
79
80
}
81