Skip to content

Remove handling of non-initialized object names #6663

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

Merged
merged 1 commit into from
Dec 23, 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
7 changes: 0 additions & 7 deletions src/Schema/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ abstract class AbstractAsset
{
protected string $_name = '';

/**
* Indicates whether the object name has been initialized.
*/
protected bool $isNameInitialized = false;

/**
* Namespace of the asset. If none isset the default namespace is assumed.
*/
Expand All @@ -67,8 +62,6 @@ public function __construct(string $name)

$this->setName($parsedName);

$this->isNameInitialized = true;

if ($parsedName === null) {
return;
}
Expand Down
10 changes: 0 additions & 10 deletions src/Schema/AbstractNamedObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Schema\Exception\InvalidName;
use Doctrine\DBAL\Schema\Exception\NameIsNotInitialized;

/**
* An abstract {@see NamedObject}.
Expand All @@ -19,9 +18,6 @@ abstract class AbstractNamedObject extends AbstractAsset implements NamedObject
/**
* The name of the database object.
*
* Until the validity of the name is enforced, this property isn't guaranteed to be always initialized. The property
* can be accessed only if {@see $isNameInitialized} is set to true.
*
* @var N
*/
protected Name $name;
Expand All @@ -35,15 +31,9 @@ public function __construct(string $name)
* Returns the object name.
*
* @return N
*
* @throws NameIsNotInitialized
*/
public function getObjectName(): Name
{
if (! $this->isNameInitialized) {
throw NameIsNotInitialized::new();
}

return $this->name;
}

Expand Down
9 changes: 0 additions & 9 deletions src/Schema/AbstractOptionallyNamedObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Schema\Exception\NameIsNotInitialized;

/**
* An abstract {@see OptionallyNamedObject}.
*
Expand All @@ -18,9 +16,6 @@ abstract class AbstractOptionallyNamedObject extends AbstractAsset implements Op
/**
* The name of the database object.
*
* Until the validity of the name is enforced, this property isn't guaranteed to be always initialized. The property
* can be accessed only if {@see $isNameInitialized} is set to true.
*
* @var ?N
*/
protected ?Name $name;
Expand All @@ -32,10 +27,6 @@ public function __construct(?string $name)

public function getObjectName(): ?Name
{
if (! $this->isNameInitialized) {
throw NameIsNotInitialized::new();
}

return $this->name;
}

Expand Down
17 changes: 0 additions & 17 deletions src/Schema/Exception/NameIsNotInitialized.php

This file was deleted.

16 changes: 0 additions & 16 deletions tests/Schema/AbstractNamedObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
namespace Doctrine\DBAL\Tests\Schema;

use Doctrine\DBAL\Schema\AbstractNamedObject;
use Doctrine\DBAL\Schema\AbstractOptionallyNamedObject;
use Doctrine\DBAL\Schema\Exception\InvalidName;
use Doctrine\DBAL\Schema\Exception\NameIsNotInitialized;
use Doctrine\DBAL\Schema\Name;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use PHPUnit\Framework\TestCase;
Expand All @@ -24,18 +22,4 @@ public function testEmptyName(): void
class ('') extends AbstractNamedObject {
};
}

public function testAccessToUninitializedName(): void
{
$object = new /** @extends AbstractOptionallyNamedObject<Name> */
class () extends AbstractOptionallyNamedObject {
/** @phpstan-ignore constructor.missingParentCall */
public function __construct()
{
}
};

$this->expectException(NameIsNotInitialized::class);
$object->getObjectName();
}
}
15 changes: 0 additions & 15 deletions tests/Schema/AbstractOptionallyNamedObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\DBAL\Tests\Schema;

use Doctrine\DBAL\Schema\AbstractOptionallyNamedObject;
use Doctrine\DBAL\Schema\Exception\NameIsNotInitialized;
use Doctrine\DBAL\Schema\Name;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
Expand All @@ -28,18 +27,4 @@ public static function emptyNameProvider(): iterable
yield 'empty-string' => [''];
yield 'empty-null' => [null];
}

public function testAccessToUninitializedName(): void
{
$object = new /** @extends AbstractOptionallyNamedObject<Name> */
class () extends AbstractOptionallyNamedObject {
/** @phpstan-ignore constructor.missingParentCall */
public function __construct()
{
}
};

$this->expectException(NameIsNotInitialized::class);
$object->getObjectName();
}
}