jkphl/micrometa

View on GitHub

Showing 38 of 38 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

/**
 * micrometa
 *
Severity: Major
Found in src/Micrometa/Infrastructure/Parser/RdfaLite.php and 1 other location - About 3 hrs to fix
src/Micrometa/Infrastructure/Parser/Microdata.php on lines 1..92

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 145.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

/**
 * micrometa
 *
Severity: Major
Found in src/Micrometa/Infrastructure/Parser/Microdata.php and 1 other location - About 3 hrs to fix
src/Micrometa/Infrastructure/Parser/RdfaLite.php on lines 1..92

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 145.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method testAliasedItemProperty has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function testAliasedItemProperty()
    {
        $itemFactory = new ItemFactory(0);
        $rawItem     = (object)[
            'type'       => ['test'],
Severity: Major
Found in src/Micrometa/Tests/Application/ItemFactoryTest.php - About 2 hrs to fix

    Method getItems has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function getItems()
        {
            $items = ItemFactory::createFromApplicationItems(
                [
                    // Stylesheet link item
    Severity: Major
    Found in src/Micrometa/Tests/Ports/ItemObjectModelTest.php - About 2 hrs to fix

      Method getProfiledNames has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getProfiledNames()
          {
              $schemaOrgProfile = 'http://schema.org/';
              $feedObject       = (object)['name' => 'h-feed', 'profile' => MicroformatsFactory::MF2_PROFILE_URI];
              $eventObject      = (object)['name' => 'Event', 'profile' => $schemaOrgProfile];
      Severity: Minor
      Found in src/Micrometa/Tests/Infrastructure/ProfiledNameFactoryTest.php - About 1 hr to fix

        Method creationArgumentProvider has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function creationArgumentProvider()
            {
                $item  = new Item('test');
                $testT = $this->typ('test');
                $nvP   = $this->prp('name1', 'value1');
        Severity: Minor
        Found in src/Micrometa/Tests/Domain/ItemTest.php - About 1 hr to fix

          Method renderItem has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function renderItem(ItemInterface $item)
          {
              $types = array_map(
                  function ($type) {
                      return '<abbr title="'.htmlspecialchars($type->profile.$type->name).'">'.
          Severity: Minor
          Found in demo/demo.inc.php - About 1 hr to fix

            Method testItemCreation has 8 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    $type,
                    array $properties,
                    $itemId,
                    $itemLanguage,
                    array $expectedTypes,
            Severity: Major
            Found in src/Micrometa/Tests/Domain/ItemTest.php - About 1 hr to fix

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

                      $format,
                      PropertyListFactoryInterface $propertyListFactory,
                      $type,
                      array $properties = [],
                      array $children = [],
              Severity: Major
              Found in src/Micrometa/Application/Item/Item.php - About 1 hr to fix

                Avoid variables with short names like $i. Configured minimum length is 3.
                Open

                            $i               = $this->parseDocument($jsonLDDocSource);

                ShortVariable

                Since: 0.2

                Detects when a field, local, or parameter has a very short name.

                Example

                class Something {
                    private $q = 15; // VIOLATION - Field
                    public static function main( array $as ) { // VIOLATION - Formal
                        $r = 20 + $this->q; // VIOLATION - Local
                        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                            $r += $this->q;
                        }
                    }
                }

                Source https://phpmd.org/rules/naming.html#shortvariable

                The class Item has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
                Open

                class Item extends Collection implements ItemInterface
                {
                    /**
                     * Application item
                     *
                Severity: Minor
                Found in src/Micrometa/Ports/Item/Item.php by phpmd

                CouplingBetweenObjects

                Since: 1.1.0

                A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                Example

                class Foo {
                    /**
                     * @var \foo\bar\X
                     */
                    private $x = null;
                
                    /**
                     * @var \foo\bar\Y
                     */
                    private $y = null;
                
                    /**
                     * @var \foo\bar\Z
                     */
                    private $z = null;
                
                    public function setFoo(\Foo $foo) {}
                    public function setBar(\Bar $bar) {}
                    public function setBaz(\Baz $baz) {}
                
                    /**
                     * @return \SplObjectStorage
                     * @throws \OutOfRangeException
                     * @throws \InvalidArgumentException
                     * @throws \ErrorException
                     */
                    public function process(\Iterator $it) {}
                
                    // ...
                }

                Source https://phpmd.org/rules/design.html#couplingbetweenobjects

                The class JsonLD has a coupling between objects value of 16. Consider to reduce the number of dependencies under 13.
                Open

                class JsonLD extends AbstractParser
                {
                    /**
                     * Format
                     *

                CouplingBetweenObjects

                Since: 1.1.0

                A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                Example

                class Foo {
                    /**
                     * @var \foo\bar\X
                     */
                    private $x = null;
                
                    /**
                     * @var \foo\bar\Y
                     */
                    private $y = null;
                
                    /**
                     * @var \foo\bar\Z
                     */
                    private $z = null;
                
                    public function setFoo(\Foo $foo) {}
                    public function setBar(\Bar $bar) {}
                    public function setBaz(\Baz $baz) {}
                
                    /**
                     * @return \SplObjectStorage
                     * @throws \OutOfRangeException
                     * @throws \InvalidArgumentException
                     * @throws \ErrorException
                     */
                    public function process(\Iterator $it) {}
                
                    // ...
                }

                Source https://phpmd.org/rules/design.html#couplingbetweenobjects

                The class Parser has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
                Open

                class Parser
                {
                    /**
                     * Micro information formats
                     *
                Severity: Minor
                Found in src/Micrometa/Ports/Parser.php by phpmd

                CouplingBetweenObjects

                Since: 1.1.0

                A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                Example

                class Foo {
                    /**
                     * @var \foo\bar\X
                     */
                    private $x = null;
                
                    /**
                     * @var \foo\bar\Y
                     */
                    private $y = null;
                
                    /**
                     * @var \foo\bar\Z
                     */
                    private $z = null;
                
                    public function setFoo(\Foo $foo) {}
                    public function setBar(\Bar $bar) {}
                    public function setBaz(\Baz $baz) {}
                
                    /**
                     * @return \SplObjectStorage
                     * @throws \OutOfRangeException
                     * @throws \InvalidArgumentException
                     * @throws \ErrorException
                     */
                    public function process(\Iterator $it) {}
                
                    // ...
                }

                Source https://phpmd.org/rules/design.html#couplingbetweenobjects

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

                        $type,
                        array $properties = [],
                        $itemId = null,
                        $itemLanguage = null,
                        PropertyListFactoryInterface $propertyListFactory = null
                Severity: Minor
                Found in src/Micrometa/Domain/Item/Item.php - About 35 mins to fix

                  Method setup has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                          PropertyListFactoryInterface $propertyListFactory,
                          array $type,
                          array $properties,
                          $itemId,
                          $itemLanguage
                  Severity: Minor
                  Found in src/Micrometa/Domain/Item/ItemSetupTrait.php - About 35 mins to fix

                    Expected 1 space after FUNCTION keyword; 0 found
                    Open

                                function($type) {

                    Expected 1 space after FUNCTION keyword; 0 found
                    Open

                                function($propertyValue) {

                    Expected 1 space after FUNCTION keyword; 0 found
                    Open

                            return $lang ? array_map(function($value) use ($lang) {

                    Missing class import via use statement (line '116', column '53').
                    Open

                            $this->logger->info('Running parser: '.(new \ReflectionClass(__CLASS__))->getShortName());

                    MissingImport

                    Since: 2.7.0

                    Importing all external classes in a file through use statements makes them clearly visible.

                    Example

                    function make() {
                        return new \stdClass();
                    }

                    Source http://phpmd.org/rules/cleancode.html#MissingImport

                    Missing class import via use statement (line '69', column '22').
                    Open

                            $xpath = new \DOMXPath($dom);

                    MissingImport

                    Since: 2.7.0

                    Importing all external classes in a file through use statements makes them clearly visible.

                    Example

                    function make() {
                        return new \stdClass();
                    }

                    Source http://phpmd.org/rules/cleancode.html#MissingImport

                    Severity
                    Category
                    Status
                    Source
                    Language