Completed
Push — master ( 50ef2b...3bc0ea )
by Shcherbak
05:22
created

FileMessage::getLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
  namespace Funivan\Cs\Message;
4
5
  use Funivan\Cs\FileFinder\FileInfo;
6
  use Funivan\Cs\FileProcessor\FileTool;
7
8
  /**
9
   
10
   * @author Ivan Shcherbak <[email protected]> 2016
11
   */
12
  class FileMessage {
13
14
    const LEVEL_NOTICE = 0;
15
16
    const LEVEL_ERROR = 1;
17
18
    /**
19
     * @var int
20
     */
21
    private $level;
22
23
    /**
24
     * @var FileInfo
25
     */
26
    private $file;
27
28
    /**
29
     * @var string
30
     */
31
    private $text;
32
33
    /**
34
     * @var array
35
     */
36
    private static $levelMap = [
37
      self::LEVEL_NOTICE => 'notice',
38
      self::LEVEL_ERROR => 'error',
39
    ];
40
41
    /**
42
     * @var FileTool
43
     */
44
    private $tool;
45
46
    /**
47
     * @var int|null
48
     */
49
    private $line;
50
51
52
    /**
53
     * @param FileInfo $file
54
     * @param FileTool $tool
55
     * @param $text
56
     * @param int|null $line
57
     * @param int $level
58
     */
59 8
    public function __construct(FileInfo $file, FileTool $tool, $text, $line, $level = null) {
60
61 8
      $level = ($level !== null) ? $level : self::LEVEL_ERROR;
62
63 8
      if (!isset(self::$levelMap[$level])) {
64
        throw new \InvalidArgumentException('Invalid level');
65
      }
66
67 8
      $this->file = $file;
68 8
      $this->text = $text;
69 8
      $this->level = $level;
70 8
      $this->tool = $tool;
71 8
      $this->line = $line;
72 8
    }
73
74
75
    /**
76
     * @return string
77
     */
78
    public function getText() {
79
      return $this->text;
80
    }
81
82
83
    /**
84
     * @return FileInfo
85
     */
86
    public function getFile() {
87
      return $this->file;
88
    }
89
90
91
    /**
92
     * @return int|null
93
     */
94 3
    public function getLine() {
95 3
      return $this->line;
96
    }
97
98
99
    /**
100
     * @return int
101
     */
102
    public function getLevel() {
103
      return $this->level;
104
    }
105
106
107
    /**
108
     * @return string
109
     */
110
    public function getLevelName() {
111
      return self::$levelMap[$this->level];
112
    }
113
114
115
    /**
116
     * @return FileTool
117
     */
118
    public function getTool() {
119
      return $this->tool;
120
    }
121
122
123
    /**
124
     * @return string
125
     */
126
    public function getToolName() {
127
      return ucfirst(str_replace('_', ' ', $this->getTool()->getName()));
128
    }
129
130
  }