NameMeta   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 51
loc 51
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 3 3 1
A render() 9 9 3
A __construct() 4 4 1
A isTitle() 4 4 1

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
3
namespace Pageon\Html\Meta\Item;
4
5
use Pageon\Html\Meta\MetaItem;
6
7 View Code Duplication
final class NameMeta implements MetaItem
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...
8
{
9
    /**
10
     * @var string
11
     */
12
    private $name;
13
14
    /**
15
     * @var string
16
     */
17
    private $content;
18
19
    /**
20
     * @param string $name
21
     * @param string $content
22
     *
23
     * @return MetaItem
24
     */
25 21
    public static function create(string $name, string $content) : MetaItem {
26 21
        return new self($name, $content);
27
    }
28
29
    /**
30
     * @return string
31
     */
32 17
    public function render(array $extra = []) : string {
33 17
        $content = $this->content;
34
35 17
        if ($this->isTitle() && isset($extra['title']['suffix'])) {
36 1
            $content = "{$content}{$extra['title']['suffix']}";
37
        }
38
39 17
        return "<meta name=\"{$this->name}\" content=\"{$content}\">";
40
    }
41
42
    /**
43
     * NamedMeta constructor.
44
     *
45
     * @param string $name
46
     * @param string $content
47
     */
48 21
    public function __construct(string $name, string $content) {
49 21
        $this->name = $name;
50 21
        $this->content = htmlentities($content);
51 21
    }
52
53 17
    private function isTitle(): bool
54
    {
55 17
        return str_contains($this->name, 'title');
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated with message: Str::contains() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
56
    }
57
}
58