Skip to content

Commit 8d817f3

Browse files
committed
chore(php8): rector elasticms-cli
Applied rules: * ClassPropertyAssignToConstructorPromotionRector (https://wiki.php.net/rfc/constructor_promotion php/php-src#5291) * StrStartsWithRector (https://wiki.php.net/rfc/add_str_starts_with_and_ends_with_functions) * NullToStrictStringFuncCallArgRector * ReadOnlyPropertyRector (https://wiki.php.net/rfc/readonly_properties_v2)
1 parent 57b56d2 commit 8d817f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+106
-279
lines changed

elasticms-cli/src/Client/Audit/AuditManager.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121

2222
class AuditManager
2323
{
24-
private LoggerInterface $logger;
25-
private bool $lighthouse;
26-
private bool $pa11y;
27-
private bool $tika;
28-
private bool $tikaJar;
29-
private CacheManager $cacheManager;
30-
private bool $all;
3124
private Pa11yWrapper $pa11yAudit;
3225
private LighthouseWrapper $lighthouseAudit;
3326
private TikaWrapper $tikaLocaleAudit;
@@ -36,20 +29,9 @@ class AuditManager
3629
private TikaWrapper $tikaMetaAudit;
3730
private TikaMetaResponse $metaRequest;
3831
private AsyncResponse $htmlRequest;
39-
private int $tikaMaxSize;
40-
private string $tikaServerUrl;
4132

42-
public function __construct(CacheManager $cacheManager, LoggerInterface $logger, bool $all, bool $pa11y, bool $lighthouse, bool $tika, bool $tikaJar, string $tikaServerUrl, int $tikaMaxSize)
33+
public function __construct(private readonly CacheManager $cacheManager, private readonly LoggerInterface $logger, private readonly bool $all, private readonly bool $pa11y, private readonly bool $lighthouse, private readonly bool $tika, private readonly bool $tikaJar, private readonly string $tikaServerUrl, private readonly int $tikaMaxSize)
4334
{
44-
$this->cacheManager = $cacheManager;
45-
$this->logger = $logger;
46-
$this->pa11y = $pa11y;
47-
$this->lighthouse = $lighthouse;
48-
$this->tikaJar = $tikaJar;
49-
$this->tika = $tika;
50-
$this->all = $all;
51-
$this->tikaMaxSize = $tikaMaxSize;
52-
$this->tikaServerUrl = $tikaServerUrl;
5335
}
5436

5537
public function analyze(Url $url, HttpResult $result, Report $report): AuditResult
@@ -256,8 +238,8 @@ private function addTikaJarAudits(AuditResult $audit, HttpResult $result): void
256238
$audit->addLinks(new Url($link, $audit->getUrl()->getUrl()));
257239
}
258240
$meta = $this->tikaMetaAudit->getJson();
259-
$audit->setTitle(null === ($meta['dc:title'] ?? null) ? null : \trim($meta['dc:title']));
260-
$audit->setAuthor(null === ($meta['dc:author'] ?? null) ? null : \trim($meta['dc:author']));
241+
$audit->setTitle(null === ($meta['dc:title'] ?? null) ? null : \trim((string) $meta['dc:title']));
242+
$audit->setAuthor(null === ($meta['dc:author'] ?? null) ? null : \trim((string) $meta['dc:author']));
261243
} catch (\Throwable $e) {
262244
$this->logger->critical(\sprintf('Tika audit for %s failed: %s', $audit->getUrl()->getUrl(), $e->getMessage()));
263245
}
@@ -281,7 +263,7 @@ private function addHtmlAudit(AuditResult $audit, HttpResult $result, Report $re
281263
for ($i = 0; $i < $content->count(); ++$i) {
282264
$item = $content->eq($i);
283265
$href = $item->attr('href');
284-
if (null === $href || 0 === \strlen($href) || '#' === \substr($href, 0, 1)) {
266+
if (null === $href || 0 === \strlen($href) || str_starts_with($href, '#')) {
285267
continue;
286268
}
287269
$audit->addLinks(new Url($href, $audit->getUrl()->getUrl()));

elasticms-cli/src/Client/Audit/AuditResult.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
class AuditResult
1313
{
14-
private Url $url;
1514
private string $hash;
1615
/** @var Url[] */
1716
private array $links = [];
@@ -35,7 +34,7 @@ class AuditResult
3534
private ?float $accessibility = null;
3635
private ?float $bestPractices = null;
3736
private ?string $mimetype = null;
38-
private \DateTimeImmutable $datetime;
37+
private readonly \DateTimeImmutable $datetime;
3938
private ?\DateTimeImmutable $tikaDatetime = null;
4039
private ?\DateTimeImmutable $lighthouseDatetime = null;
4140
private ?\DateTimeImmutable $pa11yDatetime = null;
@@ -49,9 +48,8 @@ class AuditResult
4948
private int $size = 0;
5049
private ?string $description = null;
5150

52-
public function __construct(Url $url)
51+
public function __construct(private readonly Url $url)
5352
{
54-
$this->url = $url;
5553
$this->datetime = new \DateTimeImmutable();
5654
}
5755

elasticms-cli/src/Client/Audit/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Cache
2525
private ?string $lastUpdated = null;
2626
private ?string $current = null;
2727
private ?string $status = null;
28-
private \DateTimeImmutable $startedDatetime;
28+
private readonly \DateTimeImmutable $startedDatetime;
2929
private int $startedAt;
3030
private Report $report;
3131

elasticms-cli/src/Client/Audit/Report.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Report
2222
private array $ignoredLinks = [['URL', 'Error message', 'Referrers']];
2323
/** @var string[][] */
2424
private array $warnings = [['URL', 'Warning message', 'Referrer']];
25-
private SpreadsheetGeneratorService $spreadsheetGeneratorService;
25+
private readonly SpreadsheetGeneratorService $spreadsheetGeneratorService;
2626

2727
public function __construct()
2828
{

elasticms-cli/src/Client/Audit/SecurityWarning.php

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

77
class SecurityWarning
88
{
9-
private string $type;
10-
private string $value;
11-
12-
public function __construct(string $type, string $value)
9+
public function __construct(private readonly string $type, private readonly string $value)
1310
{
14-
$this->type = $type;
15-
$this->value = $value;
1611
}
1712

1813
public function getType(): string

elasticms-cli/src/Client/Data/Column/DataColumn.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99

1010
abstract class DataColumn
1111
{
12-
public int $columnIndex;
13-
14-
public const TYPES = [
12+
final public const TYPES = [
1513
'businessId' => DataColumnBusinessId::class,
1614
];
1715

18-
public function __construct(int $index)
16+
public function __construct(public int $columnIndex)
1917
{
20-
$this->columnIndex = $index;
2118
}
2219

2320
public function transform(Data $data, TransformContext $transformContext): void

elasticms-cli/src/Client/Data/Column/DataColumnBusinessId.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ final class DataColumnBusinessId extends DataColumn
2020
public string $contentType;
2121
public int $scrollSize;
2222
/** @var ?array<mixed> */
23-
private ?array $scrollMust;
24-
private bool $removeNotFound;
23+
private readonly ?array $scrollMust;
24+
private readonly bool $removeNotFound;
2525

2626
private int $notFound = 0;
2727
/** @var array<mixed> */

elasticms-cli/src/Client/Data/Column/TransformContext.php

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

1010
class TransformContext
1111
{
12-
public CoreApiInterface $coreApi;
13-
public SymfonyStyle $io;
14-
15-
public function __construct(CoreApiInterface $coreApi, SymfonyStyle $io)
12+
public function __construct(public CoreApiInterface $coreApi, public SymfonyStyle $io)
1613
{
17-
$this->coreApi = $coreApi;
18-
$this->io = $io;
1914
}
2015
}

elasticms-cli/src/Client/Data/Data.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
*/
1010
class Data implements \Countable, \IteratorAggregate
1111
{
12-
/** @var array<mixed> */
13-
private array $data;
14-
1512
/**
1613
* @param array<mixed> $data
1714
*/
18-
public function __construct(array $data)
15+
public function __construct(private array $data)
1916
{
20-
$this->data = $data;
2117
}
2218

2319
public function slice(?int $offset, ?int $length = null): void

elasticms-cli/src/Client/Document/Update/DocumentUpdateConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class DocumentUpdateConfig
1818
public int $updateIndexEmsId;
1919
/** @var UpdateMap[] */
2020
public array $updateMapping;
21-
private ?string $collectionField;
21+
private readonly ?string $collectionField;
2222

2323
/**
2424
* @param array<mixed> $config
@@ -41,7 +41,7 @@ public static function fromFile(string $filename): self
4141
{
4242
try {
4343
$fileContent = \file_get_contents($filename);
44-
} catch (\Throwable $e) {
44+
} catch (\Throwable) {
4545
$fileContent = false;
4646
}
4747

0 commit comments

Comments
 (0)