Passed
Push — master ( 36f9d6...294ad3 )
by Mazarini
10:49
created

Folder::getPages()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/*
4
 * Copyright (C) 2019 Mazarini <[email protected]>.
5
 * This file is part of mazarini/design.
6
 *
7
 * mazarini/design is free software: you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or (at your
10
 * option) any later version.
11
 *
12
 * mazarini/design is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15
 * more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 */
19
20
namespace Mazarini\DesignBundle\Tools;
21
22
class Folder
23
{
24
    private $layout;
25
    private $stepRoot;
26
27 4
    public function __construct(string $projectRoot)
28
    {
29 4
        $this->layout = $projectRoot.'/templates/layout.html.twig';
30 4
        $this->stepRoot = \dirname(__DIR__).'/Resources/views/steps';
31 4
    }
32
33 3
    public function getLayout(): string
34
    {
35 3
        return $this->layout;
36
    }
37
38 1
    public function getStepRoot(): string
39
    {
40 1
        return $this->stepRoot;
41
    }
42
43 2
    public function hasLayout(): bool
44
    {
45 2
        return file_exists($this->getLayout());
46
    }
47
48 1
    public function getSteps(): array
49
    {
50 1
        $dirs = glob($this->stepRoot.'/??-*');
51 1
        $steps = [];
52 1
        foreach ($dirs as $dir) {
53 1
            $step = basename($dir);
54 1
            $steps[$step] = mb_substr($step, 3);
55
        }
56
57 1
        return $steps;
58
    }
59
60
    public function getPages(string $step): array
61
    {
62
        $dirs = glob($this->stepRoot.'/'.$step.'/??-*\.html\.twig');
63
        $pages = [];
64
        foreach ($dirs as $dir) {
65
            $pages[basename($dir)] = mb_substr(basename($dir, '.html.twig'), 3);
66
        }
67
68
        return $pages;
69
    }
70
}
71