1
|
|
|
<?php |
2
|
|
|
namespace JsonTable\Analyse; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Statistics information regarding the analysis. |
6
|
|
|
* |
7
|
|
|
* @package JSON table |
8
|
|
|
*/ |
9
|
|
|
class Statistics |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array Statistics relating to the file analysis. |
13
|
|
|
*/ |
14
|
|
|
protected static $statistics = [ |
15
|
|
|
'rows_with_errors' => [], |
16
|
|
|
'percent_rows_with_errors' => 0, |
17
|
|
|
'rows_analysed' => 0 |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Get the statistics about the file analysis. |
23
|
|
|
* |
24
|
|
|
* @return array The statistics. |
25
|
|
|
*/ |
26
|
10 |
|
public function getStatistics() |
27
|
|
|
{ |
28
|
10 |
|
$this->cleanErrorRow(); |
29
|
|
|
|
30
|
10 |
|
if (self::$statistics['rows_analysed'] > 0) { |
31
|
10 |
|
self::$statistics['percent_rows_with_errors'] = $this->getErrorRowPercent(); |
32
|
10 |
|
} |
33
|
|
|
|
34
|
10 |
|
return self::$statistics; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Add the row number of a row with an error to the analysis statistics. |
40
|
|
|
* |
41
|
|
|
* @param int $row_number The position of the row with the error in the CSV file. |
|
|
|
|
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
9 |
|
public function setErrorRow($rowNumber) |
46
|
|
|
{ |
47
|
9 |
|
self::$statistics['rows_with_errors'][] = $rowNumber; |
48
|
9 |
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Set the number of rows that have been analysed. |
53
|
|
|
* |
54
|
|
|
* @param int $rowsAnalysedCount The number of rows analysed. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
28 |
|
public function setRowsAnalysed($rowsAnalysedCount) |
59
|
|
|
{ |
60
|
28 |
|
self::$statistics['rows_analysed'] = $rowsAnalysedCount; |
61
|
28 |
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Clean the rows with errors statistic. |
66
|
|
|
* This removes duplicated records where the same row has had multiple errors. |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
10 |
|
private function cleanErrorRow() |
71
|
|
|
{ |
72
|
10 |
|
self::$statistics['rows_with_errors'] = array_unique(self::$statistics['rows_with_errors']); |
73
|
10 |
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the percentage of analysed rows that have had a error with them. |
78
|
|
|
* |
79
|
|
|
* @return int The percentage. |
80
|
|
|
*/ |
81
|
10 |
|
private function getErrorRowPercent() |
82
|
|
|
{ |
83
|
10 |
|
return round((count(self::$statistics['rows_with_errors']) / self::$statistics['rows_analysed']) * 100); |
84
|
|
|
} |
85
|
|
|
} |
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 methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.