1<?php
2
3/**
4 * A group of @{class:ArcanistLintMessage}s that apply to a file.
5 */
6final class ArcanistLintResult extends Phobject {
7
8  protected $path;
9  protected $data;
10  protected $filePathOnDisk;
11  protected $cacheVersion;
12  protected $messages = array();
13  protected $effectiveMessages = array();
14  private $needsSort;
15
16  public function setPath($path) {
17    $this->path = $path;
18    return $this;
19  }
20
21  public function getPath() {
22    return $this->path;
23  }
24
25  public function addMessage(ArcanistLintMessage $message) {
26    $this->messages[] = $message;
27    $this->needsSort = true;
28    return $this;
29  }
30
31  public function getMessages() {
32    if ($this->needsSort) {
33      $this->sortAndFilterMessages();
34    }
35    return $this->effectiveMessages;
36  }
37
38  public function setData($data) {
39    $this->data = $data;
40    return $this;
41  }
42
43  public function getData() {
44    return $this->data;
45  }
46
47  public function setFilePathOnDisk($file_path_on_disk) {
48    $this->filePathOnDisk = $file_path_on_disk;
49    return $this;
50  }
51
52  public function getFilePathOnDisk() {
53    return $this->filePathOnDisk;
54  }
55
56  public function setCacheVersion($version) {
57    $this->cacheVersion = $version;
58    return $this;
59  }
60
61  public function getCacheVersion() {
62    return $this->cacheVersion;
63  }
64
65  public function isPatchable() {
66    foreach ($this->messages as $message) {
67      if ($message->isPatchable()) {
68        return true;
69      }
70    }
71    return false;
72  }
73
74  public function isAllAutofix() {
75    foreach ($this->messages as $message) {
76      if (!$message->isAutofix()) {
77        return false;
78      }
79    }
80    return true;
81  }
82
83  public function sortAndFilterMessages() {
84    $messages = $this->messages;
85
86    foreach ($messages as $key => $message) {
87      if ($message->getObsolete()) {
88        unset($messages[$key]);
89        continue;
90      }
91    }
92
93    $map = array();
94    foreach ($messages as $key => $message) {
95      $map[$key] = ($message->getLine() * (2 << 12)) + $message->getChar();
96    }
97    asort($map);
98    $messages = array_select_keys($messages, array_keys($map));
99
100    $this->effectiveMessages = $messages;
101    $this->needsSort = false;
102  }
103
104}
105