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
|
|
|
* @param \ArjanSchouten\HtmlMinifier\Statistics\StatisticsInterface|null $statistics |
28
|
|
|
*/ |
29
|
30 |
|
public function __construct(PlaceholderContainer $placeholderContainer, StatisticsInterface $statistics = null) |
30
|
|
|
{ |
31
|
30 |
|
$this->placeholderContainer = $placeholderContainer; |
32
|
30 |
|
$this->statistics = $statistics; |
33
|
30 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the placeholdercontainer. |
37
|
|
|
* |
38
|
|
|
* @return \ArjanSchouten\HtmlMinifier\PlaceholderContainer |
39
|
|
|
*/ |
40
|
10 |
|
public function getPlaceholderContainer() |
41
|
|
|
{ |
42
|
10 |
|
return $this->placeholderContainer; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
30 |
|
public function getContents() |
49
|
|
|
{ |
50
|
30 |
|
return $this->contents; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $contents |
55
|
|
|
* |
56
|
|
|
* @return $this |
57
|
|
|
*/ |
58
|
30 |
|
public function setContents($contents) |
59
|
|
|
{ |
60
|
30 |
|
$this->contents = $contents; |
61
|
|
|
|
62
|
30 |
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Add a minification step. |
67
|
|
|
* |
68
|
|
|
* @param string $input |
69
|
|
|
* @param string $keyName |
|
|
|
|
70
|
|
|
*/ |
71
|
3 |
|
public function addMinificationStep($input, $keyName = null) |
72
|
|
|
{ |
73
|
3 |
|
if ($this->statistics === null) { |
74
|
3 |
|
$this->statistics = new Statistics($input, $keyName); |
75
|
|
|
|
76
|
3 |
|
return; |
77
|
|
|
} |
78
|
|
|
|
79
|
3 |
|
$this->statistics->createReferencePoint($this->placeholderContainer->getContentSize($input), $keyName); |
80
|
3 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get the minification statistics. |
84
|
|
|
* |
85
|
|
|
* @return \ArjanSchouten\HtmlMinifier\Statistics\StatisticsInterface |
86
|
|
|
*/ |
87
|
1 |
|
public function getStatistics() |
88
|
|
|
{ |
89
|
1 |
|
return $this->statistics; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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.