Skip to content

Commit cb7c8bd

Browse files
committed
Update code
- add return type declaration - add argument type hints - add strict types
1 parent 8007814 commit cb7c8bd

39 files changed

+211
-138
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
],
2222
"require": {
2323
"php": "^7.2",
24-
"symfony/process": "^4.0"
24+
"symfony/process": "^4.0",
25+
"ext-iconv": "*",
26+
"ext-dom": "*",
27+
"ext-libxml": "*"
2528
},
2629
"require-dev": {
2730
"phpunit/phpunit": "^7.5",

src/Aspell/Aspell.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller.
46
*
@@ -29,7 +31,7 @@ class Aspell extends Ispell
2931
*
3032
* @var string[]|null
3133
*/
32-
private $supportedLanguages = null;
34+
private $supportedLanguages;
3335

3436
/**
3537
* @var Dictionary
@@ -43,7 +45,7 @@ class Aspell extends Ispell
4345
*
4446
* @since 1.6
4547
*/
46-
public function __construct($binaryPath = 'aspell')
48+
public function __construct(string $binaryPath = 'aspell')
4749
{
4850
parent::__construct($binaryPath);
4951
}
@@ -57,10 +59,9 @@ public function __construct($binaryPath = 'aspell')
5759
* @throws InvalidArgumentException
5860
* @throws LogicException
5961
* @throws RuntimeException
60-
*
6162
* @since 1.6
6263
*/
63-
public function getSupportedLanguages()
64+
public function getSupportedLanguages(): array
6465
{
6566
if (null === $this->supportedLanguages) {
6667
$process = $this->createProcess('dump dicts');
@@ -96,7 +97,7 @@ public function getSupportedLanguages()
9697
/**
9798
* @param Dictionary $dictionary
9899
*/
99-
public function setPersonalDictionary(Dictionary $dictionary)
100+
public function setPersonalDictionary(Dictionary $dictionary): void
100101
{
101102
$this->personalDictionary = $dictionary;
102103
}
@@ -111,7 +112,7 @@ public function setPersonalDictionary(Dictionary $dictionary)
111112
*
112113
* @since 1.6
113114
*/
114-
protected function createArguments(EncodingAwareSource $source, array $languages)
115+
protected function createArguments(EncodingAwareSource $source, array $languages): array
115116
{
116117
$args = [
117118
// Input encoding

src/Dictionary.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller.
46
*
@@ -28,7 +30,7 @@ public function __construct(string $path)
2830
/**
2931
* @return string
3032
*/
31-
public function getPath()
33+
public function getPath(): string
3234
{
3335
return $this->dictionaryPath;
3436
}

src/Exception/EnvironmentException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller.
46
*

src/Exception/ExternalProgramFailedException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller.
46
*

src/Exception/PhpSpellerException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller.
46
*

src/Exception/RuntimeException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller.
46
*

src/Exception/SourceException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller.
46
*

src/ExternalSpeller.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller.
46
*
@@ -51,9 +53,9 @@ abstract class ExternalSpeller implements Speller
5153
*
5254
* @since 1.6
5355
*/
54-
public function __construct($binaryPath)
56+
public function __construct(string $binaryPath)
5557
{
56-
$this->binary = (string)$binaryPath;
58+
$this->binary = $binaryPath;
5759
}
5860

5961
/**
@@ -69,7 +71,7 @@ public function __construct($binaryPath)
6971
* @see http://tools.ietf.org/html/bcp47
7072
* @since 1.6
7173
*/
72-
public function checkText(EncodingAwareSource $source, array $languages)
74+
public function checkText(EncodingAwareSource $source, array $languages): array
7375
{
7476
$process = $this->createProcess($this->createArguments($source, $languages));
7577
$process->setEnv($this->createEnvVars($source, $languages));
@@ -120,7 +122,7 @@ public function checkText(EncodingAwareSource $source, array $languages)
120122
* @see \Symfony\Component\Process\Process::setTimeout()
121123
* @since 1.6
122124
*/
123-
public function setTimeout($seconds)
125+
public function setTimeout($seconds): void
124126
{
125127
$this->timeout = $seconds;
126128
}
@@ -134,16 +136,16 @@ public function setTimeout($seconds)
134136
*
135137
* @since 1.6
136138
*/
137-
protected function composeCommand($args)
139+
protected function composeCommand($args): string
138140
{
139141
$command = $this->getBinary();
140142

141-
if (is_array($args)) {
143+
if (\is_array($args)) {
142144
$args = implode(' ', $args);
143145
}
144146

145147
// Only append args if we have some
146-
$command .= strlen($args) ? ' ' . $args : '';
148+
$command .= $args !== '' ? ' ' . $args : '';
147149

148150
return $command;
149151
}
@@ -155,7 +157,7 @@ protected function composeCommand($args)
155157
*
156158
* @since 1.6
157159
*/
158-
protected function getBinary()
160+
protected function getBinary(): string
159161
{
160162
return $this->binary;
161163
}
@@ -172,7 +174,7 @@ protected function getBinary()
172174
*
173175
* @SuppressWarnings(PMD.UnusedFormalParameter)
174176
*/
175-
protected function createArguments(EncodingAwareSource $source, array $languages)
177+
protected function createArguments(EncodingAwareSource $source, array $languages): array
176178
{
177179
return [];
178180
}
@@ -189,7 +191,7 @@ protected function createArguments(EncodingAwareSource $source, array $languages
189191
*
190192
* @SuppressWarnings(PMD.UnusedFormalParameter)
191193
*/
192-
protected function createEnvVars(EncodingAwareSource $source, array $languages)
194+
protected function createEnvVars(EncodingAwareSource $source, array $languages): array
193195
{
194196
return [];
195197
}
@@ -203,7 +205,7 @@ protected function createEnvVars(EncodingAwareSource $source, array $languages)
203205
*
204206
* @since 1.6
205207
*/
206-
abstract protected function parseOutput($output);
208+
abstract protected function parseOutput(string $output): array;
207209

208210
/**
209211
* Create new instance of external program.
@@ -217,7 +219,7 @@ abstract protected function parseOutput($output);
217219
*
218220
* @since 1.6
219221
*/
220-
protected function createProcess($args = null)
222+
protected function createProcess($args = null): Process
221223
{
222224
$command = $this->composeCommand($args);
223225

@@ -239,13 +241,13 @@ protected function createProcess($args = null)
239241
*
240242
* @since 2.0
241243
*/
242-
private function composeProcess(string $command)
244+
private function composeProcess(string $command): Process
243245
{
244246
if ($this->process === null) {
245-
$this->process = new Process($command);
247+
$this->process = new Process([$command]);
246248
}
247249

248-
$this->process->inheritEnvironmentVariables(true);
250+
$this->process->inheritEnvironmentVariables();
249251
$this->process->setTimeout($this->timeout);
250252
$this->process->setCommandLine($command);
251253

@@ -257,7 +259,7 @@ private function composeProcess(string $command)
257259
*
258260
* @return self
259261
*/
260-
public function setProcess(Process $process)
262+
public function setProcess(Process $process): self
261263
{
262264
$this->process = $process;
263265

src/Helper/LanguageMapper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* PHP Speller
46
*
@@ -38,7 +40,7 @@ class LanguageMapper
3840
* @link http://tools.ietf.org/html/bcp47
3941
* @since 1.0
4042
*/
41-
public function map(array $requested, array $supported)
43+
public function map(array $requested, array $supported): array
4244
{
4345
$index = [];
4446
foreach ($supported as $tag) {
@@ -88,7 +90,7 @@ public function map(array $requested, array $supported)
8890
*
8991
* @since 1.1
9092
*/
91-
public function setPreferredMappings(array $mappings)
93+
public function setPreferredMappings(array $mappings): void
9294
{
9395
foreach ($mappings as $language => $map) {
9496
$this->preferred[$language] = (array) $map;

0 commit comments

Comments
 (0)