wikimedia/mediawiki-extensions-Wikibase

View on GitHub
repo/includes/Api/FormatSnakValue.php

Summary

Maintainability
C
1 day
Test Coverage

File FormatSnakValue.php has 272 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare( strict_types = 1 );

namespace Wikibase\Repo\Api;
Severity: Minor
Found in repo/includes/Api/FormatSnakValue.php - About 2 hrs to fix

    Method __construct has 11 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            ApiMain $mainModule,
            string $moduleName,
            OutputFormatValueFormatterFactory $valueFormatterFactory,
            OutputFormatSnakFormatterFactory $snakFormatterFactory,
            DataTypeFactory $dataTypeFactory,
    Severity: Major
    Found in repo/includes/Api/FormatSnakValue.php - About 1 hr to fix

      Method factory has 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              ApiMain $mainModule,
              string $moduleName,
              IBufferingStatsdDataFactory $stats,
              ApiHelperFactory $apiHelperFactory,
              DataTypeFactory $dataTypeFactory,
      Severity: Major
      Found in repo/includes/Api/FormatSnakValue.php - About 1 hr to fix

        Method getAllowedParams has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function getAllowedParams(): array {
                return [
                    'generate' => [
                        ParamValidator::PARAM_TYPE => [
                            SnakFormatter::FORMAT_PLAIN,
        Severity: Minor
        Found in repo/includes/Api/FormatSnakValue.php - About 1 hr to fix

          Method getExamplesMessages has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function getExamplesMessages(): array {
                  $query = 'action=' . $this->getModuleName();
                  $hello = new StringValue( 'hello' );
                  $acme = new StringValue( 'http://acme.org' );
                  $einsteinDob = new TimeValue(
          Severity: Minor
          Found in repo/includes/Api/FormatSnakValue.php - About 1 hr to fix

            Method execute has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function execute(): void {
                    $this->getMain()->setCacheMode( 'public' );
            
                    $params = $this->extractRequestParams();
                    $this->requireMaxOneParameter( $params, 'property', 'datatype' );
            Severity: Minor
            Found in repo/includes/Api/FormatSnakValue.php - About 1 hr to fix

              Function getOptionsObject has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function getOptionsObject( ?string $optionsParam ): FormatterOptions {
                      $formatterOptions = new FormatterOptions();
                      $formatterOptions->setOption( ValueFormatter::OPT_LANG, $this->getLanguage()->getCode() );
              
                      if ( is_string( $optionsParam ) && $optionsParam !== '' ) {
              Severity: Minor
              Found in repo/includes/Api/FormatSnakValue.php - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function formatValue has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function formatValue( array $params, DataValue $value, ?string $dataTypeId ): string {
                      $snak = null;
                      if ( isset( $params['property'] ) ) {
                          $snak = new PropertyValueSnak( $this->parsePropertyId( $params['property'] ), $value );
                      }
              Severity: Minor
              Found in repo/includes/Api/FormatSnakValue.php - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              There are no issues that match your filters.

              Category
              Status