Completed
Pull Request — master (#230)
by
unknown
02:43 queued 01:26
created

Image   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 35
loc 35
ccs 5
cts 11
cp 0.4545
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 6 6 2
A hasValue() 4 4 2
A addElement() 7 7 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Rule\Atom;
12
13
use FeedIo\Feed\Item;
14
use FeedIo\Feed\Item\MediaInterface;
15
use FeedIo\Feed\ItemInterface;
16
use FeedIo\Feed\NodeInterface;
17
use FeedIo\RuleAbstract;
18
19 View Code Duplication
class Image extends RuleAbstract
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
	// https://tools.ietf.org/html/rfc4287#section-4.2.8
22
    const NODE_NAME = 'logo';
23
24
    /**
25
     * @param  NodeInterface $node
26
     * @param  \DOMElement   $element
27
     */
28 1
    public function setProperty(NodeInterface $node, \DOMElement $element) : void
29
    {
30 1
		if ($node instanceof FeedInterface) {
0 ignored issues
show
Bug introduced by
The class FeedIo\Rule\Atom\FeedInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
            $node->setImage($element->nodeValue);
32
        }
33 1
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38 2
    protected function hasValue(NodeInterface $node) : bool
39
    {
40 2
		return $node instanceof FeedInterface && !! $node->getImage();
0 ignored issues
show
Bug introduced by
The class FeedIo\Rule\Atom\FeedInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
47
    {
48
		if (!($node instanceof FeedInterface) || is_null($node->getImage())) {
0 ignored issues
show
Bug introduced by
The class FeedIo\Rule\Atom\FeedInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
49
            return;
50
        }
51
        $rootElement->appendChild($document->createElement($this->getNodeName(), $node->getImage()));
52
    }
53
}
54