MediaWiki REL1_32
postprocess-phan.php
Go to the documentation of this file.
1<?php
2
3abstract class Suppressor {
8 abstract public function suppress( $input );
9
16 protected function isSuppressed( array $source, $type, $lineno ) {
17 return $lineno > 0 && preg_match(
18 "|/\*\* @suppress {$type} |",
19 $source[$lineno - 1]
20 );
21 }
22}
23
29 public function suppress( $input ) {
30 $hasErrors = false;
31 $errors = [];
32 foreach ( explode( "\n", $input ) as $error ) {
33 if ( empty( $error ) ) {
34 continue;
35 }
36 if ( !preg_match( '/^(.*):(\d+) (Phan\w+) (.*)$/', $error, $matches ) ) {
37 echo "Failed to parse line: $error\n";
38 continue;
39 }
40 list( $source, $file, $lineno, $type, $message ) = $matches;
41 $errors[$file][] = [
42 'orig' => $error,
43 // convert from 1 indexed to 0 indexed
44 'lineno' => $lineno - 1,
45 'type' => $type,
46 ];
47 }
48 foreach ( $errors as $file => $fileErrors ) {
49 $source = file( $file );
50 foreach ( $fileErrors as $error ) {
51 if ( !$this->isSuppressed( $source, $error['type'], $error['lineno'] ) ) {
52 echo $error['orig'], "\n";
53 $hasErrors = true;
54 }
55 }
56 }
57
58 return $hasErrors;
59 }
60}
61
67 public function suppress( $input ) {
68 $dom = new DOMDocument();
69 $dom->loadXML( $input );
70 $hasErrors = false;
71 // DOMNodeList's are "live", convert to an array so it works as expected
72 $files = [];
73 foreach ( $dom->getElementsByTagName( 'file' ) as $file ) {
74 $files[] = $file;
75 }
76 foreach ( $files as $file ) {
77 $errors = [];
78 foreach ( $file->getElementsByTagName( 'error' ) as $error ) {
79 $errors[] = $error;
80 }
81 $source = file( $file->getAttribute( 'name' ) );
82 $fileHasErrors = false;
83 foreach ( $errors as $error ) {
84 $lineno = $error->getAttribute( 'line' ) - 1;
85 $type = $error->getAttribute( 'source' );
86 if ( $this->isSuppressed( $source, $type, $lineno ) ) {
87 $error->parentNode->removeChild( $error );
88 } else {
89 $fileHasErrors = true;
90 $hasErrors = true;
91 }
92 }
93 if ( !$fileHasErrors ) {
94 $file->parentNode->removeChild( $file );
95 }
96 }
97 echo $dom->saveXML();
98
99 return $hasErrors;
100 }
101}
102
104 private $mode;
105
106 public function __construct( $mode ) {
107 $this->mode = $mode;
108 }
109 public function suppress( $input ) {
110 echo "Unsupported output mode: {$this->mode}\n$input";
111 return true;
112 }
113}
114
115$opt = getopt( "m:", [ "output-mode:" ] );
116// if provided multiple times getopt returns an array
117if ( isset( $opt['m'] ) ) {
118 $mode = $opt['m'];
119} elseif ( isset( $mode['output-mode'] ) ) {
120 $mode = $opt['output-mode'];
121} else {
122 $mode = 'text';
123}
124if ( is_array( $mode ) ) {
125 // If an option is passed multiple times getopt returns an
126 // array. Just take the last one.
127 $mode = end( $mode );
128}
129
130switch ( $mode ) {
131case 'text':
132 $suppressor = new TextSuppressor();
133 break;
134case 'checkstyle':
135 $suppressor = new CheckStyleSuppressor();
136 break;
137default:
138 $suppressor = new NoopSuppressor( $mode );
139}
140
141$input = file_get_contents( 'php://stdin' );
142$hasErrors = $suppressor->suppress( $input );
143
144if ( $hasErrors ) {
145 exit( 1 );
146}
suppress( $input)
isSuppressed(array $source, $type, $lineno)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition hooks.txt:106
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$source
if(is_array($mode)) switch( $mode) $input