MediaWiki  1.32.5
postprocess-phan.php
Go to the documentation of this file.
1 <?php
2 
3 abstract 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 
24 class TextSuppressor extends Suppressor {
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 
103 class NoopSuppressor extends Suppressor {
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
117 if ( isset( $opt['m'] ) ) {
118  $mode = $opt['m'];
119 } elseif ( isset( $mode['output-mode'] ) ) {
120  $mode = $opt['output-mode'];
121 } else {
122  $mode = 'text';
123 }
124 if ( 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 
130 switch ( $mode ) {
131 case 'text':
132  $suppressor = new TextSuppressor();
133  break;
134 case 'checkstyle':
135  $suppressor = new CheckStyleSuppressor();
136  break;
137 default:
138  $suppressor = new NoopSuppressor( $mode );
139 }
140 
141 $input = file_get_contents( 'php://stdin' );
142 $hasErrors = $suppressor->suppress( $input );
143 
144 if ( $hasErrors ) {
145  exit( 1 );
146 }
file
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:91
$opt
$opt
Definition: postprocess-phan.php:115
CheckStyleSuppressor
Definition: postprocess-phan.php:62
CheckStyleSuppressor\suppress
suppress( $input)
Definition: postprocess-phan.php:67
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
NoopSuppressor\suppress
suppress( $input)
Definition: postprocess-phan.php:109
$hasErrors
$hasErrors
Definition: postprocess-phan.php:142
NoopSuppressor\__construct
__construct( $mode)
Definition: postprocess-phan.php:106
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
$matches
$matches
Definition: NoLocalSettings.php:24
mode
if write to the Free Software Franklin Fifth MA USA Also add information on how to contact you by electronic and paper mail If the program is make it output a short notice like this when it starts in an interactive mode
Definition: COPYING.txt:307
NoopSuppressor\$mode
$mode
Definition: postprocess-phan.php:104
array
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))
list
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
Suppressor\isSuppressed
isSuppressed(array $source, $type, $lineno)
Definition: postprocess-phan.php:16
NoopSuppressor
Definition: postprocess-phan.php:103
TextSuppressor\suppress
suppress( $input)
Definition: postprocess-phan.php:29
Suppressor\suppress
suppress( $input)
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$source
$source
Definition: mwdoc-filter.php:46
TextSuppressor
Definition: postprocess-phan.php:24
Suppressor
Definition: postprocess-phan.php:3
$type
$type
Definition: testCompression.php:48