tesark /
msg91-php
| 1 | <?php |
||||
| 2 | namespace Sender\Log; |
||||
| 3 | |||||
| 4 | use Monolog\Logger; |
||||
| 5 | use Monolog\Handler\StreamHandler; |
||||
| 6 | use Sender\ExceptionClass\ParameterException; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * This class for Log errors and store request and response status |
||||
| 10 | * |
||||
| 11 | * @package Msg91 SMS&OTP package |
||||
| 12 | * @author VenkatS <[email protected]> |
||||
| 13 | * @link https://github.com/tesark/msg91-php |
||||
| 14 | * @license MIT |
||||
| 15 | */ |
||||
| 16 | |||||
| 17 | class Log |
||||
| 18 | { |
||||
| 19 | private static $logger; |
||||
| 20 | private static $path; |
||||
| 21 | public function __construct($logIdentifier) |
||||
| 22 | { |
||||
| 23 | $log = isset($logIdentifier) ? $logIdentifier : 'PackageLog'; |
||||
| 24 | self::$logger = new Logger($log); |
||||
| 25 | self::$path = __DIR__; |
||||
| 26 | } |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * MSG91 Error log "ERROR" |
||||
| 30 | * @param error Array |
||||
| 31 | * |
||||
| 32 | */ |
||||
| 33 | public function error(...$error) |
||||
| 34 | { |
||||
| 35 | $error = array("ERROR" => $error); |
||||
| 36 | $dateTime = date_create('now')->format('Y-m-d'); |
||||
| 37 | self::$logger->pushHandler(new StreamHandler(self::$path.'/Logger'.'/Error_'.$dateTime.'.log', Logger::ERROR)); |
||||
| 38 | self::$logger->error("\r\n \n TRACE:", $error); |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | /** |
||||
| 42 | * MSG91 Error log "INFO" |
||||
| 43 | * @param info array |
||||
| 44 | * |
||||
| 45 | */ |
||||
| 46 | public function info(...$info) |
||||
| 47 | { |
||||
| 48 | $info = array('INFO' => $info); |
||||
| 49 | $dateTime = date_create('now')->format('Y-m-d'); |
||||
| 50 | self::$logger->pushHandler(new StreamHandler(self::$path.'/Logger'.'/Info_'.$dateTime.'.log', Logger::INFO)); |
||||
| 51 | self::$logger->info("\r\n \n TRACE:", $info); |
||||
| 52 | } |
||||
| 53 | /** |
||||
| 54 | * This function for Delete automatially with in 10 days old files |
||||
| 55 | * |
||||
| 56 | */ |
||||
| 57 | public function deleteOldFiles() |
||||
| 58 | { |
||||
| 59 | $path = self::$path.'/Logger'; |
||||
| 60 | if ($handle = opendir($path)) { |
||||
| 61 | while (false !== ($file = readdir($handle))) { |
||||
| 62 | if ($file!='.' && $file!='..'){ |
||||
| 63 | $filelastmodified = filemtime($path."/".$file); |
||||
| 64 | //10 days older files deleted |
||||
| 65 | if ((time()-$filelastmodified) > 240 * 3600) { |
||||
| 66 | $filepath = $path."/".$file; |
||||
| 67 | @unlink($filepath); |
||||
|
0 ignored issues
–
show
|
|||||
| 68 | } |
||||
| 69 | } } |
||||
| 70 | @closedir($handle); |
||||
|
0 ignored issues
–
show
It seems like you do not handle an error condition for
closedir(). This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Are you sure the usage of
closedir($handle) is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||
| 71 | if (@closedir($handle)) { |
||||
|
0 ignored issues
–
show
Are you sure the usage of
closedir($handle) is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||
| 72 | throw ParameterException::missinglogic('The directory could not be created.'); |
||||
| 73 | } |
||||
| 74 | } |
||||
| 75 | } |
||||
| 76 | } |
||||
| 77 |
If you suppress an error, we recommend checking for the error condition explicitly: