Completed
Push — master ( 67b389...a41cf5 )
by Vladimir
05:14
created

PermalinkFrontMatterDocument::buildPermalink()   C

Complexity

Conditions 8
Paths 10

Size

Total Lines 27
Code Lines 14

Duplication

Lines 11
Ratio 40.74 %

Code Coverage

Tests 13
CRAP Score 8.0231

Importance

Changes 0
Metric Value
dl 11
loc 27
ccs 13
cts 14
cp 0.9286
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 14
nc 10
nop 1
crap 8.0231
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
        {
24 6
            return;
25
        }
26
27 40
        if ($this->frontMatterParser !== null && $this->frontMatterParser->hasExpansion())
28
        {
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
        {
37 22
            $this->permalink = $permalink[0];
38 22
            array_shift($permalink);
39 22
            $this->redirects = $permalink;
40
        }
41
        else
42
        {
43 24
            $this->permalink = $permalink;
44 24
            $this->redirects = [];
45
        }
46 40
    }
47
}
48