sunnysideup /
silverstripe-modulechecks
| 1 | <?php |
||||
| 2 | |||||
| 3 | |||||
| 4 | class GeneralMethods extends Object |
||||
| 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); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 19 | curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, true); |
||||
| 20 | $response = curl_exec($handle); |
||||
|
0 ignored issues
–
show
It seems like
$handle can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 21 | $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
||||
|
0 ignored issues
–
show
It seems like
$handle can also be of type false; however, parameter $ch of curl_getinfo() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 22 | $outcome = $httpCode == 200; |
||||
| 23 | curl_close($handle); |
||||
|
0 ignored issues
–
show
It seems like
$handle can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 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 | * Recursively removes a directory |
||||
| 55 | * |
||||
| 56 | * @param string $path |
||||
| 57 | */ |
||||
| 58 | |||||
| 59 | public static function removeDirectory($path) |
||||
| 60 | { |
||||
| 61 | FileSystem::removeFolder($path); |
||||
| 62 | } |
||||
| 63 | |||||
| 64 | /* |
||||
| 65 | * Replaces all instances of a string in a file, and rewrites the file |
||||
| 66 | * |
||||
| 67 | * @param string $fileName |
||||
| 68 | * @param string $search |
||||
| 69 | * @param string $replacement |
||||
| 70 | * |
||||
| 71 | **/ |
||||
| 72 | public static function replaceInFile($fileName, $search, $replacement) |
||||
| 73 | { |
||||
| 74 | $file = fopen($fileName, 'r'); |
||||
| 75 | if ($file) { |
||||
|
0 ignored issues
–
show
|
|||||
| 76 | $content = fread($file, filesize($fileName) * 2); |
||||
| 77 | $newContent = str_replace($search, $replacement, $content); |
||||
| 78 | fclose($file); |
||||
| 79 | |||||
| 80 | |||||
| 81 | $file = fopen($fileName, 'w'); |
||||
| 82 | if ($file) { |
||||
| 83 | fwrite($file, $newContent); |
||||
| 84 | fclose($file); |
||||
| 85 | } |
||||
| 86 | } |
||||
| 87 | } |
||||
| 88 | } |
||||
| 89 |