1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ArjanSchouten\HtmlMinifier\Statistics; |
4
|
|
|
|
5
|
|
|
class Statistics implements StatisticsInterface |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var \ArjanSchouten\HtmlMinifier\Statistics\ReferencePoint[] |
9
|
|
|
*/ |
10
|
|
|
private $referencePoints; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Create statistics with the input before modification. |
14
|
|
|
* |
15
|
|
|
* @param string $input |
16
|
|
|
* @param string $keyName |
17
|
|
|
*/ |
18
|
5 |
|
public function __construct($input, $keyName = 'Original input') |
19
|
|
|
{ |
20
|
5 |
|
$this->referencePoints[$keyName] = new ReferencePoint($keyName, mb_strlen($input, '8bit')); |
21
|
5 |
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Add a step and measure the input size. |
25
|
|
|
* |
26
|
|
|
* @param int $inputSize |
27
|
|
|
* @param string $keyname |
|
|
|
|
28
|
|
|
* |
29
|
|
|
* @return \ArjanSchouten\HtmlMinifier\Statistics\ReferencePoint[] |
|
|
|
|
30
|
|
|
*/ |
31
|
4 |
|
public function createReferencePoint($inputSize, $keyname = null) |
32
|
|
|
{ |
33
|
4 |
|
if ($keyname === null) { |
34
|
|
|
$keyname = 'Step: '.(count($this->referencePoints) + 1); |
35
|
|
|
} |
36
|
|
|
|
37
|
4 |
|
if (!array_key_exists($keyname, $this->referencePoints)) { |
38
|
4 |
|
$this->referencePoints[$keyname] = new ReferencePoint($keyname, $inputSize); |
39
|
|
|
} else { |
40
|
|
|
$this->referencePoints[$keyname]->addBytes($inputSize); |
41
|
|
|
} |
42
|
|
|
|
43
|
4 |
|
return $this->referencePoints; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get all the steps which are measured. |
48
|
|
|
* |
49
|
|
|
* @return \ArjanSchouten\HtmlMinifier\Statistics\ReferencePoint[] |
50
|
|
|
*/ |
51
|
2 |
|
public function getReferencePoints() |
52
|
|
|
{ |
53
|
2 |
|
return $this->referencePoints; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the total saved bytes in bytes. |
58
|
|
|
* |
59
|
|
|
* @return int |
|
|
|
|
60
|
|
|
*/ |
61
|
1 |
|
public function getTotalSavedBytes() |
62
|
|
|
{ |
63
|
1 |
|
$initialStep = array_first($this->referencePoints); |
64
|
1 |
|
$lastStep = array_last($this->referencePoints); |
65
|
|
|
|
66
|
1 |
|
return $initialStep->getBytes() - $lastStep->getBytes(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.