Skip to content

Commit

Permalink
Merge pull request #9397 from samsonasik/refactor-constructor-promo
Browse files Browse the repository at this point in the history
refactor: using property promotion on ResponseTraitTest
  • Loading branch information
samsonasik authored Jan 10, 2025
2 parents d03d306 + e5f215c commit 4c2e683
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 92 deletions.
26 changes: 4 additions & 22 deletions tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,10 @@ protected function makeController(string $routePath = '', array $userHeaders = [
return new class ($this->request, $this->response, $this->formatter) {
use ResponseTrait;

protected $request;
protected $response;
protected $formatter;

public function __construct($request, $response, $formatter)
public function __construct(protected $request, protected $response, $formatter)
{
$this->request = $request;
$this->response = $response;
$this->formatter = $formatter;
}

Expand Down Expand Up @@ -177,15 +173,11 @@ public function testNoFormatterWithStringAsHtmlTrue(): void
$controller = new class ($this->request, $this->response, $this->formatter) {
use ResponseTrait;

protected $request;
protected $response;
protected $formatter;
protected bool $stringAsHtml = true;

public function __construct($request, $response, $formatter)
public function __construct(protected $request, protected $response, $formatter)
{
$this->request = $request;
$this->response = $response;
$this->formatter = $formatter;
}
};
Expand Down Expand Up @@ -299,15 +291,11 @@ public function testRespondSetsCorrectBodyAndStatusWithStringAsHtmlTrue(): void
$controller = new class ($this->request, $this->response, $this->formatter) {
use ResponseTrait;

protected $request;
protected $response;
protected $formatter;
protected bool $stringAsHtml = true;

public function __construct($request, $response, $formatter)
public function __construct(protected $request, protected $response, $formatter)
{
$this->request = $request;
$this->response = $response;
$this->formatter = $formatter;
}
};
Expand Down Expand Up @@ -639,14 +627,8 @@ public function testFormatByRequestNegotiateIfFormatIsNotJsonOrXML(): void
$controller = new class ($request, $response) {
use ResponseTrait;

protected $request;
protected $response;

public function __construct($request, $response)
public function __construct(protected $request, protected $response)
{
$this->request = $request;
$this->response = $response;

$this->format = 'txt';
}
};
Expand Down
2 changes: 1 addition & 1 deletion utils/phpstan-baseline/assign.propertyType.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parameters:
path: ../../system/Controller.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:\$format \(''html''\|''json''\|''xml''\|null\) does not accept ''txt''\.$#'
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:\$format \(''html''\|''json''\|''xml''\|null\) does not accept ''txt''\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

Expand Down
36 changes: 18 additions & 18 deletions utils/phpstan-baseline/missingType.iterableValue.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6568,92 +6568,92 @@ parameters:
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:fail\(\) has parameter \$messages with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:fail\(\) has parameter \$messages with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:format\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:format\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:respond\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:respond\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:respondCreated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:respondCreated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:respondDeleted\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:respondDeleted\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:respondUpdated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:respondUpdated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:fail\(\) has parameter \$messages with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:fail\(\) has parameter \$messages with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:format\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:format\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:respond\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:respond\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:respondCreated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:respondCreated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:respondDeleted\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:respondDeleted\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:respondUpdated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:respondUpdated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:fail\(\) has parameter \$messages with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:fail\(\) has parameter \$messages with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:format\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:format\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:respond\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:respond\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:respondCreated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:respondCreated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:respondDeleted\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:respondDeleted\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:respondUpdated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:respondUpdated\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

Expand Down
16 changes: 8 additions & 8 deletions utils/phpstan-baseline/missingType.parameter.neon
Original file line number Diff line number Diff line change
Expand Up @@ -128,42 +128,42 @@ parameters:
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:__construct\(\) has parameter \$formatter with no type specified\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:__construct\(\) has parameter \$formatter with no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:__construct\(\) has parameter \$request with no type specified\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:__construct\(\) has parameter \$request with no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:__construct\(\) has parameter \$response with no type specified\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:__construct\(\) has parameter \$response with no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:__construct\(\) has parameter \$formatter with no type specified\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:__construct\(\) has parameter \$formatter with no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:__construct\(\) has parameter \$request with no type specified\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:__construct\(\) has parameter \$request with no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:__construct\(\) has parameter \$response with no type specified\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:__construct\(\) has parameter \$response with no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:__construct\(\) has parameter \$request with no type specified\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:__construct\(\) has parameter \$request with no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:__construct\(\) has parameter \$response with no type specified\.$#'
message: '#^Method class@anonymous/tests/system/API/ResponseTraitTest\.php\:627\:\:__construct\(\) has parameter \$response with no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

Expand Down
46 changes: 3 additions & 43 deletions utils/phpstan-baseline/missingType.property.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 135 errors
# total 127 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -148,55 +148,15 @@ parameters:
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:116\:\:\$request has no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:116\:\:\$response has no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:\$formatter has no type specified\.$#'
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:173\:\:\$formatter has no type specified\.$#'
count: 2
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:\$request has no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:177\:\:\$response has no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:\$formatter has no type specified\.$#'
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:291\:\:\$formatter has no type specified\.$#'
count: 2
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:\$request has no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:299\:\:\$response has no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:\$request has no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:\$response has no type specified\.$#'
count: 1
path: ../../tests/system/API/ResponseTraitTest.php

-
message: '#^Property CodeIgniter\\Config\\Factory@anonymous/tests/system/Config/FactoriesTest\.php\:89\:\:\$widgets has no type specified\.$#'
count: 1
Expand Down

0 comments on commit 4c2e683

Please sign in to comment.