Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor property promotions #482

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@

class DocPage
{
/**
* @var string
*/
private $path;

/*
* @return string
* @parameter string
*/
public function __construct(string $_path)
public function __construct(private readonly string $path)
{
$this->path = $_path;
}

// Ignore function if it was removed before PHP 7.1
Expand Down
7 changes: 1 addition & 6 deletions generator/src/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@

class Parameter
{
/**
* @var \SimpleXMLElement
*/
private $parameter;
/**
* @var PhpStanType
*/
private $type;

public function __construct(\SimpleXMLElement $parameter, ?PhpStanFunction $phpStanFunction, int $position)
public function __construct(private \SimpleXMLElement $parameter, ?PhpStanFunction $phpStanFunction, int $position)
{
$this->parameter = $parameter;
$phpStanParam = $phpStanFunction ? $phpStanFunction->getParameter($this->getParameterName(), $position) : null;

$this->type = $phpStanParam ? $phpStanParam->getType() : new PhpStanType($this->parameter->type->__toString()); //todo: is this if useful?
Expand Down
8 changes: 1 addition & 7 deletions generator/src/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

class Scanner
{
/**
* @var string
*/
private $path;

/**
* @var string[]
*/
Expand All @@ -25,9 +20,8 @@ class Scanner
*/
private $ignoredModules;

public function __construct(string $path)
public function __construct(private readonly string $path)
{
$this->path = $path;
}

/**
Expand Down
26 changes: 10 additions & 16 deletions generator/src/ScannerResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@

class ScannerResponse
{
/**
* @readonly
* @var Method[]
*/
public array $methods;

/**
* @readonly
* @var string[]
*/
public array $overloadedFunctions;

/**
* @param Method[] $methods
* @param string[] $overloadedFunctions
*/
public function __construct(array $methods, array $overloadedFunctions)
{
$this->methods = $methods;
$this->overloadedFunctions = $overloadedFunctions;
public function __construct(
/**
* @readonly
*/
public array $methods,
/**
* @readonly
*/
public array $overloadedFunctions
) {
}
}
8 changes: 1 addition & 7 deletions generator/src/WritePhpFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@

class WritePhpFunction
{
/**
* @var Method
*/
private $method;

public function __construct(Method $method)
public function __construct(private Method $method)
{
$this->method = $method;
}

/*
Expand Down
Loading