Skip to content

Commit

Permalink
Narrow types
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 7, 2023
1 parent b20ce11 commit e47e419
Show file tree
Hide file tree
Showing 45 changed files with 431 additions and 9 deletions.
25 changes: 16 additions & 9 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,6 @@
</RedundantCondition>
</file>
<file src="src/Metadata/Api/DataProvider.php">
<ArgumentTypeCoercion>
<code><![CDATA[$_dataProvider->methodName()]]></code>
</ArgumentTypeCoercion>
<PossiblyInvalidArgument>
<code><![CDATA[$e->getCode()]]></code>
</PossiblyInvalidArgument>
Expand Down Expand Up @@ -460,12 +457,6 @@
<code>assert($metadata instanceof RequiresSetting)</code>
</RedundantCondition>
</file>
<file src="src/Metadata/Metadata.php">
<ArgumentTypeCoercion>
<code>$className</code>
<code>$className</code>
</ArgumentTypeCoercion>
</file>
<file src="src/Metadata/MetadataCollection.php">
<PropertyTypeCoercion>
<code>$metadata</code>
Expand Down Expand Up @@ -512,10 +503,26 @@
<code>$className</code>
<code>$className</code>
<code>$className</code>
<code>$className</code>
<code>$className</code>
<code>$className</code>
<code>$function</code>
<code>$function</code>
<code>$methodName</code>
<code>$pieces[0]</code>
<code>$pieces[0]</code>
<code>$pieces[1]</code>
<code>$pieces[1]</code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
<code><![CDATA[explode('::', $value)]]></code>
<code><![CDATA[explode('::', $value)]]></code>
<code>trim($tmp[0])</code>
<code>trim($tmp[1])</code>
</ArgumentTypeCoercion>
</file>
<file src="src/Metadata/Version/Requirement.php">
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/After.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
final class After extends Metadata
{
/**
* @psalm-assert-if-true After $this
*/
public function isAfter(): bool
{
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/AfterClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
final class AfterClass extends Metadata
{
/**
* @psalm-assert-if-true AfterClass $this
*/
public function isAfterClass(): bool
{
return true;
Expand Down
6 changes: 6 additions & 0 deletions src/Metadata/BackupGlobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ final class BackupGlobals extends Metadata
{
private readonly bool $enabled;

/**
* @psalm-param 0|1 $level
*/
protected function __construct(int $level, bool $enabled)
{
parent::__construct($level);

$this->enabled = $enabled;
}

/**
* @psalm-assert-if-true BackupGlobals $this
*/
public function isBackupGlobals(): bool
{
return true;
Expand Down
6 changes: 6 additions & 0 deletions src/Metadata/BackupStaticProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ final class BackupStaticProperties extends Metadata
{
private readonly bool $enabled;

/**
* @psalm-param 0|1 $level
*/
protected function __construct(int $level, bool $enabled)
{
parent::__construct($level);

$this->enabled = $enabled;
}

/**
* @psalm-assert-if-true BackupStaticProperties $this
*/
public function isBackupStaticProperties(): bool
{
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/Before.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
final class Before extends Metadata
{
/**
* @psalm-assert-if-true Before $this
*/
public function isBefore(): bool
{
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/BeforeClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
final class BeforeClass extends Metadata
{
/**
* @psalm-assert-if-true BeforeClass $this
*/
public function isBeforeClass(): bool
{
return true;
Expand Down
13 changes: 13 additions & 0 deletions src/Metadata/Covers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,33 @@
*/
final class Covers extends Metadata
{
/**
* @psalm-var non-empty-string
*/
private readonly string $target;

/**
* @psalm-param 0|1 $level
* @psalm-param non-empty-string $target
*/
protected function __construct(int $level, string $target)
{
parent::__construct($level);

$this->target = $target;
}

/**
* @psalm-assert-if-true Covers $this
*/
public function isCovers(): bool
{
return true;
}

/**
* @psalm-return non-empty-string
*/
public function target(): string
{
return $this->target;
Expand Down
4 changes: 4 additions & 0 deletions src/Metadata/CoversClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class CoversClass extends Metadata
private readonly string $className;

/**
* @psalm-param 0|1 $level
* @psalm-param class-string $className
*/
protected function __construct(int $level, string $className)
Expand All @@ -31,6 +32,9 @@ protected function __construct(int $level, string $className)
$this->className = $className;
}

/**
* @psalm-assert-if-true CoversClass $this
*/
public function isCoversClass(): bool
{
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/Metadata/CoversDefaultClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class CoversDefaultClass extends Metadata
private readonly string $className;

/**
* @psalm-param 0|1 $level
* @psalm-param class-string $className
*/
protected function __construct(int $level, string $className)
Expand All @@ -31,6 +32,9 @@ protected function __construct(int $level, string $className)
$this->className = $className;
}

/**
* @psalm-assert-if-true CoversDefaultClass $this
*/
public function isCoversDefaultClass(): bool
{
return true;
Expand Down
13 changes: 13 additions & 0 deletions src/Metadata/CoversFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,33 @@
*/
final class CoversFunction extends Metadata
{
/**
* @psalm-var non-empty-string
*/
private readonly string $functionName;

/**
* @psalm-param 0|1 $level
* @psalm-param non-empty-string $functionName
*/
protected function __construct(int $level, string $functionName)
{
parent::__construct($level);

$this->functionName = $functionName;
}

/**
* @psalm-assert-if-true CoversFunction $this
*/
public function isCoversFunction(): bool
{
return true;
}

/**
* @psalm-return non-empty-string
*/
public function functionName(): string
{
return $this->functionName;
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/CoversNothing.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
final class CoversNothing extends Metadata
{
/**
* @psalm-assert-if-true CoversNothing $this
*/
public function isCoversNothing(): bool
{
return true;
Expand Down
12 changes: 12 additions & 0 deletions src/Metadata/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ final class DataProvider extends Metadata
* @psalm-var class-string
*/
private readonly string $className;

/**
* @psalm-var non-empty-string
*/
private readonly string $methodName;

/**
* @psalm-param 0|1 $level
* @psalm-param class-string $className
* @psalm-param non-empty-string $methodName
*/
protected function __construct(int $level, string $className, string $methodName)
{
Expand All @@ -33,6 +39,9 @@ protected function __construct(int $level, string $className, string $methodName
$this->methodName = $methodName;
}

/**
* @psalm-assert-if-true DataProvider $this
*/
public function isDataProvider(): bool
{
return true;
Expand All @@ -46,6 +55,9 @@ public function className(): string
return $this->className;
}

/**
* @psalm-return non-empty-string
*/
public function methodName(): string
{
return $this->methodName;
Expand Down
4 changes: 4 additions & 0 deletions src/Metadata/DependsOnClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class DependsOnClass extends Metadata
private readonly bool $shallowClone;

/**
* @psalm-param 0|1 $level
* @psalm-param class-string $className
*/
protected function __construct(int $level, string $className, bool $deepClone, bool $shallowClone)
Expand All @@ -35,6 +36,9 @@ protected function __construct(int $level, string $className, bool $deepClone, b
$this->shallowClone = $shallowClone;
}

/**
* @psalm-assert-if-true DependsOnClass $this
*/
public function isDependsOnClass(): bool
{
return true;
Expand Down
12 changes: 12 additions & 0 deletions src/Metadata/DependsOnMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ final class DependsOnMethod extends Metadata
* @psalm-var class-string
*/
private readonly string $className;

/**
* @psalm-var non-empty-string
*/
private readonly string $methodName;
private readonly bool $deepClone;
private readonly bool $shallowClone;

/**
* @psalm-param 0|1 $level
* @psalm-param class-string $className
* @psalm-param non-empty-string $methodName
*/
protected function __construct(int $level, string $className, string $methodName, bool $deepClone, bool $shallowClone)
{
Expand All @@ -37,6 +43,9 @@ protected function __construct(int $level, string $className, string $methodName
$this->shallowClone = $shallowClone;
}

/**
* @psalm-assert-if-true DependsOnMethod $this
*/
public function isDependsOnMethod(): bool
{
return true;
Expand All @@ -50,6 +59,9 @@ public function className(): string
return $this->className;
}

/**
* @psalm-return non-empty-string
*/
public function methodName(): string
{
return $this->methodName;
Expand Down
3 changes: 3 additions & 0 deletions src/Metadata/DoesNotPerformAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
final class DoesNotPerformAssertions extends Metadata
{
/**
* @psalm-assert-if-true DoesNotPerformAssertions $this
*/
public function isDoesNotPerformAssertions(): bool
{
return true;
Expand Down
13 changes: 13 additions & 0 deletions src/Metadata/ExcludeGlobalVariableFromBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,33 @@
*/
final class ExcludeGlobalVariableFromBackup extends Metadata
{
/**
* @psalm-var non-empty-string
*/
private readonly string $globalVariableName;

/**
* @psalm-param 0|1 $level
* @psalm-param non-empty-string $globalVariableName
*/
protected function __construct(int $level, string $globalVariableName)
{
parent::__construct($level);

$this->globalVariableName = $globalVariableName;
}

/**
* @psalm-assert-if-true ExcludeGlobalVariableFromBackup $this
*/
public function isExcludeGlobalVariableFromBackup(): bool
{
return true;
}

/**
* @psalm-return non-empty-string
*/
public function globalVariableName(): string
{
return $this->globalVariableName;
Expand Down
Loading

0 comments on commit e47e419

Please sign in to comment.