Skip to content

Commit

Permalink
enable strict_types in generator
Browse files Browse the repository at this point in the history
(Continuing with pulling the changes from shish/safe into tcm/safe in small hopefully easy-to-review chunks)
  • Loading branch information
shish committed Dec 2, 2024
1 parent d43727a commit 0627823
Show file tree
Hide file tree
Showing 32 changed files with 90 additions and 67 deletions.
1 change: 1 addition & 0 deletions generator/src/ComposerJsonEditor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand Down
3 changes: 2 additions & 1 deletion generator/src/DeprecateCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand All @@ -23,7 +24,7 @@ protected function configure(): void
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string $moduleName */
$moduleName = $input->getArgument('module');
Expand Down
6 changes: 2 additions & 4 deletions generator/src/DocPage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Safe;

use function explode;
Expand Down Expand Up @@ -236,8 +238,6 @@ public function getMethodSynopsis(): array

/**
* Loads the XML file, resolving all DTD declared entities.
*
* @return \SimpleXMLElement
*/
public function loadAndResolveFile(): \SimpleXMLElement
{
Expand Down Expand Up @@ -268,8 +268,6 @@ public function loadAndResolveFile(): \SimpleXMLElement

/**
* Returns the module name in Camelcase.
*
* @return string
*/
public function getModule(): string
{
Expand Down
1 change: 1 addition & 0 deletions generator/src/EmptyTypeException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand Down
8 changes: 2 additions & 6 deletions generator/src/FileCreator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Safe;

use Rector\Config\RectorConfig;
Expand All @@ -14,7 +16,6 @@ class FileCreator
* This function generate an improved php lib function in a php file
*
* @param Method[] $functions
* @param string $path
*/
public function generatePhpFile(array $functions, string $path): void
{
Expand Down Expand Up @@ -64,7 +65,6 @@ private function getFunctionsNameList(array $functions): array
* This function generate a PHP file containing the list of functions we can handle.
*
* @param Method[] $functions
* @param string $path
*/
public function generateFunctionsList(array $functions, string $path): void
{
Expand All @@ -86,7 +86,6 @@ public function generateFunctionsList(array $functions, string $path): void
* Generates a configuration file for replacing all functions when using rector/rector.
*
* @param Method[] $functions
* @param string $path
*/
public function generateRectorFile(array $functions, string $path): void
{
Expand Down Expand Up @@ -148,9 +147,6 @@ public static function createFromPhpError(): self

/**
* Generates the name of the exception class
*
* @param string $moduleName
* @return string
*/
public static function toExceptionName(string $moduleName): string
{
Expand Down
3 changes: 2 additions & 1 deletion generator/src/GenerateCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand All @@ -18,7 +19,7 @@ protected function configure(): void
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{

$this->rmGenerated();
Expand Down
7 changes: 3 additions & 4 deletions generator/src/Method.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Safe;

use Safe\PhpStanFunctions\PhpStanFunction;
Expand All @@ -26,14 +28,13 @@ class Method
/**
* @var Parameter[]|null
*/
private $params = null;
/**
* @var int
*/
private $errorType;
private ?array $params = null;
/**
* The function prototype from the phpstan internal documentation (functionMap.php)
* @var PhpStanFunction|null
*/
private $phpstanSignarure;
/**
Expand Down Expand Up @@ -225,8 +226,6 @@ public function getModuleName(): string

/**
* The function is overloaded if at least one parameter is optional with no default value and this parameter is not by reference.
*
* @return bool
*/
public function isOverloaded(): bool
{
Expand Down
5 changes: 3 additions & 2 deletions generator/src/Parameter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Safe;

use Safe\PhpStanFunctions\PhpStanFunction;
Expand Down Expand Up @@ -58,8 +61,6 @@ public function isByReference(): bool
/**
* Some parameters can be optional with no default value. In this case, the function is "overloaded" (which is not
* possible in user-land but possible in core...)
*
* @return bool
*/
public function isOptionalWithNoDefault(): bool
{
Expand Down
3 changes: 2 additions & 1 deletion generator/src/PhpStanFunctions/PhpStanFunction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe\PhpStanFunctions;

Expand All @@ -13,7 +14,7 @@ class PhpStanFunction
/**
* @var PhpStanParameter[]
*/
private $parameters = [];
private array $parameters = [];

/**
* @param string[] $signature
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe\PhpStanFunctions;

Expand Down
4 changes: 1 addition & 3 deletions generator/src/PhpStanFunctions/PhpStanParameter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe\PhpStanFunctions;

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

/**
* @return string
*/
public function getName(): string
{
return $this->name;
Expand Down
16 changes: 7 additions & 9 deletions generator/src/PhpStanFunctions/PhpStanType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe\PhpStanFunctions;

Expand All @@ -17,18 +18,15 @@ class PhpStanType
'\OCI-Lob',
'\OCI-Collection',
];
/**
* @var bool
*/
private $nullable;
/**
* @var bool
*/
private $falsable;

private bool $nullable;

private bool $falsable;

/**
* @var string[]
*/
private $types;
private array $types;

public function __construct(string $data, bool $writeOnly = false)
{
Expand Down
3 changes: 2 additions & 1 deletion generator/src/ScanObjectsCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand All @@ -17,7 +18,7 @@ protected function configure(): void
;
}

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

Expand Down
4 changes: 3 additions & 1 deletion generator/src/Scanner.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Safe;

use function array_merge;
Expand All @@ -18,7 +20,7 @@ class Scanner
/**
* @var string[]
*/
private $ignoredFunctions;
private ?array $ignoredFunctions = null;

/**
* @var string[]
Expand Down
2 changes: 2 additions & 0 deletions generator/src/ScannerResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Safe;

class ScannerResponse
Expand Down
4 changes: 1 addition & 3 deletions generator/src/Type.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php

declare(strict_types=1);

namespace Safe;

class Type
{
/**
* Returns true if the type passed in parameter is a class, false if it is scalar or resource
*
* @param string $type
* @return bool
*/
private static function isClass(string $type): bool
{
Expand Down
3 changes: 2 additions & 1 deletion generator/src/WritePhpFunction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Safe;

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

/**
* @param Parameter[] $params
* @return string
*/
private function displayParamsWithType(array $params): string
{
Expand Down
5 changes: 3 additions & 2 deletions generator/tests/ComposerJsonEditorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand All @@ -8,7 +9,7 @@

class ComposerJsonEditorTest extends TestCase
{
public function testFileListEditionForGeneration()
public function testFileListEditionForGeneration(): void
{
$oldList = [
"deprecated/apc.php",
Expand All @@ -31,7 +32,7 @@ public function testFileListEditionForGeneration()
}


public function testFileListEditionForDeprecation()
public function testFileListEditionForDeprecation(): void
{
$oldList = [
"generated/apache.php",
Expand Down
3 changes: 2 additions & 1 deletion generator/tests/DateTimeImmutableTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand Down Expand Up @@ -132,7 +133,7 @@ public function testSub(): void
$this->assertEquals($datetime->getTimestamp(), $safeDatime->getTimestamp());
}

public function testSerialize()
public function testSerialize(): void
{
$timezone = new \DateTimeZone('Pacific/Chatham');
$safeDatetime = DateTimeImmutable::createFromFormat('d-m-Y', '20-03-2006', $timezone);
Expand Down
1 change: 1 addition & 0 deletions generator/tests/DateTimeTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand Down
3 changes: 2 additions & 1 deletion generator/tests/DeprecateCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Safe;

Expand All @@ -8,7 +9,7 @@

class DeprecateCommandTest extends TestCase
{
public function testExceptionName()
public function testExceptionName(): void
{
$this->assertEquals('Exceptions/ApcException.php', DeprecateCommand::getExceptionFilePath('apc'));
}
Expand Down
Loading

0 comments on commit 0627823

Please sign in to comment.