Skip to content

Commit

Permalink
Constructor property promotions
Browse files Browse the repository at this point in the history
(Pulling changes from shish/safe into smaller chunks for easier reviews)
  • Loading branch information
shish committed Dec 2, 2024
1 parent d43727a commit c3cc17e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 43 deletions.
8 changes: 1 addition & 7 deletions generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@

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

0 comments on commit c3cc17e

Please sign in to comment.