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

DannyvdSluijs / exact-online-meta-data-tool / 7178990018

12 Dec 2023 08:48AM UTC coverage: 77.241% (-5.0%) from 82.201%
7178990018

push

github

web-flow
refactor: Require PHP 8.0 (#194)

* refactor: Require PHP 8.0; Bump all dependencies; Update workflow for PHP 8 requirement including newer versions PHP

* refactor: Update code to PHP 8.0 using rector; Upgrade progressbar to show current url

* refactor: Improving for PHP 8.0 support

* fix: Add missing entry in known endpoints to avoid losing ProjectProjectProgressReports

15 of 30 new or added lines in 6 files covered. (50.0%)

4 existing lines in 1 file now uncovered.

224 of 290 relevant lines covered (77.24%)

13.71 hits per line

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

0.0
/MetaDataTool/Command/MetaDataBuilderCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MetaDataTool\Command;
6

7
use MetaDataTool\Config\EndpointCrawlerConfig;
8
use MetaDataTool\Crawlers\EndpointCrawler;
9
use MetaDataTool\Crawlers\MainPageCrawler;
10
use MetaDataTool\Enum\KnownEntities;
11
use MetaDataTool\JsonFileWriter;
12
use MetaDataTool\ValueObjects\Endpoint;
13
use Symfony\Component\Console\Command\Command;
14
use Symfony\Component\Console\Helper\ProgressBar;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Style\SymfonyStyle;
19

20
class MetaDataBuilderCommand extends Command
21
{
22
    private const MAIN_PAGE = 'https://start.exactonline.nl/docs/HlpRestAPIResources.aspx';
23
    protected static $defaultName = 'run';
24

25
    protected function configure(): void
26
    {
UNCOV
27
        $this
×
28
            ->setDescription('Scans the online ExactOnline documentation allowing to discover the API entities')
×
29
            ->setHelp(<<<'HELP'
×
30
                Scans the online ExactOnline documentation allowing to discover the API entities.....
UNCOV
31
HELP
×
32
            )->setDefinition([
×
33
                new InputOption(
×
34
                    'destination',
×
35
                    'd',
×
36
                    InputOption::VALUE_REQUIRED,
×
37
                    'The destination directory',
×
38
                    $this->defaultDestinationDirectory()
×
UNCOV
39
                ),
×
UNCOV
40
            ]);
×
41
    }
42

43
    protected function execute(InputInterface $input, OutputInterface $output): int
44
    {
45
        $destination = $input->getOption('destination');
×
46
        $io = new SymfonyStyle($input, $output);
×
47
        $io->title('Exact Online Meta Data Tool');
×
48

49

50
        if (! is_string($destination)) {
×
51
            $io->error('Invalid input for the destination option');
×
52
            die(1);
×
53
        }
54

NEW
55
        $io->info(['Scanning main page', self::MAIN_PAGE]);
×
NEW
56
        $mainPageCrawler = new MainPageCrawler(self::MAIN_PAGE);
×
57
        $pages = $mainPageCrawler->run();
×
58
        foreach (KnownEntities::keys() as $entity) {
×
59
            $pages->add('https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=' . $entity);
×
60
        }
61

62
        $io->info('Scanning entity pages');
×
NEW
63
        ProgressBar::setFormatDefinition('custom', ' %current%/%max% -- %message% (%url%)');
×
NEW
64
        $progressBar = $io->createProgressBar($pages->count());
×
NEW
65
        $progressBar->setFormat('custom');
×
NEW
66
        $progressBar->setMessage('Processing documentation');
×
NEW
67
        $progressBar->start();
×
68

69
        $config = new EndpointCrawlerConfig(true);
×
70
        $endpoints = (new EndpointCrawler($config, $pages))
×
NEW
71
            ->run(static function(Endpoint $endpoint) use ($progressBar): void {
×
NEW
72
                $progressBar->advance(1);
×
NEW
73
                $progressBar->setMessage($endpoint->getDocumentation(), 'url');
×
74
            });
×
NEW
75
        $progressBar->finish();
×
NEW
76
        $progressBar->setMessage('');
×
NEW
77
        $io->newLine(2);
×
78

79
        $io->info('Creating meta data file');
×
80
        $writer = new JsonFileWriter($this->getFullDestinationPath($destination));
×
81
        $writer->write($endpoints);
×
82
        $io->success('Written meta data to ' . $writer->getFullFileName());
×
83

84
        return 0;
×
85
    }
86

87
    private function getFullDestinationPath(string $destination): string
88
    {
NEW
89
        if (str_starts_with($destination, DIRECTORY_SEPARATOR) || str_starts_with($destination, '.')) {
×
90
            return $destination;
×
91
        }
92

93
        return $this->defaultDestinationDirectory() . DIRECTORY_SEPARATOR . $destination;
×
94
    }
95

96
    private function defaultDestinationDirectory(): string
97
    {
98
        $currentWorkingDirectory = getcwd();
×
99

100
        if ($currentWorkingDirectory === false) {
×
101
            throw new \RuntimeException('Unable to determine current working directory.');
×
102
        }
103

104
        return $currentWorkingDirectory;
×
105
    }
106
}
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