Skip to content

Commit dd1fa24

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 dd1fa24

32 files changed

+101
-99
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: 9 additions & 25 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
37-
*/
38-
private $phpstanSignarure;
39-
/**
40-
* @var PhpStanType
4126
*/
42-
private $returnType;
27+
private ?PhpStanFunction $phpstanSignarure;
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: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace Safe\PhpStanFunctions;
56

67
use Safe\Type;
78

89
class PhpStanParameter
910
{
10-
/**
11-
* @var string
12-
*/
13-
private $name;
14-
/**
15-
* @var PhpStanType
16-
*/
17-
private $type;
11+
private string $name;
12+
private PhpStanType $type;
1813

1914
public function __construct(string $name, string $type)
2015
{
@@ -29,9 +24,6 @@ public function __construct(string $name, string $type)
2924
$this->type = new PhpStanType($type, $writeOnly);
3025
}
3126

32-
/**
33-
* @return string
34-
*/
3527
public function getName(): string
3628
{
3729
return $this->name;

generator/src/PhpStanFunctions/PhpStanType.php

Lines changed: 10 additions & 12 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

@@ -11,24 +12,21 @@
1112
*/
1213
class PhpStanType
1314
{
14-
const NO_SIGNATURE_TYPES = [
15+
public const NO_SIGNATURE_TYPES = [
1516
'resource',
1617
'mixed',
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
{
@@ -49,12 +47,12 @@ public function __construct(string $data, bool $writeOnly = false)
4947

5048
$returnTypes = $this->explodeTypes($data);
5149
//remove 'null' from the list to identify if the signature type should be nullable
52-
if (($nullablePosition = \array_search('null', $returnTypes)) !== false) {
50+
if (($nullablePosition = \array_search('null', $returnTypes, true)) !== false) {
5351
$nullable = true;
5452
\array_splice($returnTypes, (int) $nullablePosition, 1);
5553
}
5654
//remove 'false' from the list to identify if the function return false on error
57-
if (($falsablePosition = \array_search('false', $returnTypes)) !== false) {
55+
if (($falsablePosition = \array_search('false', $returnTypes, true)) !== false) {
5856
$falsable = true;
5957
\array_splice($returnTypes, (int) $falsablePosition, 1);
6058
}

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
{

0 commit comments

Comments
 (0)