Completed
Push — master ( 2a84bd...8621a6 )
by Nicolaas
01:36
created

GeneralMethods::outputToScreen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
4
class GeneralMethods extends Object
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
7
8
    /**
9
     * opens a location with curl to see if it exists.
10
     *
11
     * @param string $url
12
     *
13
     * @return boolean
14
     */
15
    public static function check_location($url)
16
    {
17
        $handle = curl_init($url);
18
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
19
        curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, true);
20
        $response = curl_exec($handle);
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
        $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
22
        $outcome = $httpCode == 200;
23
        curl_close($handle);
24
        return $outcome;
25
    }
26
27
28
29
    /**
30
     *
31
     * @use
32
     * ```
33
     *    GeneralMethods::output_to_screen('asdf', 'created')
34
     * ```
35
     * @see DB::alteration_message for types...
36
     *
37
     * @param  string $message
38
     * @param  string $type
39
     */
40
    public static function output_to_screen($message, $type = "")
41
    {
42
        if(Director::is_cli()) {
43
            DB::alteration_message($message, $type);
44
        } else {
45
            echo "<br />";
46
            flush();
47
            ob_end_flush();
48
            DB::alteration_message($message, $type);
49
            ob_start();
50
51
        }
52
    }
53
54
    /*
55
     * Recursively removes a directory
56
     *
57
     * @param  string $path
58
     */
59
60
    public static function removeDirectory($path)
61
    {
62
        FileSystem::removeFolder($path);
63
    }
64
65
    /*
66
     * Replaces all instances of a string in a file, and rewrites the file
67
     *
68
     * @param string $fileName
69
     * @param string $search
70
     * @param string $replacement
71
     *
72
     **/
73
    public static function replaceInFile($fileName, $search, $replacement)
74
    {
75
        $file = fopen($fileName, 'r');
76
        if ($file) {
77
            $content = fread($file, filesize($fileName) * 2);
78
            $newContent = str_replace($search, $replacement, $content);
79
            fclose($file);
80
81
82
            $file = fopen($fileName, 'w');
83
            if ($file) {
84
                fwrite($file, $newContent);
85
                fclose($file);
86
            }
87
        }
88
    }
89
90
91
}
92