Completed
Push — master ( a6c8f9...b97be3 )
by Vladimir
03:52 queued 19s
created

PermalinkFrontMatterDocument   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 31.43 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 11
loc 35
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C buildPermalink() 11 27 8

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
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Document;
9
10
/**
11
 * A document that builds its permalink from FrontMatter data.
12
 */
13
abstract class PermalinkFrontMatterDocument extends FrontMatterDocument implements PermalinkDocument
14
{
15
    use PermalinkDocumentTrait;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 40
    public function buildPermalink($force = false)
21
    {
22 40
        if ($this->permalink !== null && !$force)
23 40
        {
24 6
            return;
25
        }
26
27 40
        if ($this->frontMatterParser !== null && $this->frontMatterParser->hasExpansion())
28 40
        {
29
            throw new \Exception('The permalink for this item has not been set');
30
        }
31
32 40
        $permalink = (is_array($this->frontMatter) && isset($this->frontMatter['permalink'])) ?
33 40
            $this->frontMatter['permalink'] : $this->getPathPermalink();
34
35 40 View Code Duplication
        if (is_array($permalink))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36 40
        {
37 22
            $this->permalink = $permalink[0];
38 22
            array_shift($permalink);
39 22
            $this->redirects = $permalink;
40 22
        }
41
        else
42
        {
43 24
            $this->permalink = $permalink;
44 24
            $this->redirects = [];
45
        }
46 40
    }
47
}
48