• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 5045835811

pending completion
5045835811

Pull #1697

github

GitHub
Merge c3e3c7443 into a16355c73
Pull Request #1697: perf: native_function_invocation

321 of 321 new or added lines in 62 files covered. (100.0%)

2784 of 4121 relevant lines covered (67.56%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Command/ShowContent.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Cecil\Command;
15

16
use Cecil\Command\ShowContent\FileExtensionFilter;
17
use Cecil\Command\ShowContent\FilenameRecursiveTreeIterator;
18
use Cecil\Exception\RuntimeException;
19
use Cecil\Util;
20
use RecursiveDirectoryIterator;
21
use RecursiveTreeIterator;
22
use Symfony\Component\Console\Input\InputArgument;
23
use Symfony\Component\Console\Input\InputDefinition;
24
use Symfony\Component\Console\Input\InputInterface;
25
use Symfony\Component\Console\Input\InputOption;
26
use Symfony\Component\Console\Output\OutputInterface;
27

28
/**
29
 * Shows content.
30
 */
31
class ShowContent extends AbstractCommand
32
{
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function configure()
37
    {
38
        $this
×
39
            ->setName('show:content')
×
40
            ->setDescription('Shows content as tree')
×
41
            ->setDefinition(
×
42
                new InputDefinition([
×
43
                    new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'),
×
44
                    new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Set the path to the config file'),
×
45
                ])
×
46
            )
×
47
            ->setHelp('Shows the website\'s content as a tree');
×
48
    }
49

50
    /**
51
     * {@inheritdoc}
52
     *
53
     * @throws RuntimeException
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $count = 0;
×
58
        $contentDir = (string) $this->getBuilder()->getConfig()->get('pages.dir');
×
59
        $dataDir = (string) $this->getBuilder()->getConfig()->get('data.dir');
×
60

61
        // formating output
62
        $unicodeTreePrefix = function (RecursiveTreeIterator $tree) {
×
63
            $prefixParts = [
×
64
                RecursiveTreeIterator::PREFIX_LEFT         => ' ',
×
65
                RecursiveTreeIterator::PREFIX_MID_HAS_NEXT => '│ ',
×
66
                RecursiveTreeIterator::PREFIX_END_HAS_NEXT => '├ ',
×
67
                RecursiveTreeIterator::PREFIX_END_LAST     => '└ ',
×
68
            ];
×
69
            foreach ($prefixParts as $part => $string) {
×
70
                $tree->setPrefixPart($part, $string);
×
71
            }
72
        };
×
73

74
        try {
75
            // pages content
76
            if (is_dir(Util::joinFile($this->getPath(), $contentDir))) {
×
77
                $output->writeln(sprintf('<info>%s/</info>', $contentDir));
×
78
                $pages = $this->getFilesTree('pages');
×
79
                if (!Util\Plateform::isWindows()) {
×
80
                    $unicodeTreePrefix($pages);
×
81
                }
82
                foreach ($pages as $page) {
×
83
                    $output->writeln($page);
×
84
                    $count++;
×
85
                }
86
            }
87
            // data content
88
            if (is_dir(Util::joinFile($this->getPath(), $dataDir))) {
×
89
                $output->writeln(sprintf('<info>%s/</info>', $dataDir));
×
90
                $datas = $this->getFilesTree('data');
×
91
                if (!Util\Plateform::isWindows()) {
×
92
                    $unicodeTreePrefix($datas);
×
93
                }
94
                foreach ($datas as $data) {
×
95
                    $output->writeln($data);
×
96
                    $count++;
×
97
                }
98
            }
99
        } catch (\Exception $e) {
×
100
            throw new RuntimeException(sprintf($e->getMessage()));
×
101
        }
102

103
        if ($count < 1) {
×
104
            $output->writeln(sprintf('<comment>Nothing in "%s" nor "%s".</comment>', $contentDir, $dataDir));
×
105
        }
106

107
        return 0;
×
108
    }
109

110
    /**
111
     * Returns a console displayable tree of files.
112
     *
113
     * @throws RuntimeException
114
     */
115
    private function getFilesTree(string $directory): FilenameRecursiveTreeIterator
116
    {
117
        $dir = (string) $this->getBuilder()->getConfig()->get("$directory.dir");
×
118
        $ext = (array) $this->getBuilder()->getConfig()->get("$directory.ext");
×
119
        $path = Util::joinFile($this->getPath(), $dir);
×
120

121
        if (!is_dir($path)) {
×
122
            throw new RuntimeException(sprintf('Invalid directory: %s.', $path));
×
123
        }
124

125
        $dirIterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
×
126
        $dirIterator = new FileExtensionFilter($dirIterator, $ext);
×
127
        $files = new FilenameRecursiveTreeIterator(
×
128
            $dirIterator,
×
129
            FilenameRecursiveTreeIterator::SELF_FIRST
×
130
        );
×
131

132
        return $files;
×
133
    }
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc