Debian Codegraph @

vendor/mck89/peast/lib/Peast/Formatter/Base.php

raw
1 <?php
2 /**
3 * This file is part of the Peast package
4 *
5 * (c) Marco Marchiò <[email protected]>
6 *
7 * For the full copyright and license information refer to the LICENSE file
8 * distributed with this source code
9 */
10 namespace Peast\Formatter;
11
12 /**
13 * Base class for formatters, all the formatters must extend this class.
14 *
15 * @author Marco Marchiò <[email protected]>
16 *
17 * @abstract
18 */
19 abstract class Base
20 {
21 /**
22 * New line character
23 *
24 * @var string
25 */
26 protected $newLine = "\n";
27
28 /**
29 * Indentation character
30 *
31 * @var string
32 */
33 protected $indentation = "\t";
34
35 /**
36 * Boolean that indicates if open curly brackets in code blocks must be
37 * on a new line
38 *
39 * @var bool
40 */
41 protected $newLineBeforeCurlyBracket = false;
42
43 /**
44 * Boolean that indicates if blocks of code must be wrapped in curly
45 * brackets also if they contain only one instruction
46 *
47 * @var bool
48 */
49 protected $alwaysWrapBlocks = true;
50
51 /**
52 * Boolean that indicates if operators must be surrounded by spaces
53 *
54 * @var bool
55 */
56 protected $spacesAroundOperators = true;
57
58 /**
59 * Boolean that indicates if content inside round brackets must be
60 * surrounded by spaces
61 *
62 * @var bool
63 */
64 protected $spacesInsideRoundBrackets = false;
65
66 /**
67 * Boolean that indicates if comments must be rendered
68 *
69 * @var bool
70 */
71 protected $renderComments = true;
72
73 /**
74 * Boolean that indicates if multiline documentation comments
75 * (for example JSDoc syntax) must be manipulated to match the
76 * right indentation
77 *
78 * @var bool
79 */
80 protected $recalcCommentsIndent = true;
81
82 /**
83 * Class constructor
84 *
85 * @param bool $renderComments True to render the comments if
86 * the parser has collected them
87 * and the formatter allows their
88 * rendering
89 */
90 public function __construct($renderComments = false)
91 {
92 if ($this->renderComments) {
93 $this->renderComments = $renderComments;
94 }
95 }
96
97 /**
98 * Returns the new line character
99 *
100 * @return string
101 */
102 public function getNewLine()
103 {
104 return $this->newLine;
105 }
106
107 /**
108 * Returns the indentation character
109 *
110 * @return string
111 */
112 public function getIndentation()
113 {
114 return $this->indentation;
115 }
116
117 /**
118 * Returns a boolean that indicates if open curly brackets in code blocks
119 * must be on a new line
120 *
121 * @return bool
122 */
123 public function getNewLineBeforeCurlyBracket()
124 {
125 return $this->newLineBeforeCurlyBracket;
126 }
127
128 /**
129 * Returns a boolean that indicates if blocks of code must be wrapped in
130 * curly brackets also if they contain only one instruction
131 *
132 * @return bool
133 */
134 public function getAlwaysWrapBlocks()
135 {
136 return $this->alwaysWrapBlocks;
137 }
138
139 /**
140 * Returns a boolean that indicates if operators must be surrounded by
141 * spaces
142 *
143 * @return bool
144 */
145 public function getSpacesAroundOperator()
146 {
147 return $this->spacesAroundOperators;
148 }
149
150 /**
151 * Returns a boolean that indicates if content inside round brackets must be
152 * surrounded by spaces
153 *
154 * @return bool
155 */
156 public function getSpacesInsideRoundBrackets()
157 {
158 return $this->spacesInsideRoundBrackets;
159 }
160
161 /**
162 * Returns a boolean that indicates if comments must be rendered
163 *
164 * @return bool
165 */
166 public function getRenderComments()
167 {
168 return $this->renderComments;
169 }
170
171 /**
172 * Returns a boolean that indicates if multiline documentation comments
173 * (for example JSDoc syntax) must be manipulated to match the
174 * right indentation
175 *
176 * @return bool
177 */
178 public function getRecalcCommentsIndent()
179 {
180 return $this->recalcCommentsIndent;
181 }
182 }