Skip to content

Commit 3ef292d

Browse files
committed
~
1 parent 170d7e0 commit 3ef292d

16 files changed

+64
-54
lines changed

lib/Builder/TableBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
use AlecRabbit\WCWidth\Core\Contract\ICachingClient;
1010
use AlecRabbit\WCWidth\Core\Contract\ICategoryParser;
1111
use AlecRabbit\WCWidth\Core\Contract\IFileSaver;
12-
use AlecRabbit\WCWidth\Core\Contract\IOutput;
1312
use AlecRabbit\WCWidth\Core\Contract\ITableHeaderExtractor;
1413
use AlecRabbit\WCWidth\Core\Contract\ITableProcessor;
1514
use AlecRabbit\WCWidth\Core\Contract\ITemplateRenderer;
1615
use AlecRabbit\WCWidth\Core\FileSaver;
1716
use AlecRabbit\WCWidth\Core\Logger;
18-
use AlecRabbit\WCWidth\Core\Output\NullOutput;
1917
use AlecRabbit\WCWidth\Core\TableHeaderExtractor;
2018
use AlecRabbit\WCWidth\Core\TableProcessor;
2119
use AlecRabbit\WCWidth\Core\TemplateRenderer;
@@ -153,4 +151,4 @@ private function getHeaders(string $version): array
153151
}
154152

155153

156-
}
154+
}

lib/Command/GenerateTablesCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ protected function configure(): void
3232
'd',
3333
InputOption::VALUE_NONE,
3434
'Enable debug mode for Twig template engine.'
35-
);
35+
)
36+
;
3637
}
3738

3839
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -82,4 +83,4 @@ protected function memoryReport(): string
8283
number_format(memory_get_peak_usage(true) / 1024),
8384
);
8485
}
85-
}
86+
}

lib/Core/CachingClient.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AlecRabbit\WCWidth\Core;
66

77
use AlecRabbit\WCWidth\Core\Contract\ICachingClient;
8+
use Exception;
89
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
910
use Symfony\Component\HttpClient\HttpClient;
1011
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -59,12 +60,12 @@ private function assertResponse(ResponseInterface $response): void
5960
$statusCode = $response->getStatusCode();
6061
Logger::debug(sprintf('Status code: %s', $statusCode));
6162
if (200 !== $statusCode) {
62-
throw new \Exception('Error: Status code "' . $statusCode . '". Url: "' . $response->getInfo('url') . '"');
63+
throw new Exception('Error: Status code "' . $statusCode . '". Url: "' . $response->getInfo('url') . '"');
6364
}
6465
$contentType = $response->getHeaders()['content-type'][0];
6566
Logger::debug(sprintf('Content type: %s', $contentType));
6667
if (!str_contains($contentType, 'text/plain')) {
67-
throw new \Exception('Error: Content type "' . $contentType . '"');
68+
throw new Exception('Error: Content type "' . $contentType . '"');
6869
}
6970
}
70-
}
71+
}

lib/Core/CategoryParser.php

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

77
use AlecRabbit\WCWidth\Core\Contract\ICategoryParser;
88

9+
use function trim;
10+
911
final class CategoryParser implements ICategoryParser
1012
{
1113

@@ -21,8 +23,8 @@ public function parse(string $data, array $categories): iterable
2123
[$data, $comment] = $this->split($line);
2224
$data_fields = explode(';', $data);
2325
if ($data_fields[1] ?? false) {
24-
$codepoints = \trim($data_fields[0] ?? '');
25-
$properties = \trim($data_fields[1] ?? '');
26+
$codepoints = trim($data_fields[0] ?? '');
27+
$properties = trim($data_fields[1] ?? '');
2628
if (in_array($properties, $categories, true)) {
2729
if (str_contains($codepoints, '..')) {
2830
[$start, $end] = explode('..', $codepoints);
@@ -56,6 +58,14 @@ private function split(string $line): array
5658
];
5759
}
5860

61+
private function getSorter(): callable
62+
{
63+
return
64+
static function (TableEntry $a, TableEntry $b): int {
65+
return $a->start <=> $b->start;
66+
};
67+
}
68+
5969
private function normalizeValue(string $value): string
6070
{
6171
return
@@ -67,12 +77,4 @@ private function normalizeValue(string $value): string
6777
STR_PAD_LEFT
6878
);
6979
}
70-
71-
private function getSorter(): callable
72-
{
73-
return
74-
static function (TableEntry $a, TableEntry $b): int {
75-
return $a->start <=> $b->start;
76-
};
77-
}
78-
}
80+
}

lib/Core/Contract/ICachingClient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
23
declare(strict_types=1);
34
// 27.02.23
45
namespace AlecRabbit\WCWidth\Core\Contract;
56

67
interface ICachingClient
78
{
89
public function get(string $url): string;
9-
}
10+
}

lib/Core/Contract/ICategoryParser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
23
declare(strict_types=1);
34
// 27.02.23
45
namespace AlecRabbit\WCWidth\Core\Contract;
56

67
interface ICategoryParser
78
{
89
public function parse(string $data, array $categories);
9-
}
10+
}

lib/Core/Contract/IFileSaver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
23
declare(strict_types=1);
34
// 28.02.23
45
namespace AlecRabbit\WCWidth\Core\Contract;
56

67
interface IFileSaver
78
{
89
public function save(string $filename, string $content): void;
9-
}
10+
}

lib/Core/Contract/IOutput.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34
// 01.03.23
45
namespace AlecRabbit\WCWidth\Core\Contract;
@@ -14,4 +15,4 @@ interface IOutput
1415
public function write(string|iterable $messages, bool $newline = false, int $options = 0): void;
1516

1617
public function writeln(string|iterable $messages, int $options = 0): void;
17-
}
18+
}

lib/Core/Contract/ITableEntry.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
declare(strict_types=1);
34
// 01.03.23
45
namespace AlecRabbit\WCWidth\Core\Contract;
56

67
interface ITableEntry
78
{
8-
public function normalizedStart():string;
9+
public function normalizedStart(): string;
910

10-
public function normalizedEnd():string;
11-
}
11+
public function normalizedEnd(): string;
12+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
23
declare(strict_types=1);
34
// 28.02.23
45
namespace AlecRabbit\WCWidth\Core\Contract;
56

67
interface ITemplateRenderer
78
{
89
public function render(string $type, array $data, ?array $options = null): string;
9-
}
10+
}

lib/Core/Contract/TableHeader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34
// 02.03.23
45
namespace AlecRabbit\WCWidth\Core\Contract;
@@ -9,7 +10,6 @@ public function __construct(
910
public string $url,
1011
public string $name,
1112
public string $date,
12-
)
13-
{
13+
) {
1414
}
15-
}
15+
}

lib/Core/FileDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34
// 28.02.23
45
namespace AlecRabbit\WCWidth\Core;
@@ -11,8 +12,7 @@ public function __construct(
1112
protected string $filename,
1213
protected string $template,
1314
protected mixed $data,
14-
)
15-
{
15+
) {
1616
self::assertData($this->data);
1717
}
1818

lib/Core/Logger.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use AlecRabbit\WCWidth\Core\Contract\ILogger;
88
use AlecRabbit\WCWidth\Core\Contract\IOutput;
9+
use LogicException;
910

1011
final class Logger implements ILogger
1112
{
@@ -17,7 +18,7 @@ public static function setOutput(IOutput $output): void
1718
return;
1819
}
1920
if (self::$output instanceof IOutput) {
20-
throw new \LogicException('Output already set.');
21+
throw new LogicException('Output already set.');
2122
}
2223
self::$output = $output;
2324
}
@@ -27,16 +28,6 @@ public static function debug(string $message): void
2728
self::message($message, 'fg=gray', IOutput::VERBOSITY_DEBUG);
2829
}
2930

30-
public static function info(string $message): void
31-
{
32-
self::message($message, 'info', IOutput::VERBOSITY_NORMAL);
33-
}
34-
35-
public static function comment(string $message): void
36-
{
37-
self::message($message, 'comment', IOutput::VERBOSITY_VERBOSE);
38-
}
39-
4031
private static function message(string $message, string $color, int $verbosity): void
4132
{
4233
if (self::$output instanceof IOutput) {
@@ -51,8 +42,18 @@ private static function message(string $message, string $color, int $verbosity):
5142
}
5243
}
5344

45+
public static function info(string $message): void
46+
{
47+
self::message($message, 'info', IOutput::VERBOSITY_NORMAL);
48+
}
49+
50+
public static function comment(string $message): void
51+
{
52+
self::message($message, 'comment', IOutput::VERBOSITY_VERBOSE);
53+
}
54+
5455
public static function error(string $message): void
5556
{
5657
self::message($message, 'error', IOutput::VERBOSITY_QUIET);
5758
}
58-
}
59+
}

lib/Core/TableEntry.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ public function normalizedStart(): string
2323
return self::normalizeValue($this->start);
2424
}
2525

26-
public function normalizedEnd(): string
27-
{
28-
return self::normalizeValue($this->end);
29-
}
30-
3126
private static function normalizeValue(int $value): string
3227
{
3328
return
@@ -39,4 +34,9 @@ private static function normalizeValue(int $value): string
3934
STR_PAD_LEFT
4035
);
4136
}
37+
38+
public function normalizedEnd(): string
39+
{
40+
return self::normalizeValue($this->end);
41+
}
4242
}

lib/Core/TableHeaderExtractor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
use AlecRabbit\WCWidth\Core\Contract\ICachingClient;
99
use AlecRabbit\WCWidth\Core\Contract\TableHeader;
10+
use RuntimeException;
1011

1112
final class TableHeaderExtractor implements Contract\ITableHeaderExtractor
1213
{
1314
private const REGEX = '/(DerivedGeneralCategory|EastAsianWidth)-(.+)\.txt/';
1415

1516
public function __construct(
1617
protected ICachingClient $client,
17-
)
18-
{
18+
) {
1919
}
2020

2121

@@ -34,6 +34,6 @@ public function extractHeader(string $url): TableHeader
3434
);
3535
}
3636
}
37-
throw new \RuntimeException(sprintf('Header not found in %s', $url));
37+
throw new RuntimeException(sprintf('Header not found in %s', $url));
3838
}
3939
}

lib/Core/TemplateRenderer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace AlecRabbit\WCWidth\Core;
66

77
use AlecRabbit\WCWidth\Core\Contract\ITemplateRenderer;
8+
use InvalidArgumentException;
89
use Twig\Environment;
910
use Twig\Extension\DebugExtension;
1011
use Twig\Loader\FilesystemLoader;
@@ -64,7 +65,7 @@ private function getTemplate(string $type): string
6465
'versions' => 'versions.php.twig',
6566
'zero' => 'zero.php.twig',
6667
'wide' => 'wide.php.twig',
67-
default => throw new \InvalidArgumentException(sprintf('Unknown template type: "%s".', $type)),
68+
default => throw new InvalidArgumentException(sprintf('Unknown template type: "%s".', $type)),
6869
};
6970
}
70-
}
71+
}

0 commit comments

Comments
 (0)