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

CSV_Util   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A construct() 0 1 1
C read_and_set_index() 0 22 7
1
<?php
2
/**
3
 * Gestion des fichiers CSV
4
 *
5
 * @package Evarisk\Plugin
6
 */
7
8
namespace eoxia;
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit;
12
}
13
14
if ( ! class_exists( '\eoxia\CSV_Util' ) ) {
15
	/**
16
	 * Gestion des fichiers CSV
17
	 *
18
	 * @author Jimmy Latour <[email protected]>
19
	 * @version 1.1.0.0
20
	 */
21
	class CSV_Util extends \eoxia\Singleton_Util {
22
		/**
23
		 * Le constructeur obligatoirement pour utiliser la classe \eoxia\Singleton_Util
24
		 *
25
		 * @return void nothing
26
		 */
27
		protected function construct() {}
28
29
		/**
30
		 * Lit un fichier CSV et forme un tableau 2D selon $list_index
31
		 *
32
		 * @param string $csv_path   Le chemin vers le fichier .csv.
33
		 * @param array  $list_index Les index personnalisés.
34
		 * @return array 						 Le tableau 2D avec les données du csv
35
		 */
36
		public function read_and_set_index( $csv_path, $list_index = array() ) {
37
			if ( empty( $csv_path ) ) {
38
				return false;
39
			}
40
41
			$data = array();
42
			$csv_content = file( $csv_path );
43
			if ( ! empty( $csv_content ) ) {
44
				foreach ( $csv_content as $key => $line ) {
45
					if ( 0 !== $key ) {
46
						$data[ $key ] = str_getcsv( $line );
47
						foreach ( $data[ $key ] as $i => $entry ) {
48
							if ( ! empty( $list_index[ $i ] ) ) {
49
								$data[ $key ][ $list_index[ $i ] ] = $entry;
50
							}
51
						}
52
					}
53
				}
54
			}
55
56
			return $data;
57
		}
58
	}
59
} // End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60