44
55class Cli
66{
7- private static $ SCRIPT_NAME = 'php-css-lint ' ;
8- private static $ RETURN_CODE_ERROR = 1 ;
9- private static $ RETURN_CODE_SUCCESS = 0 ;
7+ private const SCRIPT_NAME = 'php-css-lint ' ;
8+ private const RETURN_CODE_ERROR = 1 ;
9+ private const RETURN_CODE_SUCCESS = 0 ;
1010
1111 /**
1212 * Entrypoint of the cli, will execute the linter according to the given arguments
13- * @param array $aArguments arguments to be parsed (@see $_SERVER['argv'])
13+ * @param array $arguments arguments to be parsed (@see $_SERVER['argv'])
1414 * @return int the return code related to the execution of the linter
1515 **/
16- public function run (array $ aArguments ): int
16+ public function run (array $ arguments ): int
1717 {
18- $ oCliArgs = $ this ->parseArguments ($ aArguments );
19- if (!$ oCliArgs ->filePathOrCssString ) {
18+ $ cliArgs = $ this ->parseArguments ($ arguments );
19+ if (!$ cliArgs ->filePathOrCssString ) {
2020 $ this ->printUsage ();
21- return self ::$ RETURN_CODE_SUCCESS ;
21+ return self ::RETURN_CODE_SUCCESS ;
2222 }
2323
24- $ oProperties = new \CssLint \Properties ();
25- if ($ oCliArgs ->options ) {
26- $ aOptions = json_decode ($ oCliArgs ->options , true );
24+ $ properties = new \CssLint \Properties ();
25+ if ($ cliArgs ->options ) {
26+ $ options = json_decode ($ cliArgs ->options , true );
2727
2828 if (json_last_error ()) {
29- $ sErrorMessage = json_last_error_msg ();
30- $ this ->printError ('Unable to parse option argument: ' . $ sErrorMessage );
31- return self ::$ RETURN_CODE_ERROR ;
29+ $ errorMessage = json_last_error_msg ();
30+ $ this ->printError ('Unable to parse option argument: ' . $ errorMessage );
31+ return self ::RETURN_CODE_ERROR ;
3232 }
3333
34- if (!$ aOptions ) {
34+ if (!$ options ) {
3535 $ this ->printError ('Unable to parse empty option argument ' );
36- return self ::$ RETURN_CODE_ERROR ;
36+ return self ::RETURN_CODE_ERROR ;
3737 }
38- $ oProperties ->setOptions ($ aOptions );
38+ $ properties ->setOptions ($ options );
3939 }
4040
41- $ oCssLinter = new \CssLint \Linter ($ oProperties );
41+ $ cssLinter = new \CssLint \Linter ($ properties );
4242
43- $ sFilePathOrCssString = $ oCliArgs ->filePathOrCssString ;
44- if (!file_exists ($ sFilePathOrCssString )) {
45- return $ this ->lintString ($ oCssLinter , $ sFilePathOrCssString );
43+ $ filePathOrCssString = $ cliArgs ->filePathOrCssString ;
44+ if (!file_exists ($ filePathOrCssString )) {
45+ return $ this ->lintString ($ cssLinter , $ filePathOrCssString );
4646 }
4747
48- $ sFilePath = $ sFilePathOrCssString ;
49- if (!is_readable ($ sFilePath )) {
50- $ this ->printError ('File " ' . $ sFilePath . '" is not readable ' );
51- return self ::$ RETURN_CODE_ERROR ;
48+ $ filePath = $ filePathOrCssString ;
49+ if (!is_readable ($ filePath )) {
50+ $ this ->printError ('File " ' . $ filePath . '" is not readable ' );
51+ return self ::RETURN_CODE_ERROR ;
5252 }
5353
54- return $ this ->lintFile ($ oCssLinter , $ sFilePath );
54+ return $ this ->lintFile ($ cssLinter , $ filePath );
5555 }
5656
5757 /**
5858 * Retrieve the parsed Cli arguments from given arguments array
5959 * @return \CssLint\CliArgs an instance of Cli arguments object containing parsed arguments
6060 */
61- private function parseArguments (array $ aArguments ): \CssLint \CliArgs
61+ private function parseArguments (array $ arguments ): \CssLint \CliArgs
6262 {
63- return new \CssLint \CliArgs ($ aArguments );
63+ return new \CssLint \CliArgs ($ arguments );
6464 }
6565
6666 /**
@@ -71,7 +71,7 @@ private function printUsage()
7171 $ this ->printLine ('Usage: ' . PHP_EOL .
7272 '------ ' . PHP_EOL .
7373 PHP_EOL .
74- ' ' . self ::$ SCRIPT_NAME . ' [--options= \'{ } \'] css_file_or_string_to_lint ' . PHP_EOL .
74+ ' ' . self ::SCRIPT_NAME . ' [--options= \'{ } \'] css_file_or_string_to_lint ' . PHP_EOL .
7575 PHP_EOL .
7676 'Arguments: ' . PHP_EOL .
7777 '---------- ' . PHP_EOL .
@@ -95,83 +95,83 @@ private function printUsage()
9595 '--------- ' . PHP_EOL .
9696 PHP_EOL .
9797 ' Lint a CSS file: ' . PHP_EOL .
98- ' ' . self ::$ SCRIPT_NAME . ' ./path/to/css_file_path_to_lint.css ' . PHP_EOL . PHP_EOL .
98+ ' ' . self ::SCRIPT_NAME . ' ./path/to/css_file_path_to_lint.css ' . PHP_EOL . PHP_EOL .
9999 ' Lint a CSS string: ' . PHP_EOL .
100- ' ' . self ::$ SCRIPT_NAME . ' ".test { color: red; }" ' . PHP_EOL . PHP_EOL .
100+ ' ' . self ::SCRIPT_NAME . ' ".test { color: red; }" ' . PHP_EOL . PHP_EOL .
101101 ' Lint with only tabulation as indentation: ' . PHP_EOL .
102- ' ' . self ::$ SCRIPT_NAME .
102+ ' ' . self ::SCRIPT_NAME .
103103 ' --options= \'{ "allowedIndentationChars": ["\t"] } \' ".test { color: red; }" ' . PHP_EOL .
104104 PHP_EOL . PHP_EOL );
105105 }
106106
107107 /**
108108 * Performs lint on a given file path
109- * @param \CssLint\Linter $oCssLinter the instance of the linter
110- * @param string $sFilePath the path of the file to be linted
109+ * @param \CssLint\Linter $cssLinter the instance of the linter
110+ * @param string $filePath the path of the file to be linted
111111 * @return int the return code related to the execution of the linter
112112 */
113- private function lintFile (\CssLint \Linter $ oCssLinter , string $ sFilePath ): int
113+ private function lintFile (\CssLint \Linter $ cssLinter , string $ filePath ): int
114114 {
115- $ this ->printLine ('# Lint CSS file " ' . $ sFilePath . '"... ' );
115+ $ this ->printLine ('# Lint CSS file " ' . $ filePath . '"... ' );
116116
117- if ($ oCssLinter ->lintFile ($ sFilePath )) {
118- $ this ->printLine ("\033[32m => CSS file \"" . $ sFilePath . "\" is valid \033[0m " . PHP_EOL );
119- return self ::$ RETURN_CODE_SUCCESS ;
117+ if ($ cssLinter ->lintFile ($ filePath )) {
118+ $ this ->printLine ("\033[32m => CSS file \"" . $ filePath . "\" is valid \033[0m " . PHP_EOL );
119+ return self ::RETURN_CODE_SUCCESS ;
120120 }
121121
122- $ this ->printLine ("\033[31m => CSS file \"" . $ sFilePath . "\" is not valid: \033[0m " . PHP_EOL );
123- $ this ->displayLinterErrors ($ oCssLinter ->getErrors ());
124- return self ::$ RETURN_CODE_ERROR ;
122+ $ this ->printLine ("\033[31m => CSS file \"" . $ filePath . "\" is not valid: \033[0m " . PHP_EOL );
123+ $ this ->displayLinterErrors ($ cssLinter ->getErrors ());
124+ return self ::RETURN_CODE_ERROR ;
125125 }
126126
127127
128128 /**
129129 * Performs lint on a given string
130- * @param \CssLint\Linter $oCssLinter the instance of the linter
131- * @param string $sString the CSS string to be linted
130+ * @param \CssLint\Linter $cssLinter the instance of the linter
131+ * @param string $stringValue the CSS string to be linted
132132 * @return int the return code related to the execution of the linter
133133 */
134- private function lintString (\CssLint \Linter $ oCssLinter , string $ sString ): int
134+ private function lintString (\CssLint \Linter $ cssLinter , string $ stringValue ): int
135135 {
136136 $ this ->printLine ('# Lint CSS string... ' );
137137
138- if ($ oCssLinter ->lintString ($ sString )) {
138+ if ($ cssLinter ->lintString ($ stringValue )) {
139139 $ this ->printLine ("\033[32m => CSS string is valid \033[0m " . PHP_EOL );
140- return self ::$ RETURN_CODE_SUCCESS ;
140+ return self ::RETURN_CODE_SUCCESS ;
141141 }
142142
143143 $ this ->printLine ("\033[31m => CSS string is not valid: \033[0m " . PHP_EOL );
144- $ this ->displayLinterErrors ($ oCssLinter ->getErrors ());
145- return self ::$ RETURN_CODE_ERROR ;
144+ $ this ->displayLinterErrors ($ cssLinter ->getErrors ());
145+ return self ::RETURN_CODE_ERROR ;
146146 }
147147
148148 /**
149149 * Display an error message
150- * @param string $sError the message to be displayed
150+ * @param string $error the message to be displayed
151151 */
152- private function printError (string $ sError )
152+ private function printError (string $ error )
153153 {
154- $ this ->printLine ("\033[31m/!\ Error: " . $ sError . "\033[0m " . PHP_EOL );
154+ $ this ->printLine ("\033[31m/!\ Error: " . $ error . "\033[0m " . PHP_EOL );
155155 }
156156
157157 /**
158158 * Display the errors returned by the linter
159- * @param array $aErrors the generated errors to be displayed
159+ * @param array $errors the generated errors to be displayed
160160 */
161- private function displayLinterErrors (array $ aErrors )
161+ private function displayLinterErrors (array $ errors )
162162 {
163- foreach ($ aErrors as $ sError ) {
164- $ this ->printLine ("\033[31m - " . $ sError . "\033[0m " );
163+ foreach ($ errors as $ error ) {
164+ $ this ->printLine ("\033[31m - " . $ error . "\033[0m " );
165165 }
166166 $ this ->printLine ("" );
167167 }
168168
169169 /**
170170 * Display the given message in a new line
171- * @param string $sMessage the message to be displayed
171+ * @param string $message the message to be displayed
172172 */
173- private function printLine (string $ sMessage )
173+ private function printLine (string $ message )
174174 {
175- echo $ sMessage . PHP_EOL ;
175+ echo $ message . PHP_EOL ;
176176 }
177177}
0 commit comments