Completed
Push — master ( eef885...465d0c )
by
unknown
30:08 queued 12:49
created

log_archive_class   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A construct() 0 1 1
A get_archive_file() 0 13 2
A check_need_rotate() 0 15 4
B rename_current_file() 0 23 5
1
<?php
2
3
namespace eoxia;
4
5
if ( !defined( 'ABSPATH' ) ) exit;
6
7
if ( ! class_exists( '\eoxia\log_archive_class' ) ) {
8
class log_archive_class extends \eoxia\Singleton_Util {
9
		protected function construct() {}
10
11
		public function get_archive_file( $name ) {
12
			// Get archive
13
			$upload_dir = wp_upload_dir();
14
			$dir_file = $upload_dir['basedir'] . '/wpeolog/';
15
			$array_glob_file = glob( $dir_file . $name . '*.csv' );
16
17
			foreach( $array_glob_file as &$glob_file ) {
18
				$glob_file = explode('/', $glob_file);
19
				$glob_file = $glob_file[count($glob_file) - 1];
20
			}
21
22
			return $array_glob_file;
23
		}
24
25
		/**
26
		* check_need_rotate  Checks if the file exceeds the maximum size
27
		*
28
		* @param string $file_link The file path to write
0 ignored issues
show
Bug introduced by
There is no parameter named $file_link. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
29
		*/
30
		public function check_need_rotate( $service, $name, $message ) {
31
			$upload_dir = wp_upload_dir();
32
			$max_size = $service['size'];
33
			$file_link = $upload_dir[ 'basedir' ] . '/wpeolog/' . $name . '.csv';
34
			if( file_exists( $file_link ) ) {
35
				// Get full message
36
				$message = file_get_contents( $file_link ) . $message;
37
				$file_size = filesize( $file_link );
38
				if($file_size >= $max_size)
39
					self::rename_current_file( $service, $name, $file_link );
40
				else if(strlen($message) >= $max_size)
41
					self::rename_current_file( $service, $name, $file_link );
42
				return $file_link;
43
			}
44
		}
45
		/**
46
		 * rename_current_file - Rename the current file
47
		 *
48
		 * @param string $service
49
		 * @param string $file_link
50
		 */
51
		public function rename_current_file( $service, $name, $file_link ) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
			$upload_dir = wp_upload_dir();
53
			$number_archive = $service['number'];
54
			if( file_exists ( $file_link ) ) {
55
				$file_explode = explode('.csv', $file_link);
56
				$get_all_file = glob($file_explode[0] . '*.csv');
57
				array_shift($get_all_file);
58
				arsort($get_all_file);
59
				foreach($get_all_file as $full_file) {
60
					$file = explode('/', $full_file);
61
					$file_name = $file[count($file) - 1];
62
					$file_name = explode('.', $file_name);
63
					$file_name[0]++;
64
					rename($full_file, $upload_dir[ 'basedir' ] . '/wpeolog/' . $file_name[0] . '.csv');
65
					// Check if not execeed the number archive
66
					$count = explode('_', $file_name[0]);
67
					if($count[1] > $number_archive && file_exists($upload_dir[ 'basedir' ] . '/wpeolog/' . $file_name[0] . '.csv')) {
68
						unlink($upload_dir[ 'basedir' ] . '/wpeolog/' . $file_name[0] . '.csv');
69
					}
70
				}
71
				rename( $file_link, $file_explode[0] . '_1.csv' );
72
			}
73
		}
74
	}
75
76
}
77
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
78