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 0aa85c6
Show file tree
Hide file tree
Showing 31 changed files with 88 additions and 54 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
2 changes: 2 additions & 0 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
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
2 changes: 2 additions & 0 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 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
4 changes: 2 additions & 2 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 Down Expand Up @@ -225,8 +227,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
8 changes: 5 additions & 3 deletions generator/tests/DocPageTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

declare(strict_types=1);

namespace Safe;

use PHPUnit\Framework\TestCase;

class DocPageTest extends TestCase
{
public function testDetectFalsyFunction()
public function testDetectFalsyFunction(): void
{
$pregMatch = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/pcre/functions/preg-match.xml');
$implode = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/strings/functions/implode.xml');
Expand Down Expand Up @@ -35,14 +37,14 @@ public function testDetectFalsyFunction()
$this->assertTrue($fopen->detectFalsyFunction());
}

public function testDetectNullsyFunction()
public function testDetectNullsyFunction(): void
{
$implode = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/strings/functions/implode.xml');

$this->assertFalse($implode->detectNullsyFunction());
}

public function testDetectEmptyFunction()
public function testDetectEmptyFunction(): void
{
$pgHost = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/pgsql/functions/pg-host.xml');

Expand Down
Loading

0 comments on commit 0aa85c6

Please sign in to comment.