~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to src/lint/ArcanistLintMessage.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-11-01 23:20:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20141101232006-mvlnp0cil67tsboe
Tags: upstream-0~git20141101/arcanist
Import upstream version 0~git20141101, component arcanist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Message emitted by a linter, like an error or warning.
 
5
 */
 
6
final class ArcanistLintMessage {
 
7
 
 
8
  protected $path;
 
9
  protected $line;
 
10
  protected $char;
 
11
  protected $code;
 
12
  protected $severity;
 
13
  protected $name;
 
14
  protected $description;
 
15
  protected $originalText;
 
16
  protected $replacementText;
 
17
  protected $appliedToDisk;
 
18
  protected $dependentMessages = array();
 
19
  protected $otherLocations = array();
 
20
  protected $obsolete;
 
21
  protected $granularity;
 
22
  protected $bypassChangedLineFiltering;
 
23
 
 
24
  public static function newFromDictionary(array $dict) {
 
25
    $message = new ArcanistLintMessage();
 
26
 
 
27
    $message->setPath($dict['path']);
 
28
    $message->setLine($dict['line']);
 
29
    $message->setChar($dict['char']);
 
30
    $message->setCode($dict['code']);
 
31
    $message->setSeverity($dict['severity']);
 
32
    $message->setName($dict['name']);
 
33
    $message->setDescription($dict['description']);
 
34
    if (isset($dict['original'])) {
 
35
      $message->setOriginalText($dict['original']);
 
36
    }
 
37
    if (isset($dict['replacement'])) {
 
38
      $message->setReplacementText($dict['replacement']);
 
39
    }
 
40
    $message->setGranularity(idx($dict, 'granularity'));
 
41
    $message->setOtherLocations(idx($dict, 'locations', array()));
 
42
    if (isset($dict['bypassChangedLineFiltering'])) {
 
43
      $message->bypassChangedLineFiltering($dict['bypassChangedLineFiltering']);
 
44
    }
 
45
    return $message;
 
46
  }
 
47
 
 
48
  public function toDictionary() {
 
49
    return array(
 
50
      'path'        => $this->getPath(),
 
51
      'line'        => $this->getLine(),
 
52
      'char'        => $this->getChar(),
 
53
      'code'        => $this->getCode(),
 
54
      'severity'    => $this->getSeverity(),
 
55
      'name'        => $this->getName(),
 
56
      'description' => $this->getDescription(),
 
57
      'original'    => $this->getOriginalText(),
 
58
      'replacement' => $this->getReplacementText(),
 
59
      'granularity' => $this->getGranularity(),
 
60
      'locations'   => $this->getOtherLocations(),
 
61
      'bypassChangedLineFiltering' => $this->shouldBypassChangedLineFiltering(),
 
62
    );
 
63
  }
 
64
 
 
65
  public function setPath($path) {
 
66
    $this->path = $path;
 
67
    return $this;
 
68
  }
 
69
 
 
70
  public function getPath() {
 
71
    return $this->path;
 
72
  }
 
73
 
 
74
  public function setLine($line) {
 
75
    $this->line = $line;
 
76
    return $this;
 
77
  }
 
78
 
 
79
  public function getLine() {
 
80
    return $this->line;
 
81
  }
 
82
 
 
83
  public function setChar($char) {
 
84
    $this->char = $char;
 
85
    return $this;
 
86
  }
 
87
 
 
88
  public function getChar() {
 
89
    return $this->char;
 
90
  }
 
91
 
 
92
  public function setCode($code) {
 
93
    $this->code = $code;
 
94
    return $this;
 
95
  }
 
96
 
 
97
  public function getCode() {
 
98
    return $this->code;
 
99
  }
 
100
 
 
101
  public function setSeverity($severity) {
 
102
    $this->severity = $severity;
 
103
    return $this;
 
104
  }
 
105
 
 
106
  public function getSeverity() {
 
107
    return $this->severity;
 
108
  }
 
109
 
 
110
  public function setName($name) {
 
111
    $this->name = $name;
 
112
    return $this;
 
113
  }
 
114
 
 
115
  public function getName() {
 
116
    return $this->name;
 
117
  }
 
118
 
 
119
  public function setDescription($description) {
 
120
    $this->description = $description;
 
121
    return $this;
 
122
  }
 
123
 
 
124
  public function getDescription() {
 
125
    return $this->description;
 
126
  }
 
127
 
 
128
  public function setOriginalText($original) {
 
129
    $this->originalText = $original;
 
130
    return $this;
 
131
  }
 
132
 
 
133
  public function getOriginalText() {
 
134
    return $this->originalText;
 
135
  }
 
136
 
 
137
  public function setReplacementText($replacement) {
 
138
    $this->replacementText = $replacement;
 
139
    return $this;
 
140
  }
 
141
 
 
142
  public function getReplacementText() {
 
143
    return $this->replacementText;
 
144
  }
 
145
 
 
146
  /**
 
147
   * @param dict Keys 'path', 'line', 'char', 'original'.
 
148
   */
 
149
  public function setOtherLocations(array $locations) {
 
150
    assert_instances_of($locations, 'array');
 
151
    $this->otherLocations = $locations;
 
152
    return $this;
 
153
  }
 
154
 
 
155
  public function getOtherLocations() {
 
156
    return $this->otherLocations;
 
157
  }
 
158
 
 
159
  public function isError() {
 
160
    return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_ERROR;
 
161
  }
 
162
 
 
163
  public function isWarning() {
 
164
    return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_WARNING;
 
165
  }
 
166
 
 
167
  public function isAutofix() {
 
168
    return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_AUTOFIX;
 
169
  }
 
170
 
 
171
  public function hasFileContext() {
 
172
    return ($this->getLine() !== null);
 
173
  }
 
174
 
 
175
  public function setObsolete($obsolete) {
 
176
    $this->obsolete = $obsolete;
 
177
    return $this;
 
178
  }
 
179
 
 
180
  public function getObsolete() {
 
181
    return $this->obsolete;
 
182
  }
 
183
 
 
184
  public function isPatchable() {
 
185
    return ($this->getReplacementText() !== null) &&
 
186
           ($this->getReplacementText() !== $this->getOriginalText());
 
187
  }
 
188
 
 
189
  public function didApplyPatch() {
 
190
    if ($this->appliedToDisk) {
 
191
      return $this;
 
192
    }
 
193
    $this->appliedToDisk = true;
 
194
    foreach ($this->dependentMessages as $message) {
 
195
      $message->didApplyPatch();
 
196
    }
 
197
    return $this;
 
198
  }
 
199
 
 
200
  public function isPatchApplied() {
 
201
    return $this->appliedToDisk;
 
202
  }
 
203
 
 
204
  public function setGranularity($granularity) {
 
205
    $this->granularity = $granularity;
 
206
    return $this;
 
207
  }
 
208
 
 
209
  public function getGranularity() {
 
210
    return $this->granularity;
 
211
  }
 
212
 
 
213
  public function setDependentMessages(array $messages) {
 
214
    assert_instances_of($messages, 'ArcanistLintMessage');
 
215
    $this->dependentMessages = $messages;
 
216
    return $this;
 
217
  }
 
218
 
 
219
  public function setBypassChangedLineFiltering($bypass_changed_lines) {
 
220
    $this->bypassChangedLineFiltering = $bypass_changed_lines;
 
221
    return $this;
 
222
  }
 
223
 
 
224
  public function shouldBypassChangedLineFiltering() {
 
225
    return $this->bypassChangedLineFiltering;
 
226
  }
 
227
 
 
228
}