Folder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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 7
    public function __construct(string $projectRoot)
28
    {
29 7
        $this->layout = $projectRoot.'/templates/layout.html.twig';
30 7
        $this->stepRoot = \dirname(__DIR__).'/Resources/views/steps';
31 7
    }
32
33 6
    public function getLayout(): string
34
    {
35 6
        return $this->layout;
36
    }
37
38 1
    public function getStepRoot(): string
39
    {
40 1
        return $this->stepRoot;
41
    }
42
43 5
    public function hasLayout(): bool
44
    {
45 5
        return file_exists($this->getLayout());
46
    }
47
48 4
    public function getSteps(): array
49
    {
50 4
        $dirs = glob($this->stepRoot.'/??-*');
51 4
        $steps = [];
52 4
        if (\is_array($dirs)) {
53 4
            foreach ($dirs as $dir) {
54 4
                $step = basename($dir);
55 4
                $steps[mb_substr($step, 3)] = $step;
56
            }
57
        }
58
59 4
        return $steps;
60
    }
61
62 3
    public function getPages(string $step): array
63
    {
64 3
        $dirs = glob($this->stepRoot.'/'.$step.'/??-*\.html\.twig');
65 3
        $pages = [];
66 3
        if (\is_array($dirs)) {
67 3
            foreach ($dirs as $dir) {
68 3
                $pages[mb_substr(basename($dir, '.html.twig'), 3)] = basename($dir);
69
            }
70
        }
71
72 3
        return $pages;
73
    }
74
}
75