Completed
Pull Request — master (#139)
by
unknown
46:21 queued 21:17
created

helpers.php ➔ write_wpghs_link()   C

Complexity

Conditions 7
Paths 15

Size

Total Lines 48
Code Lines 37

Duplication

Lines 16
Ratio 33.33 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 7
eloc 37
c 2
b 0
f 2
nc 15
nop 1
dl 16
loc 48
ccs 0
cts 0
cp 0
crap 56
rs 6.7272
1
<?php
2
/**
3
 * Theme helper functions.
4
 *
5
 * @package WordPress_GitHub_SYnc
6
 */
7
8
/**
9
 * Returns the HTML markup to view the current post on GitHub.
10
 *
11
 * @return string
12
 */
13
function get_the_github_view_link() {
14 1
    return '<a href="' . get_the_github_view_url() . '">' . apply_filters( 'wpghs_view_link_text', 'View this post on GitHub.' ) . '</a>';
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
15
}
16
add_shortcode( 'get_the_github_view_link', 'get_the_github_view_link' );
17
18
/**
19
 * Returns the URL to view the current post on GitHub.
20
 *
21
 * @return string
22
 */
23 2
function get_the_github_view_url() {
24
    $wpghs_post = new WordPress_GitHub_Sync_Post( get_the_ID(), WordPress_GitHub_Sync::$instance->api() );
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
25 2
26
    return $wpghs_post->github_view_url();
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
27
}
28
add_shortcode( 'get_the_github_view_url', 'get_the_github_view_url' );
29
30
/**
31
 * Returns the HTML markup to edit the current post on GitHub.
32
 *
33
 * @return string
34 1
 */
35
function get_the_github_edit_link() {
36
    return '<a href="' . get_the_github_edit_url() . '">' . apply_filters( 'wpghs_edit_link_text', 'Edit this post on GitHub.' ) . '</a>';
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
37
}
38
add_shortcode( 'get_the_github_edit_link', 'get_the_github_edit_link' );
39
40
/**
41
 * Returns the URL to edit the current post on GitHub.
42
 *
43 2
 * @return string
44
 */
45 2
function get_the_github_edit_url() {
46
    $wpghs_post = new WordPress_GitHub_Sync_Post( get_the_ID(), WordPress_GitHub_Sync::$instance->api() );
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
47
48
    return $wpghs_post->github_edit_url();
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
49
}
50
add_shortcode( 'get_the_github_edit_url', 'get_the_github_edit_url' );
51
52
53
/**
54
 * EXAMPLE FROM https://codex.wordpress.org/Shortcode_API
55
 * // [bartag foo="foo-value"]
56
 * function bartag_func( $atts ) {
57
 *     $a = shortcode_atts( array(
58
 *         'foo' => 'something',
59
 *         'bar' => 'something else',
60
 *     ), $atts );
61
 * 
62
 *     return "foo = {$a['foo']}";
63
 * }
64
 * add_shortcode( 'bartag', 'bartag_func' );
65
 */
66
67
/**
68
 * Function with attributes
69
 *   - type: 'link' (default) to return a HTML anchor tag with text, or 'url' for bare URL.
70
 *   - target: 'view' (default) or 'edit' to return the respective link/url.
71
 *   - text: text to be included in the link. Ignored if type='url'.
72
 * 
73
 * Returns either a HTML formatted anchor tag or the bare URL of the current post on GitHub.
74
 *
75
 * @return string
76
 */
77
function write_wpghs_link( $atts ) {
78
79
    extract(shortcode_atts(array(
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
introduced by
extract() usage is highly discouraged, due to the complexity and unintended issues it might cause.
Loading history...
80
	"type" => 'link',
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal type does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 4.
Loading history...
81
	"target" => 'view',
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 4.
Loading history...
Coding Style Comprehensibility introduced by
The string literal target does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
82
	"text" => ''
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 4.
Loading history...
Coding Style Comprehensibility introduced by
The string literal text does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
introduced by
Each line in an array declaration must end in a comma
Loading history...
83
    ), $atts));
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
84
85
    $output = '';
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
86
87
    switch($target) {
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
88 View Code Duplication
        case 'view':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
89
	    $getter = get_the_github_view_url();
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 3 tabs, found 2
Loading history...
90
	    if(!empty($text)) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 3 tabs, found 2
Loading history...
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
91
		$linktext = $text;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 4 tabs, found 2
Loading history...
92
	    } else {
93
		$linktext = 'View this post on GitHub';
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 3 tabs, found 2
Loading history...
94
	    }
95
	    break;
96 View Code Duplication
        case 'edit':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
97
	    $getter = get_the_github_edit_url();
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 3 tabs, found 2
Loading history...
98
	    if(!empty($text)) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 3 tabs, found 2
Loading history...
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
99
		$linktext = $text;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 4 tabs, found 2
Loading history...
100
	    } else {
101
		$linktext = 'Edit this post on GitHub';
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 3 tabs, found 2
Loading history...
102
	    }
103
	    break;
104
	default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 2 tabs, found 1
Loading history...
105
	    $getter = get_the_github_view_url();
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 3 tabs, found 2
Loading history...
106
	    $linktext = 'View this post on GitHub';
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 3 tabs, found 2
Loading history...
107
	    break;
108
    }
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
109
110
    switch($type) {
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
111
	case 'link':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 2 tabs, found 1
Loading history...
112
	    $output .= '<a href="' . $getter . '">' . $linktext . '</a>';
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 3 tabs, found 2
Loading history...
113
	    break;
114
	case 'url':
115
	    $output .= $getter;
116
	    break;
117
	default:
118
	    $output .= '<a href="' . $getter . '">' . $linktext . '</a>';
119
	    break;
120
    }
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
121
122
    return $output;
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
123
124
}
125
add_shortcode( 'wpghs', 'write_wpghs_link' );
126