Skip to content

Commit 4426e97

Browse files
committed
enable strict_types in generator
(Continuing with pulling the changes from shish/safe into tcm/safe in small hopefully easy-to-review chunks)
1 parent d43727a commit 4426e97

32 files changed

+95
-87
lines changed

generator/src/ComposerJsonEditor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

generator/src/DeprecateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

@@ -23,7 +24,7 @@ protected function configure(): void
2324
;
2425
}
2526

26-
protected function execute(InputInterface $input, OutputInterface $output)
27+
protected function execute(InputInterface $input, OutputInterface $output): int
2728
{
2829
/** @var string $moduleName */
2930
$moduleName = $input->getArgument('module');

generator/src/DocPage.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Safe;
46

57
use function explode;
@@ -236,8 +238,6 @@ public function getMethodSynopsis(): array
236238

237239
/**
238240
* Loads the XML file, resolving all DTD declared entities.
239-
*
240-
* @return \SimpleXMLElement
241241
*/
242242
public function loadAndResolveFile(): \SimpleXMLElement
243243
{
@@ -268,8 +268,6 @@ public function loadAndResolveFile(): \SimpleXMLElement
268268

269269
/**
270270
* Returns the module name in Camelcase.
271-
*
272-
* @return string
273271
*/
274272
public function getModule(): string
275273
{

generator/src/EmptyTypeException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

generator/src/FileCreator.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Safe;
46

57
use Rector\Config\RectorConfig;
@@ -14,7 +16,6 @@ class FileCreator
1416
* This function generate an improved php lib function in a php file
1517
*
1618
* @param Method[] $functions
17-
* @param string $path
1819
*/
1920
public function generatePhpFile(array $functions, string $path): void
2021
{
@@ -64,7 +65,6 @@ private function getFunctionsNameList(array $functions): array
6465
* This function generate a PHP file containing the list of functions we can handle.
6566
*
6667
* @param Method[] $functions
67-
* @param string $path
6868
*/
6969
public function generateFunctionsList(array $functions, string $path): void
7070
{
@@ -86,7 +86,6 @@ public function generateFunctionsList(array $functions, string $path): void
8686
* Generates a configuration file for replacing all functions when using rector/rector.
8787
*
8888
* @param Method[] $functions
89-
* @param string $path
9089
*/
9190
public function generateRectorFile(array $functions, string $path): void
9291
{
@@ -148,9 +147,6 @@ public static function createFromPhpError(): self
148147

149148
/**
150149
* Generates the name of the exception class
151-
*
152-
* @param string $moduleName
153-
* @return string
154150
*/
155151
public static function toExceptionName(string $moduleName): string
156152
{

generator/src/GenerateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

@@ -18,7 +19,7 @@ protected function configure(): void
1819
;
1920
}
2021

21-
protected function execute(InputInterface $input, OutputInterface $output)
22+
protected function execute(InputInterface $input, OutputInterface $output): int
2223
{
2324

2425
$this->rmGenerated();

generator/src/Method.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Safe;
46

57
use Safe\PhpStanFunctions\PhpStanFunction;
@@ -11,35 +13,19 @@ class Method
1113
const FALSY_TYPE = 1;
1214
const NULLSY_TYPE = 2;
1315
const EMPTY_TYPE = 3;
14-
/**
15-
* @var \SimpleXMLElement
16-
*/
17-
private $functionObject;
18-
/**
19-
* @var \SimpleXMLElement
20-
*/
21-
private $rootEntity;
22-
/**
23-
* @var string
24-
*/
25-
private $moduleName;
16+
private \SimpleXMLElement $functionObject;
17+
private \SimpleXMLElement $rootEntity;
18+
private string $moduleName;
2619
/**
2720
* @var Parameter[]|null
2821
*/
29-
private $params = null;
30-
/**
31-
* @var int
32-
*/
33-
private $errorType;
22+
private ?array $params = null;
23+
private int $errorType;
3424
/**
3525
* The function prototype from the phpstan internal documentation (functionMap.php)
36-
* @var PhpStanFunction|null
3726
*/
3827
private $phpstanSignarure;
39-
/**
40-
* @var PhpStanType
41-
*/
42-
private $returnType;
28+
private PhpStanType $returnType;
4329

4430
public function __construct(\SimpleXMLElement $_functionObject, \SimpleXMLElement $rootEntity, string $moduleName, PhpStanFunctionMapReader $phpStanFunctionMapReader, int $errorType)
4531
{
@@ -225,8 +211,6 @@ public function getModuleName(): string
225211

226212
/**
227213
* The function is overloaded if at least one parameter is optional with no default value and this parameter is not by reference.
228-
*
229-
* @return bool
230214
*/
231215
public function isOverloaded(): bool
232216
{

generator/src/Parameter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Safe;
36

47
use Safe\PhpStanFunctions\PhpStanFunction;
@@ -58,8 +61,6 @@ public function isByReference(): bool
5861
/**
5962
* Some parameters can be optional with no default value. In this case, the function is "overloaded" (which is not
6063
* possible in user-land but possible in core...)
61-
*
62-
* @return bool
6364
*/
6465
public function isOptionalWithNoDefault(): bool
6566
{

generator/src/PhpStanFunctions/PhpStanFunction.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe\PhpStanFunctions;
56

@@ -13,7 +14,7 @@ class PhpStanFunction
1314
/**
1415
* @var PhpStanParameter[]
1516
*/
16-
private $parameters = [];
17+
private array $parameters = [];
1718

1819
/**
1920
* @param string[] $signature

generator/src/PhpStanFunctions/PhpStanFunctionMapReader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe\PhpStanFunctions;
56

generator/src/PhpStanFunctions/PhpStanParameter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe\PhpStanFunctions;
56

@@ -29,9 +30,6 @@ public function __construct(string $name, string $type)
2930
$this->type = new PhpStanType($type, $writeOnly);
3031
}
3132

32-
/**
33-
* @return string
34-
*/
3533
public function getName(): string
3634
{
3735
return $this->name;

generator/src/PhpStanFunctions/PhpStanType.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe\PhpStanFunctions;
56

@@ -17,18 +18,15 @@ class PhpStanType
1718
'\OCI-Lob',
1819
'\OCI-Collection',
1920
];
20-
/**
21-
* @var bool
22-
*/
23-
private $nullable;
24-
/**
25-
* @var bool
26-
*/
27-
private $falsable;
21+
22+
private bool $nullable;
23+
24+
private bool $falsable;
25+
2826
/**
2927
* @var string[]
3028
*/
31-
private $types;
29+
private array $types;
3230

3331
public function __construct(string $data, bool $writeOnly = false)
3432
{

generator/src/ScanObjectsCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

@@ -17,7 +18,7 @@ protected function configure(): void
1718
;
1819
}
1920

20-
protected function execute(InputInterface $input, OutputInterface $output)
21+
protected function execute(InputInterface $input, OutputInterface $output): int
2122
{
2223
$scanner = new Scanner(__DIR__ . '/../doc/doc-en/en/reference/');
2324

generator/src/Scanner.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Safe;
46

57
use function array_merge;
@@ -18,7 +20,7 @@ class Scanner
1820
/**
1921
* @var string[]
2022
*/
21-
private $ignoredFunctions;
23+
private ?array $ignoredFunctions = null;
2224

2325
/**
2426
* @var string[]

generator/src/ScannerResponse.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Safe;
46

57
class ScannerResponse

generator/src/Type.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

67
class Type
78
{
89
/**
910
* Returns true if the type passed in parameter is a class, false if it is scalar or resource
10-
*
11-
* @param string $type
12-
* @return bool
1311
*/
1412
private static function isClass(string $type): bool
1513
{

generator/src/WritePhpFunction.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Safe;
46

57
class WritePhpFunction
@@ -134,7 +136,6 @@ private function generateExceptionCode(string $moduleName, Method $method) : str
134136

135137
/**
136138
* @param Parameter[] $params
137-
* @return string
138139
*/
139140
private function displayParamsWithType(array $params): string
140141
{

generator/tests/ComposerJsonEditorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

@@ -8,7 +9,7 @@
89

910
class ComposerJsonEditorTest extends TestCase
1011
{
11-
public function testFileListEditionForGeneration()
12+
public function testFileListEditionForGeneration(): void
1213
{
1314
$oldList = [
1415
"deprecated/apc.php",
@@ -31,7 +32,7 @@ public function testFileListEditionForGeneration()
3132
}
3233

3334

34-
public function testFileListEditionForDeprecation()
35+
public function testFileListEditionForDeprecation(): void
3536
{
3637
$oldList = [
3738
"generated/apache.php",

generator/tests/DateTimeImmutableTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

@@ -132,7 +133,7 @@ public function testSub(): void
132133
$this->assertEquals($datetime->getTimestamp(), $safeDatime->getTimestamp());
133134
}
134135

135-
public function testSerialize()
136+
public function testSerialize(): void
136137
{
137138
$timezone = new \DateTimeZone('Pacific/Chatham');
138139
$safeDatetime = DateTimeImmutable::createFromFormat('d-m-Y', '20-03-2006', $timezone);

generator/tests/DateTimeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

generator/tests/DeprecateCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe;
56

@@ -8,7 +9,7 @@
89

910
class DeprecateCommandTest extends TestCase
1011
{
11-
public function testExceptionName()
12+
public function testExceptionName(): void
1213
{
1314
$this->assertEquals('Exceptions/ApcException.php', DeprecateCommand::getExceptionFilePath('apc'));
1415
}

0 commit comments

Comments
 (0)