Skip to content

Commit

Permalink
Rector: Remove redundant parent::setUp calls and enhance declarations
Browse files Browse the repository at this point in the history
Eliminated unnecessary `parent::setUp` calls from multiple tests to streamline initialization. Added `readonly` properties and other minor improvements for better immutability and code clarity.
  • Loading branch information
koriym committed Jan 11, 2025
1 parent 764e31f commit 0fa9a53
Show file tree
Hide file tree
Showing 29 changed files with 13 additions and 43 deletions.
2 changes: 0 additions & 2 deletions tests/AnchorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class AnchorTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$invoker = (new InvokerFactory())();
$author = new Author();
$author->onGet(1);
Expand Down
2 changes: 1 addition & 1 deletion tests/AppIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp(): void

public function testForEach(): void
{
foreach ($this->appIterator as $key => $meta) {
foreach ($this->appIterator as $meta) {
$isValidUri = filter_var($meta->uri, FILTER_VALIDATE_URL);
$this->assertTrue((bool) $isValidUri);
$this->assertInstanceOf(Meta::class, $meta);
Expand Down
2 changes: 0 additions & 2 deletions tests/AttrNamedParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class AttrNamedParameterTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$this->params = new NamedParameter(new NamedParamMetas(), new Injector());
}

Expand Down
2 changes: 0 additions & 2 deletions tests/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class AttributeTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$injector = new Injector(new ResourceModule('FakeVendor\News'), __DIR__ . '/tmp');
$this->resource = $injector->getInstance(ResourceInterface::class);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class FactoryTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$injector = new Injector();
$scheme = (new SchemeCollection())
->scheme('app')->host('self')->toAdapter(new AppAdapter($injector, 'FakeVendor\Sandbox'))
Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeFreeze.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FakeFreeze extends ResourceObject

public function __construct()
{
$this->closure = function () {
$this->closure = function (): void {
};
$module = new FakeSchemeModule(new ResourceModule('FakeVendor\Sandbox'));
/* @var $resource ResourceInterface */
Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeLazyModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class FakeLazyModule implements LazyModuleInterface
{
public function __construct(private AbstractModule $module)
public function __construct(private readonly AbstractModule $module)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeSchemeCollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class FakeSchemeCollectionProvider implements ProviderInterface
{
public function __construct(private InjectorInterface $injector)
public function __construct(private readonly InjectorInterface $injector)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeVendor/Blog/src/Resource/App/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class News extends ResourceObject
{
public function __construct(private ResourceInterface $resource)
public function __construct(private readonly ResourceInterface $resource)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Hasembed extends ResourceObject
{
public function __construct(private ResourceInterface $resource)
public function __construct(private readonly ResourceInterface $resource)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeVendor/Sandbox/Resource/App/Href/Origin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Origin extends ResourceObject
{
public function __construct(private ResourceInterface $resource)
public function __construct(private readonly ResourceInterface $resource)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeVendor/Sandbox/Resource/App/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class News extends ResourceObject
{
public function __construct(private ResourceInterface $resource)
public function __construct(private readonly ResourceInterface $resource)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeVendor/Sandbox/Resource/App/User/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Entry extends ResourceObject
102 => ['id' => 102, 'title' => 'Entry3'],
];

public function __construct(private ?\BEAR\Resource\ResourceInterface $resource = null)
public function __construct(private readonly ?\BEAR\Resource\ResourceInterface $resource = null)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeVendor/Sandbox/Resource/Page/FakeLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class FakeLoop extends ResourceObject
{
public function __construct(private ResourceInterface $resource)
public function __construct(private readonly ResourceInterface $resource)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/Mock/PersonConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getAge(): int
return $this->age;
}

public function __construct(private int $age, private string $name)
public function __construct(private readonly int $age, private readonly string $name)
{
}
}
2 changes: 1 addition & 1 deletion tests/Fake/Renderer/FakeErrorRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class FakeErrorRenderer implements RenderInterface
{
public function render(ResourceObject $ro)
public function render(ResourceObject $ro): never
{
throw new \ErrorException();
}
Expand Down
2 changes: 0 additions & 2 deletions tests/LinkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class LinkerTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$this->invoker = (new InvokerFactory())();
$schemeCollection = (new SchemeCollection())
->scheme('app')
Expand Down
2 changes: 0 additions & 2 deletions tests/MetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class MetaTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$this->meta = new Meta(Doc::class);
}

Expand Down
1 change: 0 additions & 1 deletion tests/Module/HalModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class HalModuleTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
}

public function testConfigure(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Module/ImportModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ protected function setUp(): void
$tmpDir = dirname(__DIR__, 2) . '/tests/Fake/FakeVendor/Blog/var/tmp';
$rm($tmpDir);
file_put_contents($tmpDir . '/tmp.text', '1');

parent::setUp();
}

public function testConfigure(): void
Expand Down
1 change: 0 additions & 1 deletion tests/Module/ResourceModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ResourceModuleTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
}

public function testConfigure(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Module/ResrouceObjectModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ final class ResrouceObjectModuleTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

@unlink(__DIR__ . '/tmp/compiled');
array_map('unlink', (array) glob(__DIR__ . '/tmp/{*.php}', GLOB_BRACE)); // @phpstan-ignore-line
}
Expand Down
2 changes: 0 additions & 2 deletions tests/NamedParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class NamedParameterTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$this->params = new NamedParameter(new NamedParamMetas(), new Injector());
}

Expand Down
2 changes: 0 additions & 2 deletions tests/ObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class ObjectTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$this->ro = new Mock\Entry();
$this->ro[0] = 'entry1';
$this->ro[1] = 'entry2';
Expand Down
2 changes: 0 additions & 2 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class RequestTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$this->invoker = (new InvokerFactory())();
$entry = new Entry();
$entry->uri = new Uri('test://self/path/to/resource');
Expand Down
2 changes: 0 additions & 2 deletions tests/ResourceParamHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class ResourceParamHandlerTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$module = new FakeSchemeModule(new ResourceModule('FakeVendor\Sandbox'));
$this->resource = (new Injector($module, __DIR__ . '/tmp'))->getInstance(ResourceInterface::class);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class ResourceTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$injector = new Injector(new FakeSchemeModule(new ResourceModule('FakeVendor\Sandbox')), __DIR__ . '/tmp');
$this->resource = $injector->getInstance(ResourceInterface::class);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/SchemeCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class SchemeCollectionTest extends TestCase

protected function setUp(): void
{
parent::setUp();

$this->scheme = new SchemeCollection();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
header('Content-Type: application/json; charset=utf-8');
$requestHeaders = [];
foreach ($_SERVER as $key => $value) {
if (strncmp($key, 'HTTP_', 5) !== 0) {
if (! str_starts_with($key, 'HTTP_')) {
continue;
}

Expand Down

0 comments on commit 0fa9a53

Please sign in to comment.