-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWarning.php
More file actions
108 lines (98 loc) · 2.56 KB
/
Warning.php
File metadata and controls
108 lines (98 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace PostCSS;
/**
* Represents a plugin's warning. It can be created using Node->warn.
*
* @link https://github.com/postcss/postcss/blob/master/lib/warning.es6
*
* @example
* if ($decl->important ) {
* $decl->warn($result, 'Avoid !important', ['word' => '!important']);
* }
*/
class Warning
{
/**
* The warning message.
*
* @var string
*/
public $text;
/**
* Line in the input file with this warning's source.
*
* @var int|null
*/
public $line = null;
/**
* Column in the input file with this warning's source.
*
* @var int|null
*/
public $column = null;
/**
* Contains the CSS node that caused the warning.
*
* @var Node|null
*/
public $node = null;
/**
* The name of the plugin that created it will fill this property automatically when you call Node->warn.
*
* @var string|null
*/
public $plugin = null;
/**
* Index in CSS node string that caused the warning.
*
* @var int|null
*/
public $index = null;
/**
* Word in CSS source that caused the warning.
*
* @var string|null
*/
public $word = null;
/**
* @param string $text Warning message
* @param array $opts Warning options. {
*
* @var Node $node CSS node that caused the warning
* @var string $word Word in CSS source that caused the warning
* @var int $index Index in CSS node string that caused the warning
* @var string $plugin Name of the plugin that created this warning. Result->warn fills this property automatically.
* }
*/
public function __construct($text, array $opts = [])
{
$this->text = (string) $text;
if (isset($opts['node']) && isset($opts['node']->source)) {
$pos = $opts['node']->positionBy($opts);
$this->line = $pos['line'];
$this->column = $pos['column'];
}
foreach ($opts as $k => $v) {
$this->$k = $v;
}
}
/**
* Returns a warning position and message.
*
* @return string
*/
public function __toString()
{
if (isset($this->node)) {
return $this->node->error($this->text, [
'plugin' => $this->plugin,
'index' => $this->index,
'word' => $this->word,
])->getMessage();
} elseif ($this->plugin) {
return ((string) $this->plugin).': '.$this->text;
} else {
return $this->text;
}
}
}