Passed
Push — master ( 121290...ef5b2f )
by Caen
06:26 queued 03:36
created

UsesFlattenedOutputPaths   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 2
c 2
b 0
f 0
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOutputPath() 0 3 1
A getRouteKey() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Pages\Concerns;
6
7
use function basename;
8
use function unslash;
9
10
/**
11
 * @internal This trait is currently experimental and should not be relied upon outside of Hyde.
12
 *
13
 * This trait is used to flatten the output path of a page. This is only used for the documentation pages,
14
 * where all pages are output to the same directory, but where putting the page in a subdirectory will
15
 * create a nested navigation structure in the sidebar.
16
 *
17
 * @see https://hydephp.com/docs/master/documentation-pages#using-subdirectories
18
 */
19
trait UsesFlattenedOutputPaths
20
{
21
    /**
22
     * Get the route key for the page.
23
     *
24
     * Uses the identifier basename so nested pages are flattened.
25
     */
26
    public function getRouteKey(): string
27
    {
28
        return unslash(static::outputDirectory().'/'.basename($this->identifier));
29
    }
30
31
    /**
32
     * Get the path where the compiled page will be saved.
33
     *
34
     * Uses the identifier basename so nested pages are flattened.
35
     */
36
    public function getOutputPath(): string
37
    {
38
        return static::outputPath(basename($this->identifier));
39
    }
40
}
41