Completed
Push — master ( a6d8dc...680f8e )
by Jan-Petter
03:57
created

RobotVersion   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 12.07 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 7
c 3
b 2
f 0
lcom 1
cbo 0
dl 7
loc 58
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 0 8 2
A export() 0 4 2
A render() 7 7 2

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
2
namespace vipnytt\RobotsTxtParser\Parser\Directives;
3
4
use vipnytt\RobotsTxtParser\Parser\RobotsTxtInterface;
5
6
/**
7
 * Class RobotVersion
8
 *
9
 * @package vipnytt\RobotsTxtParser\Parser\Directives
10
 */
11
class RobotVersion implements DirectiveInterface, RobotsTxtInterface
12
{
13
    /**
14
     * Directive
15
     */
16
    const DIRECTIVE = self::DIRECTIVE_ROBOT_VERSION;
17
18
    /**
19
     * RobotVersion value
20
     * @var float|int|string
21
     */
22
    protected $value;
23
24
    /**
25
     * RobotVersion constructor.
26
     */
27
    public function __construct()
28
    {
29
    }
30
31
    /**
32
     * Add
33
     *
34
     * @param float|int|string $line
35
     * @return bool
36
     */
37
    public function add($line)
38
    {
39
        if (!empty($this->value)) {
40
            return false;
41
        }
42
        $this->value = $line;
43
        return true;
44
    }
45
46
    /**
47
     * Export rules
48
     *
49
     * @return float[][]|int[][]|string[][]
50
     */
51
    public function export()
52
    {
53
        return empty($this->value) ? [] : [self::DIRECTIVE => $this->value];
54
    }
55
56
    /**
57
     * Render
58
     *
59
     * @return string[]
60
     */
61 View Code Duplication
    public function render()
0 ignored issues
show
Duplication introduced by
This method 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...
62
    {
63
        if (!empty($this->value)) {
64
            return [self::DIRECTIVE . ': ' . $this->value];
65
        }
66
        return [];
67
    }
68
}
69