Code should not be duplicated

More information: https://insight.symfony.com/what-we-analyse/php.duplicated_code

in WikipediaExtracts.php, line 26
  1. $continue = null;
  2. $variant = null;
  3. // Override with user input
  4. extract( $args );
  5. if ( $input ) {

    The next 48 lines appear both in WikipediaExtracts.php:26 and WikipediaExtracts.php:94.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Sophivorus
  6. if ( filter_var( $input, FILTER_VALIDATE_URL ) ) {
  7. // Extract the title
  8. $path = parse_url( $input, PHP_URL_PATH );
  9. $PATH = explode( '/', $path );
  10. $title = $PATH[2];

Object parameters should be type hinted 2

More information: https://insight.symfony.com/what-we-analyse/php.object_parameter_not_type_hinted

  1. <?php
  2. class WikipediaExtracts {
  3. static function onParserFirstCallInit( &$parser ) {

    The parameter parser, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Last edited by Sophivorus
  4. $parser->setHook( 'WikipediaExtract', 'WikipediaExtracts::onHook' );
  5. $parser->setFunctionHook( 'WikipediaExtract', 'WikipediaExtracts::onFunctionHook' );
  6. return true;
  7. }
in WikipediaExtracts.php, line 78
  1. $extract .= wfMessage( 'wikipediaextracts-credits', $url )->parse();
  2. return $extract;
  3. }
  4. }
  5. static function onFunctionHook( $parser, $input = null ) {

    The parameter parser, which is an object, should be typehinted.

    Time to fix: about 1 hour
    Open Issue Permalink
    Last edited by Sophivorus
  6. // Set the defaults
  7. $title = $parser->getTitle()->getRootText();
  8. $language = $parser->getTargetLanguage()->getCode();
  9. $chars = null;
  10. $sentences = null;

User specific files should not appear in .gitignore

More information: https://insight.symfony.com/what-we-analyse/git.user_specific_ignored_file

in .gitignore, line 1
  1. .DS_Store

    .DS_Store is user-specific and should not appear in a project .gitignore. Consider adding it to the user global .gitignore instead.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus

Unused method, property, variable or parameter

More information: https://insight.symfony.com/what-we-analyse/php.unused_local_variable_or_private_member

in WikipediaExtracts.php, line 11
  1. $parser->setHook( 'WikipediaExtract', 'WikipediaExtracts::onHook' );
  2. $parser->setFunctionHook( 'WikipediaExtract', 'WikipediaExtracts::onFunctionHook' );
  3. return true;
  4. }
  5. static function onHook( $input, array $args, Parser $parser, PPFrame $frame ) {

    This frame argument is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus
  6. // Set the defaults
  7. $title = $parser->getTitle()->getRootText();
  8. $language = $parser->getTargetLanguage()->getCode();
  9. $chars = null;
  10. $sentences = null;

Text files should end with a valid new line character. 3

More information: https://insight.symfony.com/what-we-analyse/missing_e_o_l

in .gitignore, line 1
  1. .DS_Store

    This file ends with no newline character, or with a different newline character than other files in your project. It won't render properly on a terminal, and it's considered a bad practice.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus
in WikipediaExtracts.php, line 175
  1. // [foo] => "bar"
  2. // [apple] => "orange"
  3. // [banana] => true
  4. return $results;
  5. }
  6. }

    This file ends with no newline character, or with a different newline character than other files in your project. It won't render properly on a terminal, and it's considered a bad practice.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus
  1. 'WikipediaExtract' => array( 0, 'ExtractoWikipedia' ),
  2. );
  3. $magicWords['fr'] = array(
  4. 'WikipediaExtract' => array( 0, 'ExtraitWikipédia' ),
  5. );

    This file ends with no newline character, or with a different newline character than other files in your project. It won't render properly on a terminal, and it's considered a bad practice.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus

Methods and properties visibility should always be explicitly defined 4

More information: https://insight.symfony.com/what-we-analyse/php.method_or_property_missing_visibility

  1. <?php
  2. class WikipediaExtracts {
  3. static function onParserFirstCallInit( &$parser ) {

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus
  4. $parser->setHook( 'WikipediaExtract', 'WikipediaExtracts::onHook' );
  5. $parser->setFunctionHook( 'WikipediaExtract', 'WikipediaExtracts::onFunctionHook' );
  6. return true;
  7. }
in WikipediaExtracts.php, line 11
  1. $parser->setHook( 'WikipediaExtract', 'WikipediaExtracts::onHook' );
  2. $parser->setFunctionHook( 'WikipediaExtract', 'WikipediaExtracts::onFunctionHook' );
  3. return true;
  4. }
  5. static function onHook( $input, array $args, Parser $parser, PPFrame $frame ) {

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus
  6. // Set the defaults
  7. $title = $parser->getTitle()->getRootText();
  8. $language = $parser->getTargetLanguage()->getCode();
  9. $chars = null;
  10. $sentences = null;
in WikipediaExtracts.php, line 78
  1. $extract .= wfMessage( 'wikipediaextracts-credits', $url )->parse();
  2. return $extract;
  3. }
  4. }
  5. static function onFunctionHook( $parser, $input = null ) {

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus
  6. // Set the defaults
  7. $title = $parser->getTitle()->getRootText();
  8. $language = $parser->getTargetLanguage()->getCode();
  9. $chars = null;
  10. $sentences = null;
in WikipediaExtracts.php, line 154
  1. * true is assumed like this: [name] => true
  2. *
  3. * @param array string $options
  4. * @return array $results
  5. */
  6. static function extractOptions( $options ) {

    This method has no explicit visibility which may lead to maintainability issues. You should always declare a visibility for methods and properties.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Sophivorus
  7. $results = array();
  8. foreach ( $options as $option ) {
  9. $pair = explode( '=', $option, 2 );
  10. if ( count( $pair ) === 2 ) {