Completed
Branch RELEASE (416965)
by
unknown
12:55 queued 13s
created
vendor/squizlabs/php_codesniffer/src/Reports/Report.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -15,50 +15,50 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Generate a partial report for a single processed file.
20
-     *
21
-     * Function should return TRUE if it printed or stored data about the file
22
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
23
-     * its data should be counted in the grand totals.
24
-     *
25
-     * @param array                 $report      Prepared report data.
26
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
27
-     * @param bool                  $showSources Show sources?
28
-     * @param int                   $width       Maximum allowed line width.
29
-     *
30
-     * @return bool
31
-     */
32
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80);
18
+	/**
19
+	 * Generate a partial report for a single processed file.
20
+	 *
21
+	 * Function should return TRUE if it printed or stored data about the file
22
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
23
+	 * its data should be counted in the grand totals.
24
+	 *
25
+	 * @param array                 $report      Prepared report data.
26
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
27
+	 * @param bool                  $showSources Show sources?
28
+	 * @param int                   $width       Maximum allowed line width.
29
+	 *
30
+	 * @return bool
31
+	 */
32
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80);
33 33
 
34 34
 
35
-    /**
36
-     * Generate the actual report.
37
-     *
38
-     * @param string $cachedData    Any partial report data that was returned from
39
-     *                              generateFileReport during the run.
40
-     * @param int    $totalFiles    Total number of files processed during the run.
41
-     * @param int    $totalErrors   Total number of errors found during the run.
42
-     * @param int    $totalWarnings Total number of warnings found during the run.
43
-     * @param int    $totalFixable  Total number of problems that can be fixed.
44
-     * @param bool   $showSources   Show sources?
45
-     * @param int    $width         Maximum allowed line width.
46
-     * @param bool   $interactive   Are we running in interactive mode?
47
-     * @param bool   $toScreen      Is the report being printed to screen?
48
-     *
49
-     * @return void
50
-     */
51
-    public function generate(
52
-        $cachedData,
53
-        $totalFiles,
54
-        $totalErrors,
55
-        $totalWarnings,
56
-        $totalFixable,
57
-        $showSources=false,
58
-        $width=80,
59
-        $interactive=false,
60
-        $toScreen=true
61
-    );
35
+	/**
36
+	 * Generate the actual report.
37
+	 *
38
+	 * @param string $cachedData    Any partial report data that was returned from
39
+	 *                              generateFileReport during the run.
40
+	 * @param int    $totalFiles    Total number of files processed during the run.
41
+	 * @param int    $totalErrors   Total number of errors found during the run.
42
+	 * @param int    $totalWarnings Total number of warnings found during the run.
43
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
44
+	 * @param bool   $showSources   Show sources?
45
+	 * @param int    $width         Maximum allowed line width.
46
+	 * @param bool   $interactive   Are we running in interactive mode?
47
+	 * @param bool   $toScreen      Is the report being printed to screen?
48
+	 *
49
+	 * @return void
50
+	 */
51
+	public function generate(
52
+		$cachedData,
53
+		$totalFiles,
54
+		$totalErrors,
55
+		$totalWarnings,
56
+		$totalFixable,
57
+		$showSources=false,
58
+		$width=80,
59
+		$interactive=false,
60
+		$toScreen=true
61
+	);
62 62
 
63 63
 
64 64
 }//end interface
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      *
30 30
      * @return bool
31 31
      */
32
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80);
32
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80);
33 33
 
34 34
 
35 35
     /**
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
         $totalErrors,
55 55
         $totalWarnings,
56 56
         $totalFixable,
57
-        $showSources=false,
58
-        $width=80,
59
-        $interactive=false,
60
-        $toScreen=true
57
+        $showSources = false,
58
+        $width = 80,
59
+        $interactive = false,
60
+        $toScreen = true
61 61
     );
62 62
 
63 63
 
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Junit.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      *
32 32
      * @return bool
33 33
      */
34
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
35 35
     {
36 36
         $out = new \XMLWriter;
37 37
         $out->openMemory();
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
         $totalErrors,
104 104
         $totalWarnings,
105 105
         $totalFixable,
106
-        $showSources=false,
107
-        $width=80,
108
-        $interactive=false,
109
-        $toScreen=true
106
+        $showSources = false,
107
+        $width = 80,
108
+        $interactive = false,
109
+        $toScreen = true
110 110
     ) {
111 111
         // Figure out the total number of tests.
112 112
         $tests   = 0;
Please login to merge, or discard this patch.
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -17,115 +17,115 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Generate a partial report for a single processed file.
22
-     *
23
-     * Function should return TRUE if it printed or stored data about the file
24
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
25
-     * its data should be counted in the grand totals.
26
-     *
27
-     * @param array                 $report      Prepared report data.
28
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
29
-     * @param bool                  $showSources Show sources?
30
-     * @param int                   $width       Maximum allowed line width.
31
-     *
32
-     * @return bool
33
-     */
34
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
35
-    {
36
-        $out = new \XMLWriter;
37
-        $out->openMemory();
38
-        $out->setIndent(true);
39
-
40
-        $out->startElement('testsuite');
41
-        $out->writeAttribute('name', $report['filename']);
42
-        $out->writeAttribute('errors', 0);
43
-
44
-        if (count($report['messages']) === 0) {
45
-            $out->writeAttribute('tests', 1);
46
-            $out->writeAttribute('failures', 0);
47
-
48
-            $out->startElement('testcase');
49
-            $out->writeAttribute('name', $report['filename']);
50
-            $out->endElement();
51
-        } else {
52
-            $failures = ($report['errors'] + $report['warnings']);
53
-            $out->writeAttribute('tests', $failures);
54
-            $out->writeAttribute('failures', $failures);
55
-
56
-            foreach ($report['messages'] as $line => $lineErrors) {
57
-                foreach ($lineErrors as $column => $colErrors) {
58
-                    foreach ($colErrors as $error) {
59
-                        $out->startElement('testcase');
60
-                        $out->writeAttribute('name', $error['source'].' at '.$report['filename']." ($line:$column)");
61
-
62
-                        $error['type'] = strtolower($error['type']);
63
-                        if ($phpcsFile->config->encoding !== 'utf-8') {
64
-                            $error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
65
-                        }
66
-
67
-                        $out->startElement('failure');
68
-                        $out->writeAttribute('type', $error['type']);
69
-                        $out->writeAttribute('message', $error['message']);
70
-                        $out->endElement();
71
-
72
-                        $out->endElement();
73
-                    }
74
-                }
75
-            }
76
-        }//end if
77
-
78
-        $out->endElement();
79
-        echo $out->flush();
80
-        return true;
81
-
82
-    }//end generateFileReport()
83
-
84
-
85
-    /**
86
-     * Prints all violations for processed files, in a proprietary XML format.
87
-     *
88
-     * @param string $cachedData    Any partial report data that was returned from
89
-     *                              generateFileReport during the run.
90
-     * @param int    $totalFiles    Total number of files processed during the run.
91
-     * @param int    $totalErrors   Total number of errors found during the run.
92
-     * @param int    $totalWarnings Total number of warnings found during the run.
93
-     * @param int    $totalFixable  Total number of problems that can be fixed.
94
-     * @param bool   $showSources   Show sources?
95
-     * @param int    $width         Maximum allowed line width.
96
-     * @param bool   $interactive   Are we running in interactive mode?
97
-     * @param bool   $toScreen      Is the report being printed to screen?
98
-     *
99
-     * @return void
100
-     */
101
-    public function generate(
102
-        $cachedData,
103
-        $totalFiles,
104
-        $totalErrors,
105
-        $totalWarnings,
106
-        $totalFixable,
107
-        $showSources=false,
108
-        $width=80,
109
-        $interactive=false,
110
-        $toScreen=true
111
-    ) {
112
-        // Figure out the total number of tests.
113
-        $tests   = 0;
114
-        $matches = [];
115
-        preg_match_all('/tests="([0-9]+)"/', $cachedData, $matches);
116
-        if (isset($matches[1]) === true) {
117
-            foreach ($matches[1] as $match) {
118
-                $tests += $match;
119
-            }
120
-        }
121
-
122
-        $failures = ($totalErrors + $totalWarnings);
123
-        echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
124
-        echo '<testsuites name="PHP_CodeSniffer '.Config::VERSION.'" errors="0" tests="'.$tests.'" failures="'.$failures.'">'.PHP_EOL;
125
-        echo $cachedData;
126
-        echo '</testsuites>'.PHP_EOL;
127
-
128
-    }//end generate()
20
+	/**
21
+	 * Generate a partial report for a single processed file.
22
+	 *
23
+	 * Function should return TRUE if it printed or stored data about the file
24
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
25
+	 * its data should be counted in the grand totals.
26
+	 *
27
+	 * @param array                 $report      Prepared report data.
28
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
29
+	 * @param bool                  $showSources Show sources?
30
+	 * @param int                   $width       Maximum allowed line width.
31
+	 *
32
+	 * @return bool
33
+	 */
34
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
35
+	{
36
+		$out = new \XMLWriter;
37
+		$out->openMemory();
38
+		$out->setIndent(true);
39
+
40
+		$out->startElement('testsuite');
41
+		$out->writeAttribute('name', $report['filename']);
42
+		$out->writeAttribute('errors', 0);
43
+
44
+		if (count($report['messages']) === 0) {
45
+			$out->writeAttribute('tests', 1);
46
+			$out->writeAttribute('failures', 0);
47
+
48
+			$out->startElement('testcase');
49
+			$out->writeAttribute('name', $report['filename']);
50
+			$out->endElement();
51
+		} else {
52
+			$failures = ($report['errors'] + $report['warnings']);
53
+			$out->writeAttribute('tests', $failures);
54
+			$out->writeAttribute('failures', $failures);
55
+
56
+			foreach ($report['messages'] as $line => $lineErrors) {
57
+				foreach ($lineErrors as $column => $colErrors) {
58
+					foreach ($colErrors as $error) {
59
+						$out->startElement('testcase');
60
+						$out->writeAttribute('name', $error['source'].' at '.$report['filename']." ($line:$column)");
61
+
62
+						$error['type'] = strtolower($error['type']);
63
+						if ($phpcsFile->config->encoding !== 'utf-8') {
64
+							$error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
65
+						}
66
+
67
+						$out->startElement('failure');
68
+						$out->writeAttribute('type', $error['type']);
69
+						$out->writeAttribute('message', $error['message']);
70
+						$out->endElement();
71
+
72
+						$out->endElement();
73
+					}
74
+				}
75
+			}
76
+		}//end if
77
+
78
+		$out->endElement();
79
+		echo $out->flush();
80
+		return true;
81
+
82
+	}//end generateFileReport()
83
+
84
+
85
+	/**
86
+	 * Prints all violations for processed files, in a proprietary XML format.
87
+	 *
88
+	 * @param string $cachedData    Any partial report data that was returned from
89
+	 *                              generateFileReport during the run.
90
+	 * @param int    $totalFiles    Total number of files processed during the run.
91
+	 * @param int    $totalErrors   Total number of errors found during the run.
92
+	 * @param int    $totalWarnings Total number of warnings found during the run.
93
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
94
+	 * @param bool   $showSources   Show sources?
95
+	 * @param int    $width         Maximum allowed line width.
96
+	 * @param bool   $interactive   Are we running in interactive mode?
97
+	 * @param bool   $toScreen      Is the report being printed to screen?
98
+	 *
99
+	 * @return void
100
+	 */
101
+	public function generate(
102
+		$cachedData,
103
+		$totalFiles,
104
+		$totalErrors,
105
+		$totalWarnings,
106
+		$totalFixable,
107
+		$showSources=false,
108
+		$width=80,
109
+		$interactive=false,
110
+		$toScreen=true
111
+	) {
112
+		// Figure out the total number of tests.
113
+		$tests   = 0;
114
+		$matches = [];
115
+		preg_match_all('/tests="([0-9]+)"/', $cachedData, $matches);
116
+		if (isset($matches[1]) === true) {
117
+			foreach ($matches[1] as $match) {
118
+				$tests += $match;
119
+			}
120
+		}
121
+
122
+		$failures = ($totalErrors + $totalWarnings);
123
+		echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
124
+		echo '<testsuites name="PHP_CodeSniffer '.Config::VERSION.'" errors="0" tests="'.$tests.'" failures="'.$failures.'">'.PHP_EOL;
125
+		echo $cachedData;
126
+		echo '</testsuites>'.PHP_EOL;
127
+
128
+	}//end generate()
129 129
 
130 130
 
131 131
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Emacs.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -15,76 +15,76 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Generate a partial report for a single processed file.
20
-     *
21
-     * Function should return TRUE if it printed or stored data about the file
22
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
23
-     * its data should be counted in the grand totals.
24
-     *
25
-     * @param array                 $report      Prepared report data.
26
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
27
-     * @param bool                  $showSources Show sources?
28
-     * @param int                   $width       Maximum allowed line width.
29
-     *
30
-     * @return bool
31
-     */
32
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
33
-    {
34
-        if ($report['errors'] === 0 && $report['warnings'] === 0) {
35
-            // Nothing to print.
36
-            return false;
37
-        }
18
+	/**
19
+	 * Generate a partial report for a single processed file.
20
+	 *
21
+	 * Function should return TRUE if it printed or stored data about the file
22
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
23
+	 * its data should be counted in the grand totals.
24
+	 *
25
+	 * @param array                 $report      Prepared report data.
26
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
27
+	 * @param bool                  $showSources Show sources?
28
+	 * @param int                   $width       Maximum allowed line width.
29
+	 *
30
+	 * @return bool
31
+	 */
32
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
33
+	{
34
+		if ($report['errors'] === 0 && $report['warnings'] === 0) {
35
+			// Nothing to print.
36
+			return false;
37
+		}
38 38
 
39
-        foreach ($report['messages'] as $line => $lineErrors) {
40
-            foreach ($lineErrors as $column => $colErrors) {
41
-                foreach ($colErrors as $error) {
42
-                    $message = $error['message'];
43
-                    if ($showSources === true) {
44
-                        $message .= ' ('.$error['source'].')';
45
-                    }
39
+		foreach ($report['messages'] as $line => $lineErrors) {
40
+			foreach ($lineErrors as $column => $colErrors) {
41
+				foreach ($colErrors as $error) {
42
+					$message = $error['message'];
43
+					if ($showSources === true) {
44
+						$message .= ' ('.$error['source'].')';
45
+					}
46 46
 
47
-                    $type = strtolower($error['type']);
48
-                    echo $report['filename'].':'.$line.':'.$column.': '.$type.' - '.$message.PHP_EOL;
49
-                }
50
-            }
51
-        }
47
+					$type = strtolower($error['type']);
48
+					echo $report['filename'].':'.$line.':'.$column.': '.$type.' - '.$message.PHP_EOL;
49
+				}
50
+			}
51
+		}
52 52
 
53
-        return true;
53
+		return true;
54 54
 
55
-    }//end generateFileReport()
55
+	}//end generateFileReport()
56 56
 
57 57
 
58
-    /**
59
-     * Generates an emacs report.
60
-     *
61
-     * @param string $cachedData    Any partial report data that was returned from
62
-     *                              generateFileReport during the run.
63
-     * @param int    $totalFiles    Total number of files processed during the run.
64
-     * @param int    $totalErrors   Total number of errors found during the run.
65
-     * @param int    $totalWarnings Total number of warnings found during the run.
66
-     * @param int    $totalFixable  Total number of problems that can be fixed.
67
-     * @param bool   $showSources   Show sources?
68
-     * @param int    $width         Maximum allowed line width.
69
-     * @param bool   $interactive   Are we running in interactive mode?
70
-     * @param bool   $toScreen      Is the report being printed to screen?
71
-     *
72
-     * @return void
73
-     */
74
-    public function generate(
75
-        $cachedData,
76
-        $totalFiles,
77
-        $totalErrors,
78
-        $totalWarnings,
79
-        $totalFixable,
80
-        $showSources=false,
81
-        $width=80,
82
-        $interactive=false,
83
-        $toScreen=true
84
-    ) {
85
-        echo $cachedData;
58
+	/**
59
+	 * Generates an emacs report.
60
+	 *
61
+	 * @param string $cachedData    Any partial report data that was returned from
62
+	 *                              generateFileReport during the run.
63
+	 * @param int    $totalFiles    Total number of files processed during the run.
64
+	 * @param int    $totalErrors   Total number of errors found during the run.
65
+	 * @param int    $totalWarnings Total number of warnings found during the run.
66
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
67
+	 * @param bool   $showSources   Show sources?
68
+	 * @param int    $width         Maximum allowed line width.
69
+	 * @param bool   $interactive   Are we running in interactive mode?
70
+	 * @param bool   $toScreen      Is the report being printed to screen?
71
+	 *
72
+	 * @return void
73
+	 */
74
+	public function generate(
75
+		$cachedData,
76
+		$totalFiles,
77
+		$totalErrors,
78
+		$totalWarnings,
79
+		$totalFixable,
80
+		$showSources=false,
81
+		$width=80,
82
+		$interactive=false,
83
+		$toScreen=true
84
+	) {
85
+		echo $cachedData;
86 86
 
87
-    }//end generate()
87
+	}//end generate()
88 88
 
89 89
 
90 90
 }//end class
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      *
30 30
      * @return bool
31 31
      */
32
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
32
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
33 33
     {
34 34
         if ($report['errors'] === 0 && $report['warnings'] === 0) {
35 35
             // Nothing to print.
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
         $totalErrors,
78 78
         $totalWarnings,
79 79
         $totalFixable,
80
-        $showSources=false,
81
-        $width=80,
82
-        $interactive=false,
83
-        $toScreen=true
80
+        $showSources = false,
81
+        $width = 80,
82
+        $interactive = false,
83
+        $toScreen = true
84 84
     ) {
85 85
         echo $cachedData;
86 86
 
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Xml.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @return bool
32 32
      */
33
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
33
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
34 34
     {
35 35
         $out = new \XMLWriter;
36 36
         $out->openMemory();
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
         $totalErrors,
106 106
         $totalWarnings,
107 107
         $totalFixable,
108
-        $showSources=false,
109
-        $width=80,
110
-        $interactive=false,
111
-        $toScreen=true
108
+        $showSources = false,
109
+        $width = 80,
110
+        $interactive = false,
111
+        $toScreen = true
112 112
     ) {
113 113
         echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
114 114
         echo '<phpcs version="'.Config::VERSION.'">'.PHP_EOL;
Please login to merge, or discard this patch.
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -16,111 +16,111 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Generate a partial report for a single processed file.
21
-     *
22
-     * Function should return TRUE if it printed or stored data about the file
23
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
-     * its data should be counted in the grand totals.
25
-     *
26
-     * @param array                 $report      Prepared report data.
27
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
28
-     * @param bool                  $showSources Show sources?
29
-     * @param int                   $width       Maximum allowed line width.
30
-     *
31
-     * @return bool
32
-     */
33
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
-    {
35
-        $out = new \XMLWriter;
36
-        $out->openMemory();
37
-        $out->setIndent(true);
38
-        $out->setIndentString('    ');
39
-        $out->startDocument('1.0', 'UTF-8');
40
-
41
-        if ($report['errors'] === 0 && $report['warnings'] === 0) {
42
-            // Nothing to print.
43
-            return false;
44
-        }
45
-
46
-        $out->startElement('file');
47
-        $out->writeAttribute('name', $report['filename']);
48
-        $out->writeAttribute('errors', $report['errors']);
49
-        $out->writeAttribute('warnings', $report['warnings']);
50
-        $out->writeAttribute('fixable', $report['fixable']);
51
-
52
-        foreach ($report['messages'] as $line => $lineErrors) {
53
-            foreach ($lineErrors as $column => $colErrors) {
54
-                foreach ($colErrors as $error) {
55
-                    $error['type'] = strtolower($error['type']);
56
-                    if ($phpcsFile->config->encoding !== 'utf-8') {
57
-                        $error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
58
-                    }
59
-
60
-                    $out->startElement($error['type']);
61
-                    $out->writeAttribute('line', $line);
62
-                    $out->writeAttribute('column', $column);
63
-                    $out->writeAttribute('source', $error['source']);
64
-                    $out->writeAttribute('severity', $error['severity']);
65
-                    $out->writeAttribute('fixable', (int) $error['fixable']);
66
-                    $out->text($error['message']);
67
-                    $out->endElement();
68
-                }
69
-            }
70
-        }//end foreach
71
-
72
-        $out->endElement();
73
-
74
-        // Remove the start of the document because we will
75
-        // add that manually later. We only have it in here to
76
-        // properly set the encoding.
77
-        $content = $out->flush();
78
-        if (strpos($content, PHP_EOL) !== false) {
79
-            $content = substr($content, (strpos($content, PHP_EOL) + strlen(PHP_EOL)));
80
-        } else if (strpos($content, "\n") !== false) {
81
-            $content = substr($content, (strpos($content, "\n") + 1));
82
-        }
83
-
84
-        echo $content;
85
-
86
-        return true;
87
-
88
-    }//end generateFileReport()
89
-
90
-
91
-    /**
92
-     * Prints all violations for processed files, in a proprietary XML format.
93
-     *
94
-     * @param string $cachedData    Any partial report data that was returned from
95
-     *                              generateFileReport during the run.
96
-     * @param int    $totalFiles    Total number of files processed during the run.
97
-     * @param int    $totalErrors   Total number of errors found during the run.
98
-     * @param int    $totalWarnings Total number of warnings found during the run.
99
-     * @param int    $totalFixable  Total number of problems that can be fixed.
100
-     * @param bool   $showSources   Show sources?
101
-     * @param int    $width         Maximum allowed line width.
102
-     * @param bool   $interactive   Are we running in interactive mode?
103
-     * @param bool   $toScreen      Is the report being printed to screen?
104
-     *
105
-     * @return void
106
-     */
107
-    public function generate(
108
-        $cachedData,
109
-        $totalFiles,
110
-        $totalErrors,
111
-        $totalWarnings,
112
-        $totalFixable,
113
-        $showSources=false,
114
-        $width=80,
115
-        $interactive=false,
116
-        $toScreen=true
117
-    ) {
118
-        echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
119
-        echo '<phpcs version="'.Config::VERSION.'">'.PHP_EOL;
120
-        echo $cachedData;
121
-        echo '</phpcs>'.PHP_EOL;
122
-
123
-    }//end generate()
19
+	/**
20
+	 * Generate a partial report for a single processed file.
21
+	 *
22
+	 * Function should return TRUE if it printed or stored data about the file
23
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
+	 * its data should be counted in the grand totals.
25
+	 *
26
+	 * @param array                 $report      Prepared report data.
27
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
28
+	 * @param bool                  $showSources Show sources?
29
+	 * @param int                   $width       Maximum allowed line width.
30
+	 *
31
+	 * @return bool
32
+	 */
33
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
+	{
35
+		$out = new \XMLWriter;
36
+		$out->openMemory();
37
+		$out->setIndent(true);
38
+		$out->setIndentString('    ');
39
+		$out->startDocument('1.0', 'UTF-8');
40
+
41
+		if ($report['errors'] === 0 && $report['warnings'] === 0) {
42
+			// Nothing to print.
43
+			return false;
44
+		}
45
+
46
+		$out->startElement('file');
47
+		$out->writeAttribute('name', $report['filename']);
48
+		$out->writeAttribute('errors', $report['errors']);
49
+		$out->writeAttribute('warnings', $report['warnings']);
50
+		$out->writeAttribute('fixable', $report['fixable']);
51
+
52
+		foreach ($report['messages'] as $line => $lineErrors) {
53
+			foreach ($lineErrors as $column => $colErrors) {
54
+				foreach ($colErrors as $error) {
55
+					$error['type'] = strtolower($error['type']);
56
+					if ($phpcsFile->config->encoding !== 'utf-8') {
57
+						$error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
58
+					}
59
+
60
+					$out->startElement($error['type']);
61
+					$out->writeAttribute('line', $line);
62
+					$out->writeAttribute('column', $column);
63
+					$out->writeAttribute('source', $error['source']);
64
+					$out->writeAttribute('severity', $error['severity']);
65
+					$out->writeAttribute('fixable', (int) $error['fixable']);
66
+					$out->text($error['message']);
67
+					$out->endElement();
68
+				}
69
+			}
70
+		}//end foreach
71
+
72
+		$out->endElement();
73
+
74
+		// Remove the start of the document because we will
75
+		// add that manually later. We only have it in here to
76
+		// properly set the encoding.
77
+		$content = $out->flush();
78
+		if (strpos($content, PHP_EOL) !== false) {
79
+			$content = substr($content, (strpos($content, PHP_EOL) + strlen(PHP_EOL)));
80
+		} else if (strpos($content, "\n") !== false) {
81
+			$content = substr($content, (strpos($content, "\n") + 1));
82
+		}
83
+
84
+		echo $content;
85
+
86
+		return true;
87
+
88
+	}//end generateFileReport()
89
+
90
+
91
+	/**
92
+	 * Prints all violations for processed files, in a proprietary XML format.
93
+	 *
94
+	 * @param string $cachedData    Any partial report data that was returned from
95
+	 *                              generateFileReport during the run.
96
+	 * @param int    $totalFiles    Total number of files processed during the run.
97
+	 * @param int    $totalErrors   Total number of errors found during the run.
98
+	 * @param int    $totalWarnings Total number of warnings found during the run.
99
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
100
+	 * @param bool   $showSources   Show sources?
101
+	 * @param int    $width         Maximum allowed line width.
102
+	 * @param bool   $interactive   Are we running in interactive mode?
103
+	 * @param bool   $toScreen      Is the report being printed to screen?
104
+	 *
105
+	 * @return void
106
+	 */
107
+	public function generate(
108
+		$cachedData,
109
+		$totalFiles,
110
+		$totalErrors,
111
+		$totalWarnings,
112
+		$totalFixable,
113
+		$showSources=false,
114
+		$width=80,
115
+		$interactive=false,
116
+		$toScreen=true
117
+	) {
118
+		echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
119
+		echo '<phpcs version="'.Config::VERSION.'">'.PHP_EOL;
120
+		echo $cachedData;
121
+		echo '</phpcs>'.PHP_EOL;
122
+
123
+	}//end generate()
124 124
 
125 125
 
126 126
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Source.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @return bool
32 32
      */
33
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
33
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
34 34
     {
35 35
         if ($report['errors'] === 0 && $report['warnings'] === 0) {
36 36
             // Nothing to print.
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
         $totalErrors,
87 87
         $totalWarnings,
88 88
         $totalFixable,
89
-        $showSources=false,
90
-        $width=80,
91
-        $interactive=false,
92
-        $toScreen=true
89
+        $showSources = false,
90
+        $width = 80,
91
+        $interactive = false,
92
+        $toScreen = true
93 93
     ) {
94 94
         $lines = explode(PHP_EOL, $cachedData);
95 95
         array_pop($lines);
Please login to merge, or discard this patch.
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -16,321 +16,321 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Generate a partial report for a single processed file.
21
-     *
22
-     * Function should return TRUE if it printed or stored data about the file
23
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
-     * its data should be counted in the grand totals.
25
-     *
26
-     * @param array                 $report      Prepared report data.
27
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
28
-     * @param bool                  $showSources Show sources?
29
-     * @param int                   $width       Maximum allowed line width.
30
-     *
31
-     * @return bool
32
-     */
33
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
-    {
35
-        if ($report['errors'] === 0 && $report['warnings'] === 0) {
36
-            // Nothing to print.
37
-            return false;
38
-        }
39
-
40
-        $sources = [];
41
-
42
-        foreach ($report['messages'] as $line => $lineErrors) {
43
-            foreach ($lineErrors as $column => $colErrors) {
44
-                foreach ($colErrors as $error) {
45
-                    $src = $error['source'];
46
-                    if (isset($sources[$src]) === false) {
47
-                        $sources[$src] = [
48
-                            'fixable' => (int) $error['fixable'],
49
-                            'count'   => 1,
50
-                        ];
51
-                    } else {
52
-                        $sources[$src]['count']++;
53
-                    }
54
-                }
55
-            }
56
-        }
57
-
58
-        foreach ($sources as $source => $data) {
59
-            echo $source.'>>'.$data['fixable'].'>>'.$data['count'].PHP_EOL;
60
-        }
61
-
62
-        return true;
63
-
64
-    }//end generateFileReport()
65
-
66
-
67
-    /**
68
-     * Prints the source of all errors and warnings.
69
-     *
70
-     * @param string $cachedData    Any partial report data that was returned from
71
-     *                              generateFileReport during the run.
72
-     * @param int    $totalFiles    Total number of files processed during the run.
73
-     * @param int    $totalErrors   Total number of errors found during the run.
74
-     * @param int    $totalWarnings Total number of warnings found during the run.
75
-     * @param int    $totalFixable  Total number of problems that can be fixed.
76
-     * @param bool   $showSources   Show sources?
77
-     * @param int    $width         Maximum allowed line width.
78
-     * @param bool   $interactive   Are we running in interactive mode?
79
-     * @param bool   $toScreen      Is the report being printed to screen?
80
-     *
81
-     * @return void
82
-     */
83
-    public function generate(
84
-        $cachedData,
85
-        $totalFiles,
86
-        $totalErrors,
87
-        $totalWarnings,
88
-        $totalFixable,
89
-        $showSources=false,
90
-        $width=80,
91
-        $interactive=false,
92
-        $toScreen=true
93
-    ) {
94
-        $lines = explode(PHP_EOL, $cachedData);
95
-        array_pop($lines);
96
-
97
-        if (empty($lines) === true) {
98
-            return;
99
-        }
100
-
101
-        $sources   = [];
102
-        $maxLength = 0;
103
-
104
-        foreach ($lines as $line) {
105
-            $parts   = explode('>>', $line);
106
-            $source  = $parts[0];
107
-            $fixable = (bool) $parts[1];
108
-            $count   = $parts[2];
109
-
110
-            if (isset($sources[$source]) === false) {
111
-                if ($showSources === true) {
112
-                    $parts = null;
113
-                    $sniff = $source;
114
-                } else {
115
-                    $parts = explode('.', $source);
116
-                    if ($parts[0] === 'Internal') {
117
-                        $parts[2] = $parts[1];
118
-                        $parts[1] = '';
119
-                    }
120
-
121
-                    $parts[1] = $this->makeFriendlyName($parts[1]);
122
-
123
-                    $sniff = $this->makeFriendlyName($parts[2]);
124
-                    if (isset($parts[3]) === true) {
125
-                        $name    = $this->makeFriendlyName($parts[3]);
126
-                        $name[0] = strtolower($name[0]);
127
-                        $sniff  .= ' '.$name;
128
-                        unset($parts[3]);
129
-                    }
130
-
131
-                    $parts[2] = $sniff;
132
-                }//end if
133
-
134
-                $maxLength = max($maxLength, strlen($sniff));
135
-
136
-                $sources[$source] = [
137
-                    'count'   => $count,
138
-                    'fixable' => $fixable,
139
-                    'parts'   => $parts,
140
-                ];
141
-            } else {
142
-                $sources[$source]['count'] += $count;
143
-            }//end if
144
-        }//end foreach
145
-
146
-        if ($showSources === true) {
147
-            $width = min($width, ($maxLength + 11));
148
-        } else {
149
-            $width = min($width, ($maxLength + 41));
150
-        }
151
-
152
-        $width = max($width, 70);
153
-
154
-        // Sort the data based on counts and source code.
155
-        $sourceCodes = array_keys($sources);
156
-        $counts      = [];
157
-        foreach ($sources as $source => $data) {
158
-            $counts[$source] = $data['count'];
159
-        }
160
-
161
-        array_multisort($counts, SORT_DESC, $sourceCodes, SORT_ASC, SORT_NATURAL, $sources);
162
-
163
-        echo PHP_EOL."\033[1mPHP CODE SNIFFER VIOLATION SOURCE SUMMARY\033[0m".PHP_EOL;
164
-        echo str_repeat('-', $width).PHP_EOL."\033[1m";
165
-        if ($showSources === true) {
166
-            if ($totalFixable > 0) {
167
-                echo '    SOURCE'.str_repeat(' ', ($width - 15)).'COUNT'.PHP_EOL;
168
-            } else {
169
-                echo 'SOURCE'.str_repeat(' ', ($width - 11)).'COUNT'.PHP_EOL;
170
-            }
171
-        } else {
172
-            if ($totalFixable > 0) {
173
-                echo '    STANDARD  CATEGORY            SNIFF'.str_repeat(' ', ($width - 44)).'COUNT'.PHP_EOL;
174
-            } else {
175
-                echo 'STANDARD  CATEGORY            SNIFF'.str_repeat(' ', ($width - 40)).'COUNT'.PHP_EOL;
176
-            }
177
-        }
178
-
179
-        echo "\033[0m".str_repeat('-', $width).PHP_EOL;
180
-
181
-        $fixableSources = 0;
182
-
183
-        if ($showSources === true) {
184
-            $maxSniffWidth = ($width - 7);
185
-        } else {
186
-            $maxSniffWidth = ($width - 37);
187
-        }
188
-
189
-        if ($totalFixable > 0) {
190
-            $maxSniffWidth -= 4;
191
-        }
192
-
193
-        foreach ($sources as $source => $sourceData) {
194
-            if ($totalFixable > 0) {
195
-                echo '[';
196
-                if ($sourceData['fixable'] === true) {
197
-                    echo 'x';
198
-                    $fixableSources++;
199
-                } else {
200
-                    echo ' ';
201
-                }
202
-
203
-                echo '] ';
204
-            }
205
-
206
-            if ($showSources === true) {
207
-                if (strlen($source) > $maxSniffWidth) {
208
-                    $source = substr($source, 0, $maxSniffWidth);
209
-                }
210
-
211
-                echo $source;
212
-                if ($totalFixable > 0) {
213
-                    echo str_repeat(' ', ($width - 9 - strlen($source)));
214
-                } else {
215
-                    echo str_repeat(' ', ($width - 5 - strlen($source)));
216
-                }
217
-            } else {
218
-                $parts = $sourceData['parts'];
219
-
220
-                if (strlen($parts[0]) > 8) {
221
-                    $parts[0] = substr($parts[0], 0, ((strlen($parts[0]) - 8) * -1));
222
-                }
223
-
224
-                echo $parts[0].str_repeat(' ', (10 - strlen($parts[0])));
225
-
226
-                $category = $parts[1];
227
-                if (strlen($category) > 18) {
228
-                    $category = substr($category, 0, ((strlen($category) - 18) * -1));
229
-                }
230
-
231
-                echo $category.str_repeat(' ', (20 - strlen($category)));
232
-
233
-                $sniff = $parts[2];
234
-                if (strlen($sniff) > $maxSniffWidth) {
235
-                    $sniff = substr($sniff, 0, $maxSniffWidth);
236
-                }
237
-
238
-                if ($totalFixable > 0) {
239
-                    echo $sniff.str_repeat(' ', ($width - 39 - strlen($sniff)));
240
-                } else {
241
-                    echo $sniff.str_repeat(' ', ($width - 35 - strlen($sniff)));
242
-                }
243
-            }//end if
244
-
245
-            echo $sourceData['count'].PHP_EOL;
246
-        }//end foreach
247
-
248
-        echo str_repeat('-', $width).PHP_EOL;
249
-        echo "\033[1m".'A TOTAL OF '.($totalErrors + $totalWarnings).' SNIFF VIOLATION';
250
-        if (($totalErrors + $totalWarnings) > 1) {
251
-            echo 'S';
252
-        }
253
-
254
-        echo ' WERE FOUND IN '.count($sources).' SOURCE';
255
-        if (count($sources) !== 1) {
256
-            echo 'S';
257
-        }
258
-
259
-        echo "\033[0m";
260
-
261
-        if ($totalFixable > 0) {
262
-            echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
263
-            echo "\033[1mPHPCBF CAN FIX THE $fixableSources MARKED SOURCES AUTOMATICALLY ($totalFixable VIOLATIONS IN TOTAL)\033[0m";
264
-        }
265
-
266
-        echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
267
-
268
-        if ($toScreen === true && $interactive === false) {
269
-            Timing::printRunTime();
270
-        }
271
-
272
-    }//end generate()
273
-
274
-
275
-    /**
276
-     * Converts a camel caps name into a readable string.
277
-     *
278
-     * @param string $name The camel caps name to convert.
279
-     *
280
-     * @return string
281
-     */
282
-    public function makeFriendlyName($name)
283
-    {
284
-        if (trim($name) === '') {
285
-            return '';
286
-        }
287
-
288
-        $friendlyName = '';
289
-        $length       = strlen($name);
290
-
291
-        $lastWasUpper   = false;
292
-        $lastWasNumeric = false;
293
-        for ($i = 0; $i < $length; $i++) {
294
-            if (is_numeric($name[$i]) === true) {
295
-                if ($lastWasNumeric === false) {
296
-                    $friendlyName .= ' ';
297
-                }
298
-
299
-                $lastWasUpper   = false;
300
-                $lastWasNumeric = true;
301
-            } else {
302
-                $lastWasNumeric = false;
303
-
304
-                $char = strtolower($name[$i]);
305
-                if ($char === $name[$i]) {
306
-                    // Lowercase.
307
-                    $lastWasUpper = false;
308
-                } else {
309
-                    // Uppercase.
310
-                    if ($lastWasUpper === false) {
311
-                        $friendlyName .= ' ';
312
-                        if ($i < ($length - 1)) {
313
-                            $next = $name[($i + 1)];
314
-                            if (strtolower($next) === $next) {
315
-                                // Next char is lowercase so it is a word boundary.
316
-                                $name[$i] = strtolower($name[$i]);
317
-                            }
318
-                        }
319
-                    }
320
-
321
-                    $lastWasUpper = true;
322
-                }
323
-            }//end if
324
-
325
-            $friendlyName .= $name[$i];
326
-        }//end for
327
-
328
-        $friendlyName    = trim($friendlyName);
329
-        $friendlyName[0] = strtoupper($friendlyName[0]);
330
-
331
-        return $friendlyName;
332
-
333
-    }//end makeFriendlyName()
19
+	/**
20
+	 * Generate a partial report for a single processed file.
21
+	 *
22
+	 * Function should return TRUE if it printed or stored data about the file
23
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
+	 * its data should be counted in the grand totals.
25
+	 *
26
+	 * @param array                 $report      Prepared report data.
27
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
28
+	 * @param bool                  $showSources Show sources?
29
+	 * @param int                   $width       Maximum allowed line width.
30
+	 *
31
+	 * @return bool
32
+	 */
33
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
+	{
35
+		if ($report['errors'] === 0 && $report['warnings'] === 0) {
36
+			// Nothing to print.
37
+			return false;
38
+		}
39
+
40
+		$sources = [];
41
+
42
+		foreach ($report['messages'] as $line => $lineErrors) {
43
+			foreach ($lineErrors as $column => $colErrors) {
44
+				foreach ($colErrors as $error) {
45
+					$src = $error['source'];
46
+					if (isset($sources[$src]) === false) {
47
+						$sources[$src] = [
48
+							'fixable' => (int) $error['fixable'],
49
+							'count'   => 1,
50
+						];
51
+					} else {
52
+						$sources[$src]['count']++;
53
+					}
54
+				}
55
+			}
56
+		}
57
+
58
+		foreach ($sources as $source => $data) {
59
+			echo $source.'>>'.$data['fixable'].'>>'.$data['count'].PHP_EOL;
60
+		}
61
+
62
+		return true;
63
+
64
+	}//end generateFileReport()
65
+
66
+
67
+	/**
68
+	 * Prints the source of all errors and warnings.
69
+	 *
70
+	 * @param string $cachedData    Any partial report data that was returned from
71
+	 *                              generateFileReport during the run.
72
+	 * @param int    $totalFiles    Total number of files processed during the run.
73
+	 * @param int    $totalErrors   Total number of errors found during the run.
74
+	 * @param int    $totalWarnings Total number of warnings found during the run.
75
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
76
+	 * @param bool   $showSources   Show sources?
77
+	 * @param int    $width         Maximum allowed line width.
78
+	 * @param bool   $interactive   Are we running in interactive mode?
79
+	 * @param bool   $toScreen      Is the report being printed to screen?
80
+	 *
81
+	 * @return void
82
+	 */
83
+	public function generate(
84
+		$cachedData,
85
+		$totalFiles,
86
+		$totalErrors,
87
+		$totalWarnings,
88
+		$totalFixable,
89
+		$showSources=false,
90
+		$width=80,
91
+		$interactive=false,
92
+		$toScreen=true
93
+	) {
94
+		$lines = explode(PHP_EOL, $cachedData);
95
+		array_pop($lines);
96
+
97
+		if (empty($lines) === true) {
98
+			return;
99
+		}
100
+
101
+		$sources   = [];
102
+		$maxLength = 0;
103
+
104
+		foreach ($lines as $line) {
105
+			$parts   = explode('>>', $line);
106
+			$source  = $parts[0];
107
+			$fixable = (bool) $parts[1];
108
+			$count   = $parts[2];
109
+
110
+			if (isset($sources[$source]) === false) {
111
+				if ($showSources === true) {
112
+					$parts = null;
113
+					$sniff = $source;
114
+				} else {
115
+					$parts = explode('.', $source);
116
+					if ($parts[0] === 'Internal') {
117
+						$parts[2] = $parts[1];
118
+						$parts[1] = '';
119
+					}
120
+
121
+					$parts[1] = $this->makeFriendlyName($parts[1]);
122
+
123
+					$sniff = $this->makeFriendlyName($parts[2]);
124
+					if (isset($parts[3]) === true) {
125
+						$name    = $this->makeFriendlyName($parts[3]);
126
+						$name[0] = strtolower($name[0]);
127
+						$sniff  .= ' '.$name;
128
+						unset($parts[3]);
129
+					}
130
+
131
+					$parts[2] = $sniff;
132
+				}//end if
133
+
134
+				$maxLength = max($maxLength, strlen($sniff));
135
+
136
+				$sources[$source] = [
137
+					'count'   => $count,
138
+					'fixable' => $fixable,
139
+					'parts'   => $parts,
140
+				];
141
+			} else {
142
+				$sources[$source]['count'] += $count;
143
+			}//end if
144
+		}//end foreach
145
+
146
+		if ($showSources === true) {
147
+			$width = min($width, ($maxLength + 11));
148
+		} else {
149
+			$width = min($width, ($maxLength + 41));
150
+		}
151
+
152
+		$width = max($width, 70);
153
+
154
+		// Sort the data based on counts and source code.
155
+		$sourceCodes = array_keys($sources);
156
+		$counts      = [];
157
+		foreach ($sources as $source => $data) {
158
+			$counts[$source] = $data['count'];
159
+		}
160
+
161
+		array_multisort($counts, SORT_DESC, $sourceCodes, SORT_ASC, SORT_NATURAL, $sources);
162
+
163
+		echo PHP_EOL."\033[1mPHP CODE SNIFFER VIOLATION SOURCE SUMMARY\033[0m".PHP_EOL;
164
+		echo str_repeat('-', $width).PHP_EOL."\033[1m";
165
+		if ($showSources === true) {
166
+			if ($totalFixable > 0) {
167
+				echo '    SOURCE'.str_repeat(' ', ($width - 15)).'COUNT'.PHP_EOL;
168
+			} else {
169
+				echo 'SOURCE'.str_repeat(' ', ($width - 11)).'COUNT'.PHP_EOL;
170
+			}
171
+		} else {
172
+			if ($totalFixable > 0) {
173
+				echo '    STANDARD  CATEGORY            SNIFF'.str_repeat(' ', ($width - 44)).'COUNT'.PHP_EOL;
174
+			} else {
175
+				echo 'STANDARD  CATEGORY            SNIFF'.str_repeat(' ', ($width - 40)).'COUNT'.PHP_EOL;
176
+			}
177
+		}
178
+
179
+		echo "\033[0m".str_repeat('-', $width).PHP_EOL;
180
+
181
+		$fixableSources = 0;
182
+
183
+		if ($showSources === true) {
184
+			$maxSniffWidth = ($width - 7);
185
+		} else {
186
+			$maxSniffWidth = ($width - 37);
187
+		}
188
+
189
+		if ($totalFixable > 0) {
190
+			$maxSniffWidth -= 4;
191
+		}
192
+
193
+		foreach ($sources as $source => $sourceData) {
194
+			if ($totalFixable > 0) {
195
+				echo '[';
196
+				if ($sourceData['fixable'] === true) {
197
+					echo 'x';
198
+					$fixableSources++;
199
+				} else {
200
+					echo ' ';
201
+				}
202
+
203
+				echo '] ';
204
+			}
205
+
206
+			if ($showSources === true) {
207
+				if (strlen($source) > $maxSniffWidth) {
208
+					$source = substr($source, 0, $maxSniffWidth);
209
+				}
210
+
211
+				echo $source;
212
+				if ($totalFixable > 0) {
213
+					echo str_repeat(' ', ($width - 9 - strlen($source)));
214
+				} else {
215
+					echo str_repeat(' ', ($width - 5 - strlen($source)));
216
+				}
217
+			} else {
218
+				$parts = $sourceData['parts'];
219
+
220
+				if (strlen($parts[0]) > 8) {
221
+					$parts[0] = substr($parts[0], 0, ((strlen($parts[0]) - 8) * -1));
222
+				}
223
+
224
+				echo $parts[0].str_repeat(' ', (10 - strlen($parts[0])));
225
+
226
+				$category = $parts[1];
227
+				if (strlen($category) > 18) {
228
+					$category = substr($category, 0, ((strlen($category) - 18) * -1));
229
+				}
230
+
231
+				echo $category.str_repeat(' ', (20 - strlen($category)));
232
+
233
+				$sniff = $parts[2];
234
+				if (strlen($sniff) > $maxSniffWidth) {
235
+					$sniff = substr($sniff, 0, $maxSniffWidth);
236
+				}
237
+
238
+				if ($totalFixable > 0) {
239
+					echo $sniff.str_repeat(' ', ($width - 39 - strlen($sniff)));
240
+				} else {
241
+					echo $sniff.str_repeat(' ', ($width - 35 - strlen($sniff)));
242
+				}
243
+			}//end if
244
+
245
+			echo $sourceData['count'].PHP_EOL;
246
+		}//end foreach
247
+
248
+		echo str_repeat('-', $width).PHP_EOL;
249
+		echo "\033[1m".'A TOTAL OF '.($totalErrors + $totalWarnings).' SNIFF VIOLATION';
250
+		if (($totalErrors + $totalWarnings) > 1) {
251
+			echo 'S';
252
+		}
253
+
254
+		echo ' WERE FOUND IN '.count($sources).' SOURCE';
255
+		if (count($sources) !== 1) {
256
+			echo 'S';
257
+		}
258
+
259
+		echo "\033[0m";
260
+
261
+		if ($totalFixable > 0) {
262
+			echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
263
+			echo "\033[1mPHPCBF CAN FIX THE $fixableSources MARKED SOURCES AUTOMATICALLY ($totalFixable VIOLATIONS IN TOTAL)\033[0m";
264
+		}
265
+
266
+		echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
267
+
268
+		if ($toScreen === true && $interactive === false) {
269
+			Timing::printRunTime();
270
+		}
271
+
272
+	}//end generate()
273
+
274
+
275
+	/**
276
+	 * Converts a camel caps name into a readable string.
277
+	 *
278
+	 * @param string $name The camel caps name to convert.
279
+	 *
280
+	 * @return string
281
+	 */
282
+	public function makeFriendlyName($name)
283
+	{
284
+		if (trim($name) === '') {
285
+			return '';
286
+		}
287
+
288
+		$friendlyName = '';
289
+		$length       = strlen($name);
290
+
291
+		$lastWasUpper   = false;
292
+		$lastWasNumeric = false;
293
+		for ($i = 0; $i < $length; $i++) {
294
+			if (is_numeric($name[$i]) === true) {
295
+				if ($lastWasNumeric === false) {
296
+					$friendlyName .= ' ';
297
+				}
298
+
299
+				$lastWasUpper   = false;
300
+				$lastWasNumeric = true;
301
+			} else {
302
+				$lastWasNumeric = false;
303
+
304
+				$char = strtolower($name[$i]);
305
+				if ($char === $name[$i]) {
306
+					// Lowercase.
307
+					$lastWasUpper = false;
308
+				} else {
309
+					// Uppercase.
310
+					if ($lastWasUpper === false) {
311
+						$friendlyName .= ' ';
312
+						if ($i < ($length - 1)) {
313
+							$next = $name[($i + 1)];
314
+							if (strtolower($next) === $next) {
315
+								// Next char is lowercase so it is a word boundary.
316
+								$name[$i] = strtolower($name[$i]);
317
+							}
318
+						}
319
+					}
320
+
321
+					$lastWasUpper = true;
322
+				}
323
+			}//end if
324
+
325
+			$friendlyName .= $name[$i];
326
+		}//end for
327
+
328
+		$friendlyName    = trim($friendlyName);
329
+		$friendlyName[0] = strtoupper($friendlyName[0]);
330
+
331
+		return $friendlyName;
332
+
333
+	}//end makeFriendlyName()
334 334
 
335 335
 
336 336
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Notifysend.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
      *
95 95
      * @return bool
96 96
      */
97
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
97
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
98 98
     {
99 99
         echo $report['filename'].PHP_EOL;
100 100
 
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
         $totalErrors,
128 128
         $totalWarnings,
129 129
         $totalFixable,
130
-        $showSources=false,
131
-        $width=80,
132
-        $interactive=false,
133
-        $toScreen=true
130
+        $showSources = false,
131
+        $width = 80,
132
+        $interactive = false,
133
+        $toScreen = true
134 134
     ) {
135 135
         $checkedFiles = explode(PHP_EOL, trim($cachedData));
136 136
 
Please login to merge, or discard this patch.
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -23,220 +23,220 @@
 block discarded – undo
23 23
 class Notifysend implements Report
24 24
 {
25 25
 
26
-    /**
27
-     * Notification timeout in milliseconds.
28
-     *
29
-     * @var integer
30
-     */
31
-    protected $timeout = 3000;
32
-
33
-    /**
34
-     * Path to notify-send command.
35
-     *
36
-     * @var string
37
-     */
38
-    protected $path = 'notify-send';
39
-
40
-    /**
41
-     * Show "ok, all fine" messages.
42
-     *
43
-     * @var boolean
44
-     */
45
-    protected $showOk = true;
46
-
47
-    /**
48
-     * Version of installed notify-send executable.
49
-     *
50
-     * @var string
51
-     */
52
-    protected $version = null;
53
-
54
-
55
-    /**
56
-     * Load configuration data.
57
-     */
58
-    public function __construct()
59
-    {
60
-        $path = Config::getExecutablePath('notifysend');
61
-        if ($path !== null) {
62
-            $this->path = Common::escapeshellcmd($path);
63
-        }
64
-
65
-        $timeout = Config::getConfigData('notifysend_timeout');
66
-        if ($timeout !== null) {
67
-            $this->timeout = (int) $timeout;
68
-        }
69
-
70
-        $showOk = Config::getConfigData('notifysend_showok');
71
-        if ($showOk !== null) {
72
-            $this->showOk = (bool) $showOk;
73
-        }
74
-
75
-        $this->version = str_replace(
76
-            'notify-send ',
77
-            '',
78
-            exec($this->path.' --version')
79
-        );
80
-
81
-    }//end __construct()
82
-
83
-
84
-    /**
85
-     * Generate a partial report for a single processed file.
86
-     *
87
-     * Function should return TRUE if it printed or stored data about the file
88
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
89
-     * its data should be counted in the grand totals.
90
-     *
91
-     * @param array                 $report      Prepared report data.
92
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
93
-     * @param bool                  $showSources Show sources?
94
-     * @param int                   $width       Maximum allowed line width.
95
-     *
96
-     * @return bool
97
-     */
98
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
99
-    {
100
-        echo $report['filename'].PHP_EOL;
101
-
102
-        // We want this file counted in the total number
103
-        // of checked files even if it has no errors.
104
-        return true;
105
-
106
-    }//end generateFileReport()
107
-
108
-
109
-    /**
110
-     * Generates a summary of errors and warnings for each file processed.
111
-     *
112
-     * @param string $cachedData    Any partial report data that was returned from
113
-     *                              generateFileReport during the run.
114
-     * @param int    $totalFiles    Total number of files processed during the run.
115
-     * @param int    $totalErrors   Total number of errors found during the run.
116
-     * @param int    $totalWarnings Total number of warnings found during the run.
117
-     * @param int    $totalFixable  Total number of problems that can be fixed.
118
-     * @param bool   $showSources   Show sources?
119
-     * @param int    $width         Maximum allowed line width.
120
-     * @param bool   $interactive   Are we running in interactive mode?
121
-     * @param bool   $toScreen      Is the report being printed to screen?
122
-     *
123
-     * @return void
124
-     */
125
-    public function generate(
126
-        $cachedData,
127
-        $totalFiles,
128
-        $totalErrors,
129
-        $totalWarnings,
130
-        $totalFixable,
131
-        $showSources=false,
132
-        $width=80,
133
-        $interactive=false,
134
-        $toScreen=true
135
-    ) {
136
-        $checkedFiles = explode(PHP_EOL, trim($cachedData));
137
-
138
-        $msg = $this->generateMessage($checkedFiles, $totalErrors, $totalWarnings);
139
-        if ($msg === null) {
140
-            if ($this->showOk === true) {
141
-                $this->notifyAllFine();
142
-            }
143
-        } else {
144
-            $this->notifyErrors($msg);
145
-        }
146
-
147
-    }//end generate()
148
-
149
-
150
-    /**
151
-     * Generate the error message to show to the user.
152
-     *
153
-     * @param string[] $checkedFiles  The files checked during the run.
154
-     * @param int      $totalErrors   Total number of errors found during the run.
155
-     * @param int      $totalWarnings Total number of warnings found during the run.
156
-     *
157
-     * @return string Error message or NULL if no error/warning found.
158
-     */
159
-    protected function generateMessage($checkedFiles, $totalErrors, $totalWarnings)
160
-    {
161
-        if ($totalErrors === 0 && $totalWarnings === 0) {
162
-            // Nothing to print.
163
-            return null;
164
-        }
165
-
166
-        $totalFiles = count($checkedFiles);
167
-
168
-        $msg = '';
169
-        if ($totalFiles > 1) {
170
-            $msg .= 'Checked '.$totalFiles.' files'.PHP_EOL;
171
-        } else {
172
-            $msg .= $checkedFiles[0].PHP_EOL;
173
-        }
174
-
175
-        if ($totalWarnings > 0) {
176
-            $msg .= $totalWarnings.' warnings'.PHP_EOL;
177
-        }
178
-
179
-        if ($totalErrors > 0) {
180
-            $msg .= $totalErrors.' errors'.PHP_EOL;
181
-        }
182
-
183
-        return $msg;
184
-
185
-    }//end generateMessage()
186
-
187
-
188
-    /**
189
-     * Tell the user that all is fine and no error/warning has been found.
190
-     *
191
-     * @return void
192
-     */
193
-    protected function notifyAllFine()
194
-    {
195
-        $cmd  = $this->getBasicCommand();
196
-        $cmd .= ' -i info';
197
-        $cmd .= ' "PHP CodeSniffer: Ok"';
198
-        $cmd .= ' "All fine"';
199
-        exec($cmd);
200
-
201
-    }//end notifyAllFine()
202
-
203
-
204
-    /**
205
-     * Tell the user that errors/warnings have been found.
206
-     *
207
-     * @param string $msg Message to display.
208
-     *
209
-     * @return void
210
-     */
211
-    protected function notifyErrors($msg)
212
-    {
213
-        $cmd  = $this->getBasicCommand();
214
-        $cmd .= ' -i error';
215
-        $cmd .= ' "PHP CodeSniffer: Error"';
216
-        $cmd .= ' '.escapeshellarg(trim($msg));
217
-        exec($cmd);
218
-
219
-    }//end notifyErrors()
220
-
221
-
222
-    /**
223
-     * Generate and return the basic notify-send command string to execute.
224
-     *
225
-     * @return string Shell command with common parameters.
226
-     */
227
-    protected function getBasicCommand()
228
-    {
229
-        $cmd  = $this->path;
230
-        $cmd .= ' --category dev.validate';
231
-        $cmd .= ' -h int:transient:1';
232
-        $cmd .= ' -t '.(int) $this->timeout;
233
-        if (version_compare($this->version, '0.7.3', '>=') === true) {
234
-            $cmd .= ' -a phpcs';
235
-        }
236
-
237
-        return $cmd;
238
-
239
-    }//end getBasicCommand()
26
+	/**
27
+	 * Notification timeout in milliseconds.
28
+	 *
29
+	 * @var integer
30
+	 */
31
+	protected $timeout = 3000;
32
+
33
+	/**
34
+	 * Path to notify-send command.
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $path = 'notify-send';
39
+
40
+	/**
41
+	 * Show "ok, all fine" messages.
42
+	 *
43
+	 * @var boolean
44
+	 */
45
+	protected $showOk = true;
46
+
47
+	/**
48
+	 * Version of installed notify-send executable.
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $version = null;
53
+
54
+
55
+	/**
56
+	 * Load configuration data.
57
+	 */
58
+	public function __construct()
59
+	{
60
+		$path = Config::getExecutablePath('notifysend');
61
+		if ($path !== null) {
62
+			$this->path = Common::escapeshellcmd($path);
63
+		}
64
+
65
+		$timeout = Config::getConfigData('notifysend_timeout');
66
+		if ($timeout !== null) {
67
+			$this->timeout = (int) $timeout;
68
+		}
69
+
70
+		$showOk = Config::getConfigData('notifysend_showok');
71
+		if ($showOk !== null) {
72
+			$this->showOk = (bool) $showOk;
73
+		}
74
+
75
+		$this->version = str_replace(
76
+			'notify-send ',
77
+			'',
78
+			exec($this->path.' --version')
79
+		);
80
+
81
+	}//end __construct()
82
+
83
+
84
+	/**
85
+	 * Generate a partial report for a single processed file.
86
+	 *
87
+	 * Function should return TRUE if it printed or stored data about the file
88
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
89
+	 * its data should be counted in the grand totals.
90
+	 *
91
+	 * @param array                 $report      Prepared report data.
92
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
93
+	 * @param bool                  $showSources Show sources?
94
+	 * @param int                   $width       Maximum allowed line width.
95
+	 *
96
+	 * @return bool
97
+	 */
98
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
99
+	{
100
+		echo $report['filename'].PHP_EOL;
101
+
102
+		// We want this file counted in the total number
103
+		// of checked files even if it has no errors.
104
+		return true;
105
+
106
+	}//end generateFileReport()
107
+
108
+
109
+	/**
110
+	 * Generates a summary of errors and warnings for each file processed.
111
+	 *
112
+	 * @param string $cachedData    Any partial report data that was returned from
113
+	 *                              generateFileReport during the run.
114
+	 * @param int    $totalFiles    Total number of files processed during the run.
115
+	 * @param int    $totalErrors   Total number of errors found during the run.
116
+	 * @param int    $totalWarnings Total number of warnings found during the run.
117
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
118
+	 * @param bool   $showSources   Show sources?
119
+	 * @param int    $width         Maximum allowed line width.
120
+	 * @param bool   $interactive   Are we running in interactive mode?
121
+	 * @param bool   $toScreen      Is the report being printed to screen?
122
+	 *
123
+	 * @return void
124
+	 */
125
+	public function generate(
126
+		$cachedData,
127
+		$totalFiles,
128
+		$totalErrors,
129
+		$totalWarnings,
130
+		$totalFixable,
131
+		$showSources=false,
132
+		$width=80,
133
+		$interactive=false,
134
+		$toScreen=true
135
+	) {
136
+		$checkedFiles = explode(PHP_EOL, trim($cachedData));
137
+
138
+		$msg = $this->generateMessage($checkedFiles, $totalErrors, $totalWarnings);
139
+		if ($msg === null) {
140
+			if ($this->showOk === true) {
141
+				$this->notifyAllFine();
142
+			}
143
+		} else {
144
+			$this->notifyErrors($msg);
145
+		}
146
+
147
+	}//end generate()
148
+
149
+
150
+	/**
151
+	 * Generate the error message to show to the user.
152
+	 *
153
+	 * @param string[] $checkedFiles  The files checked during the run.
154
+	 * @param int      $totalErrors   Total number of errors found during the run.
155
+	 * @param int      $totalWarnings Total number of warnings found during the run.
156
+	 *
157
+	 * @return string Error message or NULL if no error/warning found.
158
+	 */
159
+	protected function generateMessage($checkedFiles, $totalErrors, $totalWarnings)
160
+	{
161
+		if ($totalErrors === 0 && $totalWarnings === 0) {
162
+			// Nothing to print.
163
+			return null;
164
+		}
165
+
166
+		$totalFiles = count($checkedFiles);
167
+
168
+		$msg = '';
169
+		if ($totalFiles > 1) {
170
+			$msg .= 'Checked '.$totalFiles.' files'.PHP_EOL;
171
+		} else {
172
+			$msg .= $checkedFiles[0].PHP_EOL;
173
+		}
174
+
175
+		if ($totalWarnings > 0) {
176
+			$msg .= $totalWarnings.' warnings'.PHP_EOL;
177
+		}
178
+
179
+		if ($totalErrors > 0) {
180
+			$msg .= $totalErrors.' errors'.PHP_EOL;
181
+		}
182
+
183
+		return $msg;
184
+
185
+	}//end generateMessage()
186
+
187
+
188
+	/**
189
+	 * Tell the user that all is fine and no error/warning has been found.
190
+	 *
191
+	 * @return void
192
+	 */
193
+	protected function notifyAllFine()
194
+	{
195
+		$cmd  = $this->getBasicCommand();
196
+		$cmd .= ' -i info';
197
+		$cmd .= ' "PHP CodeSniffer: Ok"';
198
+		$cmd .= ' "All fine"';
199
+		exec($cmd);
200
+
201
+	}//end notifyAllFine()
202
+
203
+
204
+	/**
205
+	 * Tell the user that errors/warnings have been found.
206
+	 *
207
+	 * @param string $msg Message to display.
208
+	 *
209
+	 * @return void
210
+	 */
211
+	protected function notifyErrors($msg)
212
+	{
213
+		$cmd  = $this->getBasicCommand();
214
+		$cmd .= ' -i error';
215
+		$cmd .= ' "PHP CodeSniffer: Error"';
216
+		$cmd .= ' '.escapeshellarg(trim($msg));
217
+		exec($cmd);
218
+
219
+	}//end notifyErrors()
220
+
221
+
222
+	/**
223
+	 * Generate and return the basic notify-send command string to execute.
224
+	 *
225
+	 * @return string Shell command with common parameters.
226
+	 */
227
+	protected function getBasicCommand()
228
+	{
229
+		$cmd  = $this->path;
230
+		$cmd .= ' --category dev.validate';
231
+		$cmd .= ' -h int:transient:1';
232
+		$cmd .= ' -t '.(int) $this->timeout;
233
+		if (version_compare($this->version, '0.7.3', '>=') === true) {
234
+			$cmd .= ' -a phpcs';
235
+		}
236
+
237
+		return $cmd;
238
+
239
+	}//end getBasicCommand()
240 240
 
241 241
 
242 242
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Json.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @return bool
32 32
      */
33
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
33
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
34 34
     {
35 35
         $filename = str_replace('\\', '\\\\', $report['filename']);
36 36
         $filename = str_replace('"', '\"', $filename);
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
         $totalErrors,
97 97
         $totalWarnings,
98 98
         $totalFixable,
99
-        $showSources=false,
100
-        $width=80,
101
-        $interactive=false,
102
-        $toScreen=true
99
+        $showSources = false,
100
+        $width = 80,
101
+        $interactive = false,
102
+        $toScreen = true
103 103
     ) {
104 104
         echo '{"totals":{"errors":'.$totalErrors.',"warnings":'.$totalWarnings.',"fixable":'.$totalFixable.'},"files":{';
105 105
         echo rtrim($cachedData, ',');
Please login to merge, or discard this patch.
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -16,91 +16,91 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Generate a partial report for a single processed file.
21
-     *
22
-     * Function should return TRUE if it printed or stored data about the file
23
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
-     * its data should be counted in the grand totals.
25
-     *
26
-     * @param array                 $report      Prepared report data.
27
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
28
-     * @param bool                  $showSources Show sources?
29
-     * @param int                   $width       Maximum allowed line width.
30
-     *
31
-     * @return bool
32
-     */
33
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
-    {
35
-        $filename = str_replace('\\', '\\\\', $report['filename']);
36
-        $filename = str_replace('"', '\"', $filename);
37
-        $filename = str_replace('/', '\/', $filename);
38
-        echo '"'.$filename.'":{';
39
-        echo '"errors":'.$report['errors'].',"warnings":'.$report['warnings'].',"messages":[';
40
-
41
-        $messages = '';
42
-        foreach ($report['messages'] as $line => $lineErrors) {
43
-            foreach ($lineErrors as $column => $colErrors) {
44
-                foreach ($colErrors as $error) {
45
-                    $error['message'] = str_replace("\n", '\n', $error['message']);
46
-                    $error['message'] = str_replace("\r", '\r', $error['message']);
47
-                    $error['message'] = str_replace("\t", '\t', $error['message']);
48
-
49
-                    $fixable = false;
50
-                    if ($error['fixable'] === true) {
51
-                        $fixable = true;
52
-                    }
53
-
54
-                    $messagesObject          = (object) $error;
55
-                    $messagesObject->line    = $line;
56
-                    $messagesObject->column  = $column;
57
-                    $messagesObject->fixable = $fixable;
58
-
59
-                    $messages .= json_encode($messagesObject).",";
60
-                }
61
-            }
62
-        }//end foreach
63
-
64
-        echo rtrim($messages, ',');
65
-        echo ']},';
66
-
67
-        return true;
68
-
69
-    }//end generateFileReport()
70
-
71
-
72
-    /**
73
-     * Generates a JSON report.
74
-     *
75
-     * @param string $cachedData    Any partial report data that was returned from
76
-     *                              generateFileReport during the run.
77
-     * @param int    $totalFiles    Total number of files processed during the run.
78
-     * @param int    $totalErrors   Total number of errors found during the run.
79
-     * @param int    $totalWarnings Total number of warnings found during the run.
80
-     * @param int    $totalFixable  Total number of problems that can be fixed.
81
-     * @param bool   $showSources   Show sources?
82
-     * @param int    $width         Maximum allowed line width.
83
-     * @param bool   $interactive   Are we running in interactive mode?
84
-     * @param bool   $toScreen      Is the report being printed to screen?
85
-     *
86
-     * @return void
87
-     */
88
-    public function generate(
89
-        $cachedData,
90
-        $totalFiles,
91
-        $totalErrors,
92
-        $totalWarnings,
93
-        $totalFixable,
94
-        $showSources=false,
95
-        $width=80,
96
-        $interactive=false,
97
-        $toScreen=true
98
-    ) {
99
-        echo '{"totals":{"errors":'.$totalErrors.',"warnings":'.$totalWarnings.',"fixable":'.$totalFixable.'},"files":{';
100
-        echo rtrim($cachedData, ',');
101
-        echo "}}".PHP_EOL;
102
-
103
-    }//end generate()
19
+	/**
20
+	 * Generate a partial report for a single processed file.
21
+	 *
22
+	 * Function should return TRUE if it printed or stored data about the file
23
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
+	 * its data should be counted in the grand totals.
25
+	 *
26
+	 * @param array                 $report      Prepared report data.
27
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
28
+	 * @param bool                  $showSources Show sources?
29
+	 * @param int                   $width       Maximum allowed line width.
30
+	 *
31
+	 * @return bool
32
+	 */
33
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
+	{
35
+		$filename = str_replace('\\', '\\\\', $report['filename']);
36
+		$filename = str_replace('"', '\"', $filename);
37
+		$filename = str_replace('/', '\/', $filename);
38
+		echo '"'.$filename.'":{';
39
+		echo '"errors":'.$report['errors'].',"warnings":'.$report['warnings'].',"messages":[';
40
+
41
+		$messages = '';
42
+		foreach ($report['messages'] as $line => $lineErrors) {
43
+			foreach ($lineErrors as $column => $colErrors) {
44
+				foreach ($colErrors as $error) {
45
+					$error['message'] = str_replace("\n", '\n', $error['message']);
46
+					$error['message'] = str_replace("\r", '\r', $error['message']);
47
+					$error['message'] = str_replace("\t", '\t', $error['message']);
48
+
49
+					$fixable = false;
50
+					if ($error['fixable'] === true) {
51
+						$fixable = true;
52
+					}
53
+
54
+					$messagesObject          = (object) $error;
55
+					$messagesObject->line    = $line;
56
+					$messagesObject->column  = $column;
57
+					$messagesObject->fixable = $fixable;
58
+
59
+					$messages .= json_encode($messagesObject).",";
60
+				}
61
+			}
62
+		}//end foreach
63
+
64
+		echo rtrim($messages, ',');
65
+		echo ']},';
66
+
67
+		return true;
68
+
69
+	}//end generateFileReport()
70
+
71
+
72
+	/**
73
+	 * Generates a JSON report.
74
+	 *
75
+	 * @param string $cachedData    Any partial report data that was returned from
76
+	 *                              generateFileReport during the run.
77
+	 * @param int    $totalFiles    Total number of files processed during the run.
78
+	 * @param int    $totalErrors   Total number of errors found during the run.
79
+	 * @param int    $totalWarnings Total number of warnings found during the run.
80
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
81
+	 * @param bool   $showSources   Show sources?
82
+	 * @param int    $width         Maximum allowed line width.
83
+	 * @param bool   $interactive   Are we running in interactive mode?
84
+	 * @param bool   $toScreen      Is the report being printed to screen?
85
+	 *
86
+	 * @return void
87
+	 */
88
+	public function generate(
89
+		$cachedData,
90
+		$totalFiles,
91
+		$totalErrors,
92
+		$totalWarnings,
93
+		$totalFixable,
94
+		$showSources=false,
95
+		$width=80,
96
+		$interactive=false,
97
+		$toScreen=true
98
+	) {
99
+		echo '{"totals":{"errors":'.$totalErrors.',"warnings":'.$totalWarnings.',"fixable":'.$totalFixable.'},"files":{';
100
+		echo rtrim($cachedData, ',');
101
+		echo "}}".PHP_EOL;
102
+
103
+	}//end generate()
104 104
 
105 105
 
106 106
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Csv.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -15,77 +15,77 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Generate a partial report for a single processed file.
20
-     *
21
-     * Function should return TRUE if it printed or stored data about the file
22
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
23
-     * its data should be counted in the grand totals.
24
-     *
25
-     * @param array                 $report      Prepared report data.
26
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
27
-     * @param bool                  $showSources Show sources?
28
-     * @param int                   $width       Maximum allowed line width.
29
-     *
30
-     * @return bool
31
-     */
32
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
33
-    {
34
-        if ($report['errors'] === 0 && $report['warnings'] === 0) {
35
-            // Nothing to print.
36
-            return false;
37
-        }
18
+	/**
19
+	 * Generate a partial report for a single processed file.
20
+	 *
21
+	 * Function should return TRUE if it printed or stored data about the file
22
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
23
+	 * its data should be counted in the grand totals.
24
+	 *
25
+	 * @param array                 $report      Prepared report data.
26
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
27
+	 * @param bool                  $showSources Show sources?
28
+	 * @param int                   $width       Maximum allowed line width.
29
+	 *
30
+	 * @return bool
31
+	 */
32
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
33
+	{
34
+		if ($report['errors'] === 0 && $report['warnings'] === 0) {
35
+			// Nothing to print.
36
+			return false;
37
+		}
38 38
 
39
-        foreach ($report['messages'] as $line => $lineErrors) {
40
-            foreach ($lineErrors as $column => $colErrors) {
41
-                foreach ($colErrors as $error) {
42
-                    $filename = str_replace('"', '\"', $report['filename']);
43
-                    $message  = str_replace('"', '\"', $error['message']);
44
-                    $type     = strtolower($error['type']);
45
-                    $source   = $error['source'];
46
-                    $severity = $error['severity'];
47
-                    $fixable  = (int) $error['fixable'];
48
-                    echo "\"$filename\",$line,$column,$type,\"$message\",$source,$severity,$fixable".PHP_EOL;
49
-                }
50
-            }
51
-        }
39
+		foreach ($report['messages'] as $line => $lineErrors) {
40
+			foreach ($lineErrors as $column => $colErrors) {
41
+				foreach ($colErrors as $error) {
42
+					$filename = str_replace('"', '\"', $report['filename']);
43
+					$message  = str_replace('"', '\"', $error['message']);
44
+					$type     = strtolower($error['type']);
45
+					$source   = $error['source'];
46
+					$severity = $error['severity'];
47
+					$fixable  = (int) $error['fixable'];
48
+					echo "\"$filename\",$line,$column,$type,\"$message\",$source,$severity,$fixable".PHP_EOL;
49
+				}
50
+			}
51
+		}
52 52
 
53
-        return true;
53
+		return true;
54 54
 
55
-    }//end generateFileReport()
55
+	}//end generateFileReport()
56 56
 
57 57
 
58
-    /**
59
-     * Generates a csv report.
60
-     *
61
-     * @param string $cachedData    Any partial report data that was returned from
62
-     *                              generateFileReport during the run.
63
-     * @param int    $totalFiles    Total number of files processed during the run.
64
-     * @param int    $totalErrors   Total number of errors found during the run.
65
-     * @param int    $totalWarnings Total number of warnings found during the run.
66
-     * @param int    $totalFixable  Total number of problems that can be fixed.
67
-     * @param bool   $showSources   Show sources?
68
-     * @param int    $width         Maximum allowed line width.
69
-     * @param bool   $interactive   Are we running in interactive mode?
70
-     * @param bool   $toScreen      Is the report being printed to screen?
71
-     *
72
-     * @return void
73
-     */
74
-    public function generate(
75
-        $cachedData,
76
-        $totalFiles,
77
-        $totalErrors,
78
-        $totalWarnings,
79
-        $totalFixable,
80
-        $showSources=false,
81
-        $width=80,
82
-        $interactive=false,
83
-        $toScreen=true
84
-    ) {
85
-        echo 'File,Line,Column,Type,Message,Source,Severity,Fixable'.PHP_EOL;
86
-        echo $cachedData;
58
+	/**
59
+	 * Generates a csv report.
60
+	 *
61
+	 * @param string $cachedData    Any partial report data that was returned from
62
+	 *                              generateFileReport during the run.
63
+	 * @param int    $totalFiles    Total number of files processed during the run.
64
+	 * @param int    $totalErrors   Total number of errors found during the run.
65
+	 * @param int    $totalWarnings Total number of warnings found during the run.
66
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
67
+	 * @param bool   $showSources   Show sources?
68
+	 * @param int    $width         Maximum allowed line width.
69
+	 * @param bool   $interactive   Are we running in interactive mode?
70
+	 * @param bool   $toScreen      Is the report being printed to screen?
71
+	 *
72
+	 * @return void
73
+	 */
74
+	public function generate(
75
+		$cachedData,
76
+		$totalFiles,
77
+		$totalErrors,
78
+		$totalWarnings,
79
+		$totalFixable,
80
+		$showSources=false,
81
+		$width=80,
82
+		$interactive=false,
83
+		$toScreen=true
84
+	) {
85
+		echo 'File,Line,Column,Type,Message,Source,Severity,Fixable'.PHP_EOL;
86
+		echo $cachedData;
87 87
 
88
-    }//end generate()
88
+	}//end generate()
89 89
 
90 90
 
91 91
 }//end class
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      *
30 30
      * @return bool
31 31
      */
32
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
32
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
33 33
     {
34 34
         if ($report['errors'] === 0 && $report['warnings'] === 0) {
35 35
             // Nothing to print.
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
         $totalErrors,
78 78
         $totalWarnings,
79 79
         $totalFixable,
80
-        $showSources=false,
81
-        $width=80,
82
-        $interactive=false,
83
-        $toScreen=true
80
+        $showSources = false,
81
+        $width = 80,
82
+        $interactive = false,
83
+        $toScreen = true
84 84
     ) {
85 85
         echo 'File,Line,Column,Type,Message,Source,Severity,Fixable'.PHP_EOL;
86 86
         echo $cachedData;
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Code.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @return bool
32 32
      */
33
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
33
+    public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80)
34 34
     {
35 35
         if ($report['errors'] === 0 && $report['warnings'] === 0) {
36 36
             // Nothing to print.
@@ -341,10 +341,10 @@  discard block
 block discarded – undo
341 341
         $totalErrors,
342 342
         $totalWarnings,
343 343
         $totalFixable,
344
-        $showSources=false,
345
-        $width=80,
346
-        $interactive=false,
347
-        $toScreen=true
344
+        $showSources = false,
345
+        $width = 80,
346
+        $interactive = false,
347
+        $toScreen = true
348 348
     ) {
349 349
         if ($cachedData === '') {
350 350
             return;
Please login to merge, or discard this patch.
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -16,347 +16,347 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Generate a partial report for a single processed file.
21
-     *
22
-     * Function should return TRUE if it printed or stored data about the file
23
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
-     * its data should be counted in the grand totals.
25
-     *
26
-     * @param array                 $report      Prepared report data.
27
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
28
-     * @param bool                  $showSources Show sources?
29
-     * @param int                   $width       Maximum allowed line width.
30
-     *
31
-     * @return bool
32
-     */
33
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
-    {
35
-        if ($report['errors'] === 0 && $report['warnings'] === 0) {
36
-            // Nothing to print.
37
-            return false;
38
-        }
39
-
40
-        // How many lines to show about and below the error line.
41
-        $surroundingLines = 2;
42
-
43
-        $file   = $report['filename'];
44
-        $tokens = $phpcsFile->getTokens();
45
-        if (empty($tokens) === true) {
46
-            if (PHP_CODESNIFFER_VERBOSITY === 1) {
47
-                $startTime = microtime(true);
48
-                echo 'CODE report is parsing '.basename($file).' ';
49
-            } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
50
-                echo "CODE report is forcing parse of $file".PHP_EOL;
51
-            }
52
-
53
-            try {
54
-                $phpcsFile->parse();
55
-            } catch (\Exception $e) {
56
-                // This is a second parse, so ignore exceptions.
57
-                // They would have been added to the file's error list already.
58
-            }
59
-
60
-            if (PHP_CODESNIFFER_VERBOSITY === 1) {
61
-                $timeTaken = ((microtime(true) - $startTime) * 1000);
62
-                if ($timeTaken < 1000) {
63
-                    $timeTaken = round($timeTaken);
64
-                    echo "DONE in {$timeTaken}ms";
65
-                } else {
66
-                    $timeTaken = round(($timeTaken / 1000), 2);
67
-                    echo "DONE in $timeTaken secs";
68
-                }
69
-
70
-                echo PHP_EOL;
71
-            }
72
-
73
-            $tokens = $phpcsFile->getTokens();
74
-        }//end if
75
-
76
-        // Create an array that maps lines to the first token on the line.
77
-        $lineTokens = [];
78
-        $lastLine   = 0;
79
-        $stackPtr   = 0;
80
-        foreach ($tokens as $stackPtr => $token) {
81
-            if ($token['line'] !== $lastLine) {
82
-                if ($lastLine > 0) {
83
-                    $lineTokens[$lastLine]['end'] = ($stackPtr - 1);
84
-                }
85
-
86
-                $lastLine++;
87
-                $lineTokens[$lastLine] = [
88
-                    'start' => $stackPtr,
89
-                    'end'   => null,
90
-                ];
91
-            }
92
-        }
93
-
94
-        // Make sure the last token in the file sits on an imaginary
95
-        // last line so it is easier to generate code snippets at the
96
-        // end of the file.
97
-        $lineTokens[$lastLine]['end'] = $stackPtr;
98
-
99
-        // Determine the longest code line we will be showing.
100
-        $maxSnippetLength = 0;
101
-        $eolLen           = strlen($phpcsFile->eolChar);
102
-        foreach ($report['messages'] as $line => $lineErrors) {
103
-            $startLine = max(($line - $surroundingLines), 1);
104
-            $endLine   = min(($line + $surroundingLines), $lastLine);
105
-
106
-            $maxLineNumLength = strlen($endLine);
107
-
108
-            for ($i = $startLine; $i <= $endLine; $i++) {
109
-                if ($i === 1) {
110
-                    continue;
111
-                }
112
-
113
-                $lineLength       = ($tokens[($lineTokens[$i]['start'] - 1)]['column'] + $tokens[($lineTokens[$i]['start'] - 1)]['length'] - $eolLen);
114
-                $maxSnippetLength = max($lineLength, $maxSnippetLength);
115
-            }
116
-        }
117
-
118
-        $maxSnippetLength += ($maxLineNumLength + 8);
119
-
120
-        // Determine the longest error message we will be showing.
121
-        $maxErrorLength = 0;
122
-        foreach ($report['messages'] as $line => $lineErrors) {
123
-            foreach ($lineErrors as $column => $colErrors) {
124
-                foreach ($colErrors as $error) {
125
-                    $length = strlen($error['message']);
126
-                    if ($showSources === true) {
127
-                        $length += (strlen($error['source']) + 3);
128
-                    }
129
-
130
-                    $maxErrorLength = max($maxErrorLength, ($length + 1));
131
-                }
132
-            }
133
-        }
134
-
135
-        // The padding that all lines will require that are printing an error message overflow.
136
-        if ($report['warnings'] > 0) {
137
-            $typeLength = 7;
138
-        } else {
139
-            $typeLength = 5;
140
-        }
141
-
142
-        $errorPadding  = str_repeat(' ', ($maxLineNumLength + 7));
143
-        $errorPadding .= str_repeat(' ', $typeLength);
144
-        $errorPadding .= ' ';
145
-        if ($report['fixable'] > 0) {
146
-            $errorPadding .= '    ';
147
-        }
148
-
149
-        $errorPaddingLength = strlen($errorPadding);
150
-
151
-        // The maximum amount of space an error message can use.
152
-        $maxErrorSpace = ($width - $errorPaddingLength);
153
-        if ($showSources === true) {
154
-            // Account for the chars used to print colors.
155
-            $maxErrorSpace += 8;
156
-        }
157
-
158
-        // Figure out the max report width we need and can use.
159
-        $fileLength = strlen($file);
160
-        $maxWidth   = max(($fileLength + 6), ($maxErrorLength + $errorPaddingLength));
161
-        $width      = max(min($width, $maxWidth), $maxSnippetLength);
162
-        if ($width < 70) {
163
-            $width = 70;
164
-        }
165
-
166
-        // Print the file header.
167
-        echo PHP_EOL."\033[1mFILE: ";
168
-        if ($fileLength <= ($width - 6)) {
169
-            echo $file;
170
-        } else {
171
-            echo '...'.substr($file, ($fileLength - ($width - 6)));
172
-        }
173
-
174
-        echo "\033[0m".PHP_EOL;
175
-        echo str_repeat('-', $width).PHP_EOL;
176
-
177
-        echo "\033[1m".'FOUND '.$report['errors'].' ERROR';
178
-        if ($report['errors'] !== 1) {
179
-            echo 'S';
180
-        }
181
-
182
-        if ($report['warnings'] > 0) {
183
-            echo ' AND '.$report['warnings'].' WARNING';
184
-            if ($report['warnings'] !== 1) {
185
-                echo 'S';
186
-            }
187
-        }
188
-
189
-        echo ' AFFECTING '.count($report['messages']).' LINE';
190
-        if (count($report['messages']) !== 1) {
191
-            echo 'S';
192
-        }
193
-
194
-        echo "\033[0m".PHP_EOL;
195
-
196
-        foreach ($report['messages'] as $line => $lineErrors) {
197
-            $startLine = max(($line - $surroundingLines), 1);
198
-            $endLine   = min(($line + $surroundingLines), $lastLine);
199
-
200
-            $snippet = '';
201
-            if (isset($lineTokens[$startLine]) === true) {
202
-                for ($i = $lineTokens[$startLine]['start']; $i <= $lineTokens[$endLine]['end']; $i++) {
203
-                    $snippetLine = $tokens[$i]['line'];
204
-                    if ($lineTokens[$snippetLine]['start'] === $i) {
205
-                        // Starting a new line.
206
-                        if ($snippetLine === $line) {
207
-                            $snippet .= "\033[1m".'>> ';
208
-                        } else {
209
-                            $snippet .= '   ';
210
-                        }
211
-
212
-                        $snippet .= str_repeat(' ', ($maxLineNumLength - strlen($snippetLine)));
213
-                        $snippet .= $snippetLine.':  ';
214
-                        if ($snippetLine === $line) {
215
-                            $snippet .= "\033[0m";
216
-                        }
217
-                    }
218
-
219
-                    if (isset($tokens[$i]['orig_content']) === true) {
220
-                        $tokenContent = $tokens[$i]['orig_content'];
221
-                    } else {
222
-                        $tokenContent = $tokens[$i]['content'];
223
-                    }
224
-
225
-                    if (strpos($tokenContent, "\t") !== false) {
226
-                        $token            = $tokens[$i];
227
-                        $token['content'] = $tokenContent;
228
-                        if (stripos(PHP_OS, 'WIN') === 0) {
229
-                            $tab = "\000";
230
-                        } else {
231
-                            $tab = "\033[30;1m»\033[0m";
232
-                        }
233
-
234
-                        $phpcsFile->tokenizer->replaceTabsInToken($token, $tab, "\000");
235
-                        $tokenContent = $token['content'];
236
-                    }
237
-
238
-                    $tokenContent = Util\Common::prepareForOutput($tokenContent, ["\r", "\n", "\t"]);
239
-                    $tokenContent = str_replace("\000", ' ', $tokenContent);
240
-
241
-                    $underline = false;
242
-                    if ($snippetLine === $line && isset($lineErrors[$tokens[$i]['column']]) === true) {
243
-                        $underline = true;
244
-                    }
245
-
246
-                    // Underline invisible characters as well.
247
-                    if ($underline === true && trim($tokenContent) === '') {
248
-                        $snippet .= "\033[4m".' '."\033[0m".$tokenContent;
249
-                    } else {
250
-                        if ($underline === true) {
251
-                            $snippet .= "\033[4m";
252
-                        }
253
-
254
-                        $snippet .= $tokenContent;
255
-
256
-                        if ($underline === true) {
257
-                            $snippet .= "\033[0m";
258
-                        }
259
-                    }
260
-                }//end for
261
-            }//end if
262
-
263
-            echo str_repeat('-', $width).PHP_EOL;
264
-
265
-            foreach ($lineErrors as $column => $colErrors) {
266
-                foreach ($colErrors as $error) {
267
-                    $padding = ($maxLineNumLength - strlen($line));
268
-                    echo 'LINE '.str_repeat(' ', $padding).$line.': ';
269
-
270
-                    if ($error['type'] === 'ERROR') {
271
-                        echo "\033[31mERROR\033[0m";
272
-                        if ($report['warnings'] > 0) {
273
-                            echo '  ';
274
-                        }
275
-                    } else {
276
-                        echo "\033[33mWARNING\033[0m";
277
-                    }
278
-
279
-                    echo ' ';
280
-                    if ($report['fixable'] > 0) {
281
-                        echo '[';
282
-                        if ($error['fixable'] === true) {
283
-                            echo 'x';
284
-                        } else {
285
-                            echo ' ';
286
-                        }
287
-
288
-                        echo '] ';
289
-                    }
290
-
291
-                    $message = $error['message'];
292
-                    $message = str_replace("\n", "\n".$errorPadding, $message);
293
-                    if ($showSources === true) {
294
-                        $message = "\033[1m".$message."\033[0m".' ('.$error['source'].')';
295
-                    }
296
-
297
-                    $errorMsg = wordwrap(
298
-                        $message,
299
-                        $maxErrorSpace,
300
-                        PHP_EOL.$errorPadding
301
-                    );
302
-
303
-                    echo $errorMsg.PHP_EOL;
304
-                }//end foreach
305
-            }//end foreach
306
-
307
-            echo str_repeat('-', $width).PHP_EOL;
308
-            echo rtrim($snippet).PHP_EOL;
309
-        }//end foreach
310
-
311
-        echo str_repeat('-', $width).PHP_EOL;
312
-        if ($report['fixable'] > 0) {
313
-            echo "\033[1m".'PHPCBF CAN FIX THE '.$report['fixable'].' MARKED SNIFF VIOLATIONS AUTOMATICALLY'."\033[0m".PHP_EOL;
314
-            echo str_repeat('-', $width).PHP_EOL;
315
-        }
316
-
317
-        return true;
318
-
319
-    }//end generateFileReport()
320
-
321
-
322
-    /**
323
-     * Prints all errors and warnings for each file processed.
324
-     *
325
-     * @param string $cachedData    Any partial report data that was returned from
326
-     *                              generateFileReport during the run.
327
-     * @param int    $totalFiles    Total number of files processed during the run.
328
-     * @param int    $totalErrors   Total number of errors found during the run.
329
-     * @param int    $totalWarnings Total number of warnings found during the run.
330
-     * @param int    $totalFixable  Total number of problems that can be fixed.
331
-     * @param bool   $showSources   Show sources?
332
-     * @param int    $width         Maximum allowed line width.
333
-     * @param bool   $interactive   Are we running in interactive mode?
334
-     * @param bool   $toScreen      Is the report being printed to screen?
335
-     *
336
-     * @return void
337
-     */
338
-    public function generate(
339
-        $cachedData,
340
-        $totalFiles,
341
-        $totalErrors,
342
-        $totalWarnings,
343
-        $totalFixable,
344
-        $showSources=false,
345
-        $width=80,
346
-        $interactive=false,
347
-        $toScreen=true
348
-    ) {
349
-        if ($cachedData === '') {
350
-            return;
351
-        }
352
-
353
-        echo $cachedData;
354
-
355
-        if ($toScreen === true && $interactive === false) {
356
-            Util\Timing::printRunTime();
357
-        }
358
-
359
-    }//end generate()
19
+	/**
20
+	 * Generate a partial report for a single processed file.
21
+	 *
22
+	 * Function should return TRUE if it printed or stored data about the file
23
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
+	 * its data should be counted in the grand totals.
25
+	 *
26
+	 * @param array                 $report      Prepared report data.
27
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
28
+	 * @param bool                  $showSources Show sources?
29
+	 * @param int                   $width       Maximum allowed line width.
30
+	 *
31
+	 * @return bool
32
+	 */
33
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
34
+	{
35
+		if ($report['errors'] === 0 && $report['warnings'] === 0) {
36
+			// Nothing to print.
37
+			return false;
38
+		}
39
+
40
+		// How many lines to show about and below the error line.
41
+		$surroundingLines = 2;
42
+
43
+		$file   = $report['filename'];
44
+		$tokens = $phpcsFile->getTokens();
45
+		if (empty($tokens) === true) {
46
+			if (PHP_CODESNIFFER_VERBOSITY === 1) {
47
+				$startTime = microtime(true);
48
+				echo 'CODE report is parsing '.basename($file).' ';
49
+			} else if (PHP_CODESNIFFER_VERBOSITY > 1) {
50
+				echo "CODE report is forcing parse of $file".PHP_EOL;
51
+			}
52
+
53
+			try {
54
+				$phpcsFile->parse();
55
+			} catch (\Exception $e) {
56
+				// This is a second parse, so ignore exceptions.
57
+				// They would have been added to the file's error list already.
58
+			}
59
+
60
+			if (PHP_CODESNIFFER_VERBOSITY === 1) {
61
+				$timeTaken = ((microtime(true) - $startTime) * 1000);
62
+				if ($timeTaken < 1000) {
63
+					$timeTaken = round($timeTaken);
64
+					echo "DONE in {$timeTaken}ms";
65
+				} else {
66
+					$timeTaken = round(($timeTaken / 1000), 2);
67
+					echo "DONE in $timeTaken secs";
68
+				}
69
+
70
+				echo PHP_EOL;
71
+			}
72
+
73
+			$tokens = $phpcsFile->getTokens();
74
+		}//end if
75
+
76
+		// Create an array that maps lines to the first token on the line.
77
+		$lineTokens = [];
78
+		$lastLine   = 0;
79
+		$stackPtr   = 0;
80
+		foreach ($tokens as $stackPtr => $token) {
81
+			if ($token['line'] !== $lastLine) {
82
+				if ($lastLine > 0) {
83
+					$lineTokens[$lastLine]['end'] = ($stackPtr - 1);
84
+				}
85
+
86
+				$lastLine++;
87
+				$lineTokens[$lastLine] = [
88
+					'start' => $stackPtr,
89
+					'end'   => null,
90
+				];
91
+			}
92
+		}
93
+
94
+		// Make sure the last token in the file sits on an imaginary
95
+		// last line so it is easier to generate code snippets at the
96
+		// end of the file.
97
+		$lineTokens[$lastLine]['end'] = $stackPtr;
98
+
99
+		// Determine the longest code line we will be showing.
100
+		$maxSnippetLength = 0;
101
+		$eolLen           = strlen($phpcsFile->eolChar);
102
+		foreach ($report['messages'] as $line => $lineErrors) {
103
+			$startLine = max(($line - $surroundingLines), 1);
104
+			$endLine   = min(($line + $surroundingLines), $lastLine);
105
+
106
+			$maxLineNumLength = strlen($endLine);
107
+
108
+			for ($i = $startLine; $i <= $endLine; $i++) {
109
+				if ($i === 1) {
110
+					continue;
111
+				}
112
+
113
+				$lineLength       = ($tokens[($lineTokens[$i]['start'] - 1)]['column'] + $tokens[($lineTokens[$i]['start'] - 1)]['length'] - $eolLen);
114
+				$maxSnippetLength = max($lineLength, $maxSnippetLength);
115
+			}
116
+		}
117
+
118
+		$maxSnippetLength += ($maxLineNumLength + 8);
119
+
120
+		// Determine the longest error message we will be showing.
121
+		$maxErrorLength = 0;
122
+		foreach ($report['messages'] as $line => $lineErrors) {
123
+			foreach ($lineErrors as $column => $colErrors) {
124
+				foreach ($colErrors as $error) {
125
+					$length = strlen($error['message']);
126
+					if ($showSources === true) {
127
+						$length += (strlen($error['source']) + 3);
128
+					}
129
+
130
+					$maxErrorLength = max($maxErrorLength, ($length + 1));
131
+				}
132
+			}
133
+		}
134
+
135
+		// The padding that all lines will require that are printing an error message overflow.
136
+		if ($report['warnings'] > 0) {
137
+			$typeLength = 7;
138
+		} else {
139
+			$typeLength = 5;
140
+		}
141
+
142
+		$errorPadding  = str_repeat(' ', ($maxLineNumLength + 7));
143
+		$errorPadding .= str_repeat(' ', $typeLength);
144
+		$errorPadding .= ' ';
145
+		if ($report['fixable'] > 0) {
146
+			$errorPadding .= '    ';
147
+		}
148
+
149
+		$errorPaddingLength = strlen($errorPadding);
150
+
151
+		// The maximum amount of space an error message can use.
152
+		$maxErrorSpace = ($width - $errorPaddingLength);
153
+		if ($showSources === true) {
154
+			// Account for the chars used to print colors.
155
+			$maxErrorSpace += 8;
156
+		}
157
+
158
+		// Figure out the max report width we need and can use.
159
+		$fileLength = strlen($file);
160
+		$maxWidth   = max(($fileLength + 6), ($maxErrorLength + $errorPaddingLength));
161
+		$width      = max(min($width, $maxWidth), $maxSnippetLength);
162
+		if ($width < 70) {
163
+			$width = 70;
164
+		}
165
+
166
+		// Print the file header.
167
+		echo PHP_EOL."\033[1mFILE: ";
168
+		if ($fileLength <= ($width - 6)) {
169
+			echo $file;
170
+		} else {
171
+			echo '...'.substr($file, ($fileLength - ($width - 6)));
172
+		}
173
+
174
+		echo "\033[0m".PHP_EOL;
175
+		echo str_repeat('-', $width).PHP_EOL;
176
+
177
+		echo "\033[1m".'FOUND '.$report['errors'].' ERROR';
178
+		if ($report['errors'] !== 1) {
179
+			echo 'S';
180
+		}
181
+
182
+		if ($report['warnings'] > 0) {
183
+			echo ' AND '.$report['warnings'].' WARNING';
184
+			if ($report['warnings'] !== 1) {
185
+				echo 'S';
186
+			}
187
+		}
188
+
189
+		echo ' AFFECTING '.count($report['messages']).' LINE';
190
+		if (count($report['messages']) !== 1) {
191
+			echo 'S';
192
+		}
193
+
194
+		echo "\033[0m".PHP_EOL;
195
+
196
+		foreach ($report['messages'] as $line => $lineErrors) {
197
+			$startLine = max(($line - $surroundingLines), 1);
198
+			$endLine   = min(($line + $surroundingLines), $lastLine);
199
+
200
+			$snippet = '';
201
+			if (isset($lineTokens[$startLine]) === true) {
202
+				for ($i = $lineTokens[$startLine]['start']; $i <= $lineTokens[$endLine]['end']; $i++) {
203
+					$snippetLine = $tokens[$i]['line'];
204
+					if ($lineTokens[$snippetLine]['start'] === $i) {
205
+						// Starting a new line.
206
+						if ($snippetLine === $line) {
207
+							$snippet .= "\033[1m".'>> ';
208
+						} else {
209
+							$snippet .= '   ';
210
+						}
211
+
212
+						$snippet .= str_repeat(' ', ($maxLineNumLength - strlen($snippetLine)));
213
+						$snippet .= $snippetLine.':  ';
214
+						if ($snippetLine === $line) {
215
+							$snippet .= "\033[0m";
216
+						}
217
+					}
218
+
219
+					if (isset($tokens[$i]['orig_content']) === true) {
220
+						$tokenContent = $tokens[$i]['orig_content'];
221
+					} else {
222
+						$tokenContent = $tokens[$i]['content'];
223
+					}
224
+
225
+					if (strpos($tokenContent, "\t") !== false) {
226
+						$token            = $tokens[$i];
227
+						$token['content'] = $tokenContent;
228
+						if (stripos(PHP_OS, 'WIN') === 0) {
229
+							$tab = "\000";
230
+						} else {
231
+							$tab = "\033[30;1m»\033[0m";
232
+						}
233
+
234
+						$phpcsFile->tokenizer->replaceTabsInToken($token, $tab, "\000");
235
+						$tokenContent = $token['content'];
236
+					}
237
+
238
+					$tokenContent = Util\Common::prepareForOutput($tokenContent, ["\r", "\n", "\t"]);
239
+					$tokenContent = str_replace("\000", ' ', $tokenContent);
240
+
241
+					$underline = false;
242
+					if ($snippetLine === $line && isset($lineErrors[$tokens[$i]['column']]) === true) {
243
+						$underline = true;
244
+					}
245
+
246
+					// Underline invisible characters as well.
247
+					if ($underline === true && trim($tokenContent) === '') {
248
+						$snippet .= "\033[4m".' '."\033[0m".$tokenContent;
249
+					} else {
250
+						if ($underline === true) {
251
+							$snippet .= "\033[4m";
252
+						}
253
+
254
+						$snippet .= $tokenContent;
255
+
256
+						if ($underline === true) {
257
+							$snippet .= "\033[0m";
258
+						}
259
+					}
260
+				}//end for
261
+			}//end if
262
+
263
+			echo str_repeat('-', $width).PHP_EOL;
264
+
265
+			foreach ($lineErrors as $column => $colErrors) {
266
+				foreach ($colErrors as $error) {
267
+					$padding = ($maxLineNumLength - strlen($line));
268
+					echo 'LINE '.str_repeat(' ', $padding).$line.': ';
269
+
270
+					if ($error['type'] === 'ERROR') {
271
+						echo "\033[31mERROR\033[0m";
272
+						if ($report['warnings'] > 0) {
273
+							echo '  ';
274
+						}
275
+					} else {
276
+						echo "\033[33mWARNING\033[0m";
277
+					}
278
+
279
+					echo ' ';
280
+					if ($report['fixable'] > 0) {
281
+						echo '[';
282
+						if ($error['fixable'] === true) {
283
+							echo 'x';
284
+						} else {
285
+							echo ' ';
286
+						}
287
+
288
+						echo '] ';
289
+					}
290
+
291
+					$message = $error['message'];
292
+					$message = str_replace("\n", "\n".$errorPadding, $message);
293
+					if ($showSources === true) {
294
+						$message = "\033[1m".$message."\033[0m".' ('.$error['source'].')';
295
+					}
296
+
297
+					$errorMsg = wordwrap(
298
+						$message,
299
+						$maxErrorSpace,
300
+						PHP_EOL.$errorPadding
301
+					);
302
+
303
+					echo $errorMsg.PHP_EOL;
304
+				}//end foreach
305
+			}//end foreach
306
+
307
+			echo str_repeat('-', $width).PHP_EOL;
308
+			echo rtrim($snippet).PHP_EOL;
309
+		}//end foreach
310
+
311
+		echo str_repeat('-', $width).PHP_EOL;
312
+		if ($report['fixable'] > 0) {
313
+			echo "\033[1m".'PHPCBF CAN FIX THE '.$report['fixable'].' MARKED SNIFF VIOLATIONS AUTOMATICALLY'."\033[0m".PHP_EOL;
314
+			echo str_repeat('-', $width).PHP_EOL;
315
+		}
316
+
317
+		return true;
318
+
319
+	}//end generateFileReport()
320
+
321
+
322
+	/**
323
+	 * Prints all errors and warnings for each file processed.
324
+	 *
325
+	 * @param string $cachedData    Any partial report data that was returned from
326
+	 *                              generateFileReport during the run.
327
+	 * @param int    $totalFiles    Total number of files processed during the run.
328
+	 * @param int    $totalErrors   Total number of errors found during the run.
329
+	 * @param int    $totalWarnings Total number of warnings found during the run.
330
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
331
+	 * @param bool   $showSources   Show sources?
332
+	 * @param int    $width         Maximum allowed line width.
333
+	 * @param bool   $interactive   Are we running in interactive mode?
334
+	 * @param bool   $toScreen      Is the report being printed to screen?
335
+	 *
336
+	 * @return void
337
+	 */
338
+	public function generate(
339
+		$cachedData,
340
+		$totalFiles,
341
+		$totalErrors,
342
+		$totalWarnings,
343
+		$totalFixable,
344
+		$showSources=false,
345
+		$width=80,
346
+		$interactive=false,
347
+		$toScreen=true
348
+	) {
349
+		if ($cachedData === '') {
350
+			return;
351
+		}
352
+
353
+		echo $cachedData;
354
+
355
+		if ($toScreen === true && $interactive === false) {
356
+			Util\Timing::printRunTime();
357
+		}
358
+
359
+	}//end generate()
360 360
 
361 361
 
362 362
 }//end class
Please login to merge, or discard this patch.