1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ArjanSchouten\HtmlMinifier; |
4
|
|
|
|
5
|
|
|
use ArjanSchouten\HtmlMinifier\Statistics\Statistics; |
6
|
|
|
use ArjanSchouten\HtmlMinifier\Statistics\StatisticsInterface; |
7
|
|
|
|
8
|
|
|
class MinifyContext |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var \ArjanSchouten\HtmlMinifier\PlaceholderContainer |
12
|
|
|
*/ |
13
|
|
|
private $placeholderContainer; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $contents; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \ArjanSchouten\HtmlMinifier\Statistics\StatisticsInterface |
22
|
|
|
*/ |
23
|
|
|
private $statistics; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer |
27
|
|
|
*/ |
28
|
30 |
|
public function __construct(PlaceholderContainer $placeholderContainer, StatisticsInterface $statistics = null) |
29
|
|
|
{ |
30
|
30 |
|
$this->placeholderContainer = $placeholderContainer; |
31
|
30 |
|
$this->statistics = $statistics; |
32
|
30 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get the placeholdercontainer. |
36
|
|
|
* |
37
|
|
|
* @return \ArjanSchouten\HtmlMinifier\PlaceholderContainer |
38
|
|
|
*/ |
39
|
10 |
|
public function getPlaceholderContainer() |
40
|
|
|
{ |
41
|
10 |
|
return $this->placeholderContainer; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
30 |
|
public function getContents() |
48
|
|
|
{ |
49
|
30 |
|
return $this->contents; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $contents |
54
|
|
|
* |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
30 |
|
public function setContents($contents) |
58
|
|
|
{ |
59
|
30 |
|
$this->contents = $contents; |
60
|
|
|
|
61
|
30 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Add a minification step. |
66
|
|
|
* |
67
|
|
|
* @param string $input |
68
|
|
|
* @param string $keyName |
|
|
|
|
69
|
|
|
*/ |
70
|
3 |
|
public function addMinificationStep($input, $keyName = null) |
71
|
|
|
{ |
72
|
3 |
|
if ($this->statistics === null) { |
73
|
3 |
|
$this->statistics = new Statistics($input, $keyName); |
74
|
|
|
|
75
|
3 |
|
return; |
76
|
|
|
} |
77
|
|
|
|
78
|
3 |
|
$this->statistics->createReferencePoint($this->calculateInputLength($input), $keyName); |
79
|
3 |
|
} |
80
|
|
|
|
81
|
3 |
|
private function calculateInputLength($input) |
82
|
|
|
{ |
83
|
3 |
|
return mb_strlen($input, '8bit') + $this->placeholderContainer->getOriginalSize() - $this->placeholderContainer->getPlaceholderSize(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the minification statistics. |
88
|
|
|
* |
89
|
|
|
* @return \ArjanSchouten\HtmlMinifier\Statistics\StatisticsInterface |
90
|
|
|
*/ |
91
|
1 |
|
public function getStatistics() |
92
|
|
|
{ |
93
|
1 |
|
return $this->statistics; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.