Passed
Push — master ( 410349...4e2bae )
by litefeel
02:24
created

function.php ➔ wogh_is_dont_export_content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
/**
5
 * Append error
6
 * @param  mixed|WP_Error $error
7
 * @param  WP_Error   $error2
8
 * @return WP_Error
9
 */
10
function wogh_append_error( $error, $error2 ) {
11
    if ( is_wp_error( $error ) ) {
12
        $error->add( $error2->get_error_code(), $error2->get_error_message() );
13
    }
14
    return $error2;
15
}
16
17
/**
18
 * Test is equal front matter of post and blob
19
 * @param  Writing_On_GitHub_Post $post
20
 * @param  Writing_On_GitHub_Blob $blob
21
 * @return bool
22
 */
23
function wogh_equal_front_matter( $post, $blob ) {
24
    $str1 = $post->front_matter();
25
    $str2 = $blob->front_matter();
26
    return trim($str1) === trim($str2);
0 ignored issues
show
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...
27
}
28
29
/**
30
 * Check is dont export wordpress content
31
 * @return bool
32
 */
33
function wogh_is_dont_export_content() {
34
    return 'yes' === get_option( 'wogh_dont_export_content' );
35
}
36
37
/**
38
 * Calc git sha
39
 * https://git-scm.com/book/en/v2/Git-Internals-Git-Objects#_object_storage
40
 * @param  string $content
41
 * @return string
42
 */
43
function wogh_git_sha( $content ) {
44
    // $header = "blob $len\0"
45
    // sha1($header . $content)
46
    $len = strlen( $content );
47
    return sha1( "blob $len\0$content" );
48
}
49