Skip to content

Commit d95a89b

Browse files
committed
rm config setters and getters
1 parent 19e9ce9 commit d95a89b

File tree

7 files changed

+17
-137
lines changed

7 files changed

+17
-137
lines changed

phpstan-baseline.neon

Whitespace-only changes.

phpstan.neon.dist

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
includes:
2-
- phpstan-baseline.neon
3-
41
parameters:
5-
level: 9
2+
level: max
63
paths:
74
- src
85
tmpDir: build/phpstan

src/Dompurify/DompurifyCli.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ public function configure(ConfigInterface $config): static
2424

2525
public function setup(): void
2626
{
27-
$process = new Process([$this->config->getNpmPath(), 'i'], __DIR__);
27+
$process = new Process([$this->config->npm, 'i'], __DIR__);
2828
$process->mustRun();
2929
}
3030

3131
public function exec(string $html): string
3232
{
3333
$htmlFile = $this->saveHtml($html);
3434

35-
$process = new Process([$this->config->getNodePath(), $this->binPath(), $htmlFile]);
35+
$process = new Process([$this->config->node, $this->binPath(), $htmlFile]);
3636
$process->mustRun();
3737

3838
$output = $process->getOutput();

src/Dompurify/DompurifyCliConfig.php

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,20 @@
33
namespace Medilies\Xssless\Dompurify;
44

55
use Medilies\Xssless\ConfigInterface;
6-
use Medilies\Xssless\XsslessException;
76

87
class DompurifyCliConfig implements ConfigInterface
98
{
109
private readonly string $class;
1110

12-
private string $nodePath;
13-
14-
private string $npmPath;
15-
1611
public function __construct(
17-
mixed $nodePath,
18-
mixed $npmPath,
12+
public string $node,
13+
public string $npm,
1914
) {
2015
$this->class = DompurifyCli::class;
21-
$this->setNodePath($nodePath);
22-
$this->setNpmPath($npmPath);
2316
}
2417

2518
public function getClass(): string
2619
{
2720
return $this->class;
2821
}
29-
30-
public function setNodePath(mixed $value): static
31-
{
32-
if (! is_string($value)) {
33-
throw new XsslessException('nodePath must be a string.');
34-
}
35-
36-
$this->nodePath = $value;
37-
38-
return $this;
39-
}
40-
41-
public function setNpmPath(mixed $value): static
42-
{
43-
if (! is_string($value)) {
44-
throw new XsslessException('npmPath must be a string.');
45-
}
46-
47-
$this->npmPath = $value;
48-
49-
return $this;
50-
}
51-
52-
public function getNodePath(): string
53-
{
54-
return $this->nodePath;
55-
}
56-
57-
public function getNpmPath(): string
58-
{
59-
return $this->npmPath;
60-
}
6122
}

src/Dompurify/DompurifyService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public function configure(ConfigInterface $config): static
3131

3232
public function setup(): void
3333
{
34-
$process = new Process([$this->config->npmPath, 'i'], __DIR__);
34+
$process = new Process([$this->config->npm, 'i'], __DIR__);
3535
$process->mustRun();
3636
}
3737

3838
public function send(string $html): string
3939
{
40-
$url = "http://{$this->config->getHost()}:{$this->config->getPort()}";
40+
$url = "http://{$this->config->host}:{$this->config->port}";
4141

4242
$client = new Client;
4343
$res = $client->post($url, [
@@ -52,7 +52,7 @@ public function send(string $html): string
5252
public function start(): static
5353
{
5454
$this->serviceProcess = new Process([
55-
$this->config->nodePath,
55+
$this->config->node,
5656
__DIR__.DIRECTORY_SEPARATOR.'http.js',
5757
$this->config->host,
5858
$this->config->port,

src/Dompurify/DompurifyServiceConfig.php

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -3,100 +3,22 @@
33
namespace Medilies\Xssless\Dompurify;
44

55
use Medilies\Xssless\ConfigInterface;
6-
use Medilies\Xssless\XsslessException;
76

87
class DompurifyServiceConfig implements ConfigInterface
98
{
10-
public string $class;
9+
public readonly string $class;
1110

12-
public string $nodePath;
13-
14-
public string $npmPath;
15-
16-
public string $host;
17-
18-
public int $port;
19-
20-
// TODO: use type guard
2111
public function __construct(
22-
mixed $nodePath,
23-
mixed $npmPath,
24-
mixed $host,
25-
mixed $port,
12+
public string $node,
13+
public string $npm,
14+
public string $host,
15+
public int $port,
2616
) {
2717
$this->class = DompurifyService::class;
28-
$this->setNodePath($nodePath);
29-
$this->setNpmPath($npmPath);
30-
$this->setHost($host);
31-
$this->setPort($port);
3218
}
3319

3420
public function getClass(): string
3521
{
3622
return $this->class;
3723
}
38-
39-
public function setNodePath(mixed $value): static
40-
{
41-
if (! is_string($value)) {
42-
throw new XsslessException('nodePath must be a string.');
43-
}
44-
45-
$this->nodePath = $value;
46-
47-
return $this;
48-
}
49-
50-
public function setHost(mixed $value): static
51-
{
52-
if (! is_string($value)) {
53-
throw new XsslessException('host must be a string.');
54-
}
55-
56-
$this->host = $value;
57-
58-
return $this;
59-
}
60-
61-
public function setPort(mixed $value): static
62-
{
63-
if (! is_int($value)) {
64-
throw new XsslessException('host must be a string.');
65-
}
66-
67-
$this->port = $value;
68-
69-
return $this;
70-
}
71-
72-
public function setNpmPath(mixed $value): static
73-
{
74-
if (! is_string($value)) {
75-
throw new XsslessException('npmPath must be a string.');
76-
}
77-
78-
$this->npmPath = $value;
79-
80-
return $this;
81-
}
82-
83-
public function getNodePath(): string
84-
{
85-
return $this->nodePath;
86-
}
87-
88-
public function getNpmPath(): string
89-
{
90-
return $this->npmPath;
91-
}
92-
93-
public function getHost(): string
94-
{
95-
return $this->host;
96-
}
97-
98-
public function getPort(): int
99-
{
100-
return $this->port;
101-
}
10224
}

src/laravel/config/xssless.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
'drivers' => [
1010
'dompurify-cli' => new DompurifyCliConfig(
11-
env('NODE_PATH', 'node'),
12-
env('NPM_PATH', 'npm'),
11+
env('NODE_PATH', 'node'), // @phpstan-ignore argument.type
12+
env('NPM_PATH', 'npm'), // @phpstan-ignore argument.type
1313
),
1414
'dompurify-service' => new DompurifyServiceConfig(
15-
env('NODE_PATH', 'node'),
16-
env('NPM_PATH', 'npm'),
15+
env('NODE_PATH', 'node'), // @phpstan-ignore argument.type
16+
env('NPM_PATH', 'npm'), // @phpstan-ignore argument.type
1717
'127.0.0.1',
1818
63000,
1919
),

0 commit comments

Comments
 (0)