Skip to content

Commit 910700b

Browse files
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
1 parent c941e4a commit 910700b

22 files changed

+141
-197
lines changed

.github/workflows/build.yaml

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,6 @@ jobs:
1313
strategy:
1414
matrix:
1515
include:
16-
- php: 7.2
17-
allow_fail: false
18-
name: 'PHP 7.2 with latest deps'
19-
- php: 7.2
20-
allow_fail: false
21-
composer_update_flags: '--prefer-lowest --prefer-stable'
22-
name: 'PHP 7.2 with lowest stable deps'
23-
- php: 7.3
24-
allow_fail: false
25-
name: 'PHP 7.3 with latest deps'
26-
- php: 7.3
27-
allow_fail: false
28-
composer_update_flags: '--prefer-lowest --prefer-stable'
29-
name: 'PHP 7.3 with lowest stable deps'
30-
- php: 7.4
31-
allow_fail: false
32-
name: 'PHP 7.4 with latest deps'
33-
- php: 7.4
34-
allow_fail: false
35-
composer_update_flags: '--prefer-lowest --prefer-stable'
36-
name: 'PHP 7.4 with lowest stable deps'
3716
- php: 8.0
3817
allow_fail: false
3918
php_ini: 'xdebug.coverage_enable=On'
@@ -52,11 +31,29 @@ jobs:
5231
composer_update_flags: '--prefer-lowest --prefer-stable'
5332
php_ini: 'xdebug.coverage_enable=On'
5433
name: 'PHP 8.1 with lowest stable deps'
34+
- php: 8.2
35+
allow_fail: true
36+
php_ini: 'xdebug.coverage_enable=On'
37+
name: 'PHP 8.2 with latest deps'
38+
- php: 8.2
39+
allow_fail: true
40+
composer_update_flags: '--prefer-lowest --prefer-stable'
41+
php_ini: 'xdebug.coverage_enable=On'
42+
name: 'PHP 8.2 with lowest stable deps'
43+
- php: 8.3
44+
allow_fail: true
45+
php_ini: 'xdebug.coverage_enable=On'
46+
name: 'PHP 8.3 with latest deps'
47+
- php: 8.3
48+
allow_fail: true
49+
composer_update_flags: '--prefer-lowest --prefer-stable'
50+
php_ini: 'xdebug.coverage_enable=On'
51+
name: 'PHP 8.3 with lowest stable deps'
5552

5653
runs-on: ubuntu-latest
5754

5855
steps:
59-
- uses: actions/checkout@v2
56+
- uses: actions/checkout@v3
6057

6158
- name: Validate composer.json and composer.lock
6259
run: composer validate

MetaDataTool/Command/MetaDataBuilderCommand.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
use MetaDataTool\Crawlers\MainPageCrawler;
1010
use MetaDataTool\Enum\KnownEntities;
1111
use MetaDataTool\JsonFileWriter;
12-
use MetaDataTool\PageRegistry;
12+
use MetaDataTool\ValueObjects\Endpoint;
1313
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Component\Console\Helper\ProgressBar;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Input\InputOption;
1617
use Symfony\Component\Console\Output\OutputInterface;
1718
use Symfony\Component\Console\Style\SymfonyStyle;
1819

1920
class MetaDataBuilderCommand extends Command
2021
{
21-
private const MAINPAGE = 'https://start.exactonline.nl/docs/HlpRestAPIResources.aspx';
22+
private const MAIN_PAGE = 'https://start.exactonline.nl/docs/HlpRestAPIResources.aspx';
2223
protected static $defaultName = 'run';
2324

24-
2525
protected function configure(): void
2626
{
2727
$this
@@ -52,22 +52,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5252
die(1);
5353
}
5454

55-
$io->info(['Scanning main page', self::MAINPAGE]);
56-
$mainPageCrawler = new MainPageCrawler(self::MAINPAGE);
55+
$io->info(['Scanning main page', self::MAIN_PAGE]);
56+
$mainPageCrawler = new MainPageCrawler(self::MAIN_PAGE);
5757
$pages = $mainPageCrawler->run();
5858
foreach (KnownEntities::keys() as $entity) {
5959
$pages->add('https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=' . $entity);
6060
}
6161

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

6569
$config = new EndpointCrawlerConfig(true);
6670
$endpoints = (new EndpointCrawler($config, $pages))
67-
->run(static function() use ($io): void {
68-
$io->progressAdvance(1);
71+
->run(static function(Endpoint $endpoint) use ($progressBar): void {
72+
$progressBar->advance(1);
73+
$progressBar->setMessage($endpoint->getDocumentation(), 'url');
6974
});
70-
$io->progressFinish();
75+
$progressBar->finish();
76+
$progressBar->setMessage('');
77+
$io->newLine(2);
7178

7279
$io->info('Creating meta data file');
7380
$writer = new JsonFileWriter($this->getFullDestinationPath($destination));
@@ -79,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7986

8087
private function getFullDestinationPath(string $destination): string
8188
{
82-
if (strpos($destination, DIRECTORY_SEPARATOR) === 0 || strpos($destination, '.') === 0) {
89+
if (str_starts_with($destination, DIRECTORY_SEPARATOR) || str_starts_with($destination, '.')) {
8390
return $destination;
8491
}
8592

MetaDataTool/Config/EndpointCrawlerConfig.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66

77
class EndpointCrawlerConfig
88
{
9-
/** @var bool */
10-
private $queueDiscoveredLinks;
11-
12-
public function __construct(bool $queueDiscoveredLinks)
9+
public function __construct(private bool $queueDiscoveredLinks)
1310
{
14-
$this->queueDiscoveredLinks = $queueDiscoveredLinks;
1511
}
1612

1713
public function shouldQueueDiscoveredLinks(): bool

MetaDataTool/Crawlers/EndpointCrawler.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,12 @@ class EndpointCrawler
2020
private const BASE_URL = 'https://start.exactonline.nl/docs/';
2121
private const ATTRIBUTE_HEADER_XPATH = '//table[@id="referencetable"]/tr[1]';
2222
private const ATTRIBUTE_ROWS_XPATH = '//table[@id="referencetable"]/tr[position()>1]';
23+
private PageRegistry $pagesToVisit;
24+
private PageRegistry $visitedPages;
25+
private ?Crawler $domCrawler = null;
2326

24-
/** @var EndpointCrawlerConfig */
25-
private $config;
26-
/** @var PageRegistry */
27-
private $pagesToVisit;
28-
/** @var PageRegistry */
29-
private $visitedPages;
30-
/** @var Crawler */
31-
private $domCrawler;
32-
33-
public function __construct(EndpointCrawlerConfig $config, ?PageRegistry $pagesToVisit = null)
27+
public function __construct(private EndpointCrawlerConfig $config, ?PageRegistry $pagesToVisit = null)
3428
{
35-
$this->config = $config;
3629
$this->pagesToVisit = $pagesToVisit ?? $this->createDefaultPagesToVisit();
3730
$this->visitedPages = new PageRegistry();
3831
}
@@ -83,7 +76,7 @@ private function crawlWebPage(string $url): ?Endpoint
8376
$scope = $this->domCrawler->filterXPath('//*[@id="scope"]')->first()->text();
8477
try {
8578
$uri = $this->domCrawler->filterXPath('//*[@id="serviceUri"]')->first()->text();
86-
} catch (\Exception $exception) {
79+
} catch (\Exception) {
8780
return null;
8881
}
8982
$supportedMethodsCrawler = $this->domCrawler->filterXPath('//input[@name="supportedmethods"]');
@@ -107,9 +100,7 @@ private function crawlWebPage(string $url): ?Endpoint
107100
return null;
108101
}
109102

110-
$columns = array_map(static function ($n) {
111-
return explode(' ', $n->nodeValue)[0];
112-
}, $header->children()->getIterator()->getArrayCopy());
103+
$columns = array_map(static fn($n) => explode(' ', $n->nodeValue)[0], $header->children()->getIterator()->getArrayCopy());
113104

114105
$propertyRowParserConfig = new PropertyRowParserConfig(
115106
array_search('Type', $columns, true) + 1,
@@ -122,7 +113,7 @@ private function crawlWebPage(string $url): ?Endpoint
122113

123114
$goodToKnows = $this->domCrawler->filterXPath('//*[@id="goodToKnow"]');
124115
$deprecationMessage = 'This endpoint is redundant and is going to be removed.';
125-
$isDeprecated = $goodToKnows->count() > 0 && strpos($goodToKnows->first()->text(), $deprecationMessage) !== false;
116+
$isDeprecated = $goodToKnows->count() > 0 && str_contains($goodToKnows->first()->text(), $deprecationMessage);
126117
return new Endpoint(
127118
$endpoint,
128119
$url,
@@ -137,7 +128,16 @@ private function crawlWebPage(string $url): ?Endpoint
137128

138129
private function fetchHtmlFromUrl(string $url): string
139130
{
140-
$html = file_get_contents($url);
131+
[,$basename] = explode('=', $url);
132+
$filename = sys_get_temp_dir() . '/exact-online-meta-data-tool-' . strtolower($basename) . '.html';
133+
134+
if (!file_exists($filename)) {
135+
$html = file_get_contents($url);
136+
file_put_contents($filename, $html);
137+
} else {
138+
$html = file_get_contents($filename);
139+
}
140+
141141
$this->visitedPages->add($url);
142142

143143
if ($html === false) {
@@ -166,16 +166,16 @@ private function getPropertyRowParser(PropertyRowParserConfig $config): \Closure
166166
if ($name === 'ID') {
167167
$httpMethods = $httpMethods->addDelete();
168168
}
169-
if (strpos($class, 'hideput') === false && strpos($class, 'showget') === false) {
169+
if (!str_contains($class, 'hideput') && !str_contains($class, 'showget')) {
170170
$httpMethods = $httpMethods->addPut();
171171
}
172-
if (strpos($class, 'hidepost') === false && strpos($class, 'showget') === false) {
172+
if (!str_contains($class, 'hidepost') && !str_contains($class, 'showget')) {
173173
$httpMethods = $httpMethods->addPost();
174174
}
175175
if ($name === 'ID') {
176176
$httpMethods = HttpMethodMask::all();
177177
}
178-
$hidden = strpos($node->attr('class') ?? '', 'hiderow') !== false;
178+
$hidden = str_contains($node->attr('class') ?? '', 'hiderow');
179179
$mandatory = strtolower(trim($node->filterXpath("//td[{$config->getMandatoryColumnIndex()}]")->text())) === 'true';
180180

181181
return new Property($name, $type, $description, $primaryKey, $httpMethods, $hidden, $mandatory);

MetaDataTool/Crawlers/MainPageCrawler.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99

1010
class MainPageCrawler
1111
{
12-
/** @var string */
13-
private $mainPage;
14-
15-
public function __construct(string $mainPage)
16-
{
17-
$this->mainPage = $mainPage;
18-
}
12+
public function __construct(private string $mainPage) {}
1913

2014
public function run(): PageRegistry
2115
{

MetaDataTool/Enum/KnownEntities.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class KnownEntities extends Enum
110110
private const ProjectProjectHourBudgets = 'ProjectProjectHourBudgets';
111111
private const ProjectProjectPlanning = 'ProjectProjectPlanning';
112112
private const ProjectProjectPlanningRecurring = 'ProjectProjectPlanningRecurring';
113+
private const ProjectProjectProgressReports = 'ProjectProjectProgressReports';
113114
private const ProjectProjectRestrictionEmployees = 'ProjectProjectRestrictionEmployees';
114115
private const ProjectProjectRestrictionItems = 'ProjectProjectRestrictionItems';
115116
private const ProjectProjectRestrictionRebillings = 'ProjectProjectRestrictionRebillings';

MetaDataTool/JsonFileWriter.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,17 @@ class JsonFileWriter
1111
{
1212
private const FILE_NAME = '/meta-data.json';
1313

14-
/** @var string */
15-
private $path;
16-
1714
/**
1815
* JsonFileWriter constructor.
19-
* @param string $path
2016
*/
21-
public function __construct(string $path)
17+
public function __construct(private string $path)
2218
{
23-
$this->path = $path;
2419
$this->ensureDirectoryAvailability($path);
2520
}
2621

2722
public function write(EndpointCollection $endpoints): void
2823
{
29-
file_put_contents($this->getFullFileName(), json_encode($endpoints, JSON_PRETTY_PRINT));
24+
file_put_contents($this->getFullFileName(), json_encode($endpoints, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT));
3025
}
3126

3227
public function getFullFileName(): string

MetaDataTool/PageRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class PageRegistry implements \Countable, \IteratorAggregate
1010
{
1111
/** @var string[] */
12-
private $pages = [];
12+
private array $pages;
1313

1414
public function __construct(string ...$pages)
1515
{

MetaDataTool/ValueObjects/Endpoint.php

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,16 @@
88

99
class Endpoint implements JsonSerializable
1010
{
11-
/** @var string */
12-
private $endpoint;
13-
/** @var string */
14-
private $documentation;
15-
/** @var string */
16-
private $scope;
17-
/** @var string */
18-
private $uri;
19-
/** @var HttpMethodMask */
20-
private $supportedHttpMethods;
21-
/** @var string */
22-
private $example;
23-
/** @var PropertyCollection */
24-
private $properties;
25-
/** @var bool */
26-
private $isDeprecated;
27-
2811
public function __construct(
29-
string $endpoint,
30-
string $documentation,
31-
string $scope,
32-
string $uri,
33-
HttpMethodMask $supportedHttpMethods,
34-
string $example,
35-
PropertyCollection $properties,
36-
bool $isDeprecated = false
37-
) {
38-
$this->endpoint = $endpoint;
39-
$this->documentation = $documentation;
40-
$this->scope = $scope;
41-
$this->uri = $uri;
42-
$this->supportedHttpMethods = $supportedHttpMethods;
43-
$this->example = $example;
44-
$this->properties = $properties;
45-
$this->isDeprecated = $isDeprecated;
46-
}
12+
private string $endpoint,
13+
private string $documentation,
14+
private string $scope,
15+
private string $uri,
16+
private HttpMethodMask $supportedHttpMethods,
17+
private string $example,
18+
private PropertyCollection $properties,
19+
private bool $isDeprecated = false
20+
) {}
4721

4822
public function getEndpoint(): string
4923
{

MetaDataTool/ValueObjects/HttpMethodMask.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ class HttpMethodMask implements JsonSerializable
1515
private const DELETE = 8;
1616
private const ALL = 15;
1717

18-
/** @var int */
19-
private $mask;
20-
21-
private function __construct(int $mask)
18+
private function __construct(private int $mask)
2219
{
23-
$this->mask = $mask;
2420
}
2521

2622
public static function none(): self

0 commit comments

Comments
 (0)