Skip to content
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
4 changes: 2 additions & 2 deletions analyzer-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1976,8 +1976,8 @@ count = 14

[[issues]]
file = "src/RowGateway/AbstractRowGateway.php"
code = "mixed-operand"
message = "Invalid middle operand: type `mixed` cannot be reliably used in string concatenation."
code = "mixed-argument"
message = 'Invalid argument type for argument #1 of `PhpDb\RowGateway\Exception\RuntimeException::forMissingPrimaryKeyData`: expected `string`, but found `mixed`.'
count = 1

[[issues]]
Expand Down
150 changes: 24 additions & 126 deletions lint-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3360,36 +3360,6 @@ code = "assertion-style"
message = "Inconsistent assertions style."
count = 48

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "method-name"
message = "Method name `test__getThrowsExceptionForInvalidColumn` should be in camel case."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "method-name"
message = "Method name `test__get` should be in camel case."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "method-name"
message = "Method name `test__isset` should be in camel case."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "method-name"
message = "Method name `test__set` should be in camel case."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "method-name"
message = "Method name `test__unset` should be in camel case."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "no-isset"
Expand Down Expand Up @@ -3531,31 +3501,31 @@ count = 1
[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__getThrowsExceptionForInvalidColumn`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicGetThrowsForUnknownColumn`."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__get`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicGetReturnsTheColumnValue`."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__isset`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicIssetReportsWhetherAColumnIsSet`."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__set`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicSetAssignsTheColumnValue`."
count = 1

[[issues]]
file = "test/unit/RowGateway/AbstractRowGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__unset`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicUnsetClearsTheColumnValue`."
count = 1

[[issues]]
Expand Down Expand Up @@ -8034,84 +8004,6 @@ code = "assertion-style"
message = "Inconsistent assertions style."
count = 47

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__callThrowsExceptionForInvalidMethod` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__callWithFeatureSetMagicCall` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__cloneWithAliasedTableIdentifier` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__cloneWithTableIdentifier` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__clone` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__getAdapter` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__getLastInsertValue` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__getTable` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__getThrowsExceptionForInvalidProperty` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__getWithFeatureSetMagicGet` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__get` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__setThrowsExceptionForInvalidProperty` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "method-name"
message = "Method name `test__setWithFeatureSetMagicSet` should be in camel case."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
Expand Down Expand Up @@ -8301,79 +8193,79 @@ count = 1
[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__callThrowsExceptionForInvalidMethod`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicCallThrowsForUnknownMethod`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__callWithFeatureSetMagicCall`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicCallDelegatesToTheFeatureSet`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__cloneWithAliasedTableIdentifier`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testCloneWithAnAliasedTableIdentifier`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__cloneWithTableIdentifier`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testCloneWithATableIdentifier`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__clone`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testCloneKeepsTheAdapter`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__getAdapter`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicGetReturnsTheAdapter`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__getLastInsertValue`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicGetReturnsTheLastInsertValue`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__getTable`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicGetReturnsTheTable`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__getThrowsExceptionForInvalidProperty`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicGetThrowsForUnknownProperty`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__getWithFeatureSetMagicGet`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicGetDelegatesToTheFeatureSet`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__get`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicGetReturnsTheLastInsertValueAndAdapter`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__setThrowsExceptionForInvalidProperty`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicSetThrowsForUnknownProperty`."
count = 1

[[issues]]
file = "test/unit/TableGateway/AbstractTableGatewayTest.php"
code = "prefer-test-attribute"
message = "Use `#[Test]` attribute instead of `test` prefix on method `test__setWithFeatureSetMagicSet`."
message = "Use `#[Test]` attribute instead of `test` prefix on method `testMagicSetDelegatesToTheFeatureSet`."
count = 1

[[issues]]
Expand Down Expand Up @@ -8471,6 +8363,12 @@ file = "test/unit/TableGateway/TableGatewayTest.php"
code = "strict-assertions"
message = "Use strict assertions in PHPUnit tests."
count = 2
[[issues]]
file = "src/TableGateway/AbstractTableGateway.php"
code = "halstead"
message = "Method has a high halstead difficulty"
count = 1

[[issues]]
file = "src/Sql/AbstractSql.php"
code = "halstead"
Expand Down
2 changes: 1 addition & 1 deletion mago.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ baseline = "lint-baseline.toml"
# condition, per the convention in docs/book/exceptions.md. The method count tracks the
# number of distinct failures a component can report, so the maintainability signal does
# not apply. "test/" repeats the phpdb-qa-tools default, which this key replaces.
too-many-methods = { exclude = ["test/", "src/Sql/Exception/"] }
too-many-methods = { exclude = ["test/", "src/Sql/Exception/", "src/TableGateway/Exception/"] }

[analyzer]
baseline = "analyzer-baseline.toml"
Expand Down
12 changes: 5 additions & 7 deletions src/RowGateway/AbstractRowGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public function initialize(): void
$this->featureSet->apply('preInitialize', []);

if ($this->table === null) {
throw new Exception\RuntimeException('This row object does not have a valid table set.');
throw Exception\RuntimeException::forMissingTable();
}

if ($this->primaryKeyColumn === null) {
throw new Exception\RuntimeException('This row object does not have a primary key column set.');
throw Exception\RuntimeException::forMissingPrimaryKeyColumn();
}

if ($this->sql === null) {
throw new Exception\RuntimeException('This row object does not have a Sql object set.');
throw Exception\RuntimeException::forMissingSqlObject();
}

$this->featureSet->apply('postInitialize', []);
Expand Down Expand Up @@ -259,9 +259,7 @@ protected function processPrimaryKeyData(): void
$this->primaryKeyData = [];
foreach ($this->primaryKeyColumn as $column) {
if (! isset($this->data[$column])) {
throw new Exception\RuntimeException(
'While processing primary key data, a known key ' . $column . ' was not found in the data array',
);
throw Exception\RuntimeException::forMissingPrimaryKeyData($column);
}
$this->primaryKeyData[$column] = $this->data[$column];
}
Expand All @@ -275,7 +273,7 @@ public function __get(string $name): mixed
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
}
throw new Exception\InvalidArgumentException('Not a valid column in this row: ' . $name);
throw Exception\InvalidArgumentException::forInvalidColumn($name);
}

public function __isset(string $name): bool
Expand Down
21 changes: 20 additions & 1 deletion src/RowGateway/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,23 @@

use PhpDb\Exception;

class InvalidArgumentException extends Exception\InvalidArgumentException {}
use function sprintf;

class InvalidArgumentException extends Exception\InvalidArgumentException
{
final public const string INVALID_COLUMN = 'Not a valid column in this row: %s';

final public const string SQL_TABLE_MISMATCH =
'The Sql object provided does not have a table'
. ' that matches this row object';

public static function forInvalidColumn(string $name): self
{
return new self(sprintf(self::INVALID_COLUMN, $name));
}

public static function forSqlTableMismatch(): self
{
return new self(self::SQL_TABLE_MISMATCH);
}
}
44 changes: 43 additions & 1 deletion src/RowGateway/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,46 @@

use PhpDb\Exception;

class RuntimeException extends Exception\RuntimeException {}
use function sprintf;

class RuntimeException extends Exception\RuntimeException
{
final public const string MISSING_PRIMARY_KEY_COLUMN =
'This row object does not have'
. ' a primary key column set.';

final public const string MISSING_PRIMARY_KEY_DATA =
'While processing primary key data, a known key %s'
. ' was not found in the data array';

final public const string MISSING_SQL_OBJECT = 'This row object does not have a Sql object set.';

final public const string MISSING_TABLE = 'This row object does not have a valid table set.';

final public const string UNCALLABLE_METHOD = 'This method is not intended to be called on this object.';

public static function forMissingPrimaryKeyColumn(): self
{
return new self(self::MISSING_PRIMARY_KEY_COLUMN);
}

public static function forMissingPrimaryKeyData(string $column): self
{
return new self(sprintf(self::MISSING_PRIMARY_KEY_DATA, $column));
}

public static function forMissingSqlObject(): self
{
return new self(self::MISSING_SQL_OBJECT);
}

public static function forMissingTable(): self
{
return new self(self::MISSING_TABLE);
}

public static function forUncallableMethod(): self
{
return new self(self::UNCALLABLE_METHOD);
}
}
Loading
Loading