-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.php
More file actions
29 lines (26 loc) · 1.01 KB
/
Utility.php
File metadata and controls
29 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
// Utility functions for Secure Code Checker
// Function to log messages to a file
function logMessage($message, $logFile = 'checker.log') {
$timestamp = date('Y-m-d H:i:s');
// Error handling for file operations
if (file_put_contents($logFile, "[$timestamp] $message\n", FILE_APPEND) === false) {
// log to system error if file writing fails
error_log("Failed to write to log file: $logFile");
}
}
// Function to send notifications (e.g., to Slack or email)
function sendNotification($message) {
// Placeholder for notification implementation
logMessage("Notification sent: $message");
}
// Function to format report output with error handling
function formatReport($report) {
$jsonReport = json_encode($report, JSON_PRETTY_PRINT);
if ($jsonReport === false) {
// log an error if encoding fails
logMessage("Failed to format report: " . json_last_error_msg());
return json_encode(['error' => 'Failed to format report']);
}
return $jsonReport;
}