Passed
Push — master ( 9a56a9...944433 )
by litefeel
04:14
created

wogh_equal_path()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
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
function wogh_equal_path( $post, $blob ) {
30
    $str1 = $post->github_path();
31
    $str2 = $blob->path();
32
    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...
33
}
34
35
/**
36
 * Check is dont export wordpress content
37
 * @return bool
38
 */
39
function wogh_is_dont_export_content() {
40
    return 'yes' === get_option( 'wogh_dont_export_content' );
41
}
42
43
/**
44
 * Calc git sha
45
 * https://git-scm.com/book/en/v2/Git-Internals-Git-Objects#_object_storage
46
 * @param  string $content
47
 * @return string
48
 */
49
function wogh_git_sha( $content ) {
50
    // $header = "blob $len\0"
51
    // sha1($header . $content)
52
    $len = strlen( $content );
53
    return sha1( "blob $len\0$content" );
54
}
55