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
22 changes: 20 additions & 2 deletions analyzer-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3819,7 +3819,7 @@ count = 1
[[issues]]
file = "src/Sql/Join.php"
code = "mixed-argument"
message = "Invalid argument type for argument #2 of `sprintf`: expected `Stringable|null|scalar`, but found `mixed`."
message = "Invalid argument type for argument #1 of `PhpDb\\Sql\\Exception\\InvalidArgumentException::forInvalidJoinName`: expected `string`, but found `mixed`."
count = 1

[[issues]]
Expand Down Expand Up @@ -4917,7 +4917,7 @@ count = 1
[[issues]]
file = "src/Sql/Sql.php"
code = "possibly-invalid-argument"
message = 'Possible argument type mismatch for argument #2 of `sprintf`: expected `Stringable|null|scalar`, but possibly received `PhpDb\Sql\TableIdentifier|array<array-key, mixed>|string`.'
message = 'Possible argument type mismatch for argument #1 of `PhpDb\Sql\Exception\InvalidArgumentException::forForeignTable`: expected `string`, but possibly received `PhpDb\Sql\TableIdentifier|array<array-key, mixed>|string`.'
count = 4

[[issues]]
Expand Down Expand Up @@ -5537,3 +5537,21 @@ file = "src/TableGateway/TableGatewayInterface.php"
code = "missing-api-or-internal"
message = 'Interface `PhpDb\TableGateway\TableGatewayInterface` is missing an `@api` or `@internal` annotation.'
count = 1

[[issues]]
file = "src/Sql/Predicate/Exception/ExceptionInterface.php"
code = "missing-api-or-internal"
message = 'Interface `PhpDb\Sql\Predicate\Exception\ExceptionInterface` is missing an `@api` or `@internal` annotation.'
count = 1

[[issues]]
file = "src/Sql/Predicate/Exception/InvalidArgumentException.php"
code = "class-must-be-final"
message = 'Class `PhpDb\Sql\Predicate\Exception\InvalidArgumentException` should be declared `final`.'
count = 1

[[issues]]
file = "src/Sql/Predicate/Exception/RuntimeException.php"
code = "class-must-be-final"
message = 'Class `PhpDb\Sql\Predicate\Exception\RuntimeException` should be declared `final`.'
count = 1
13 changes: 12 additions & 1 deletion lint-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ count = 1
file = "src/Sql/Select.php"
code = "halstead"
message = "Method has a high halstead difficulty"
count = 1
count = 2

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

[[issues]]
file = "src/Sql/Ddl/Column/AbstractPrecisionColumn.php"
code = "halstead"
message = "Method has a high halstead difficulty"
count = 1
7 changes: 7 additions & 0 deletions mago.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ parentheses-around-new-in-member-access = true
[linter]
baseline = "lint-baseline.toml"

[linter.rules]
# Exception classes are message catalogues: one template and one named constructor per
# 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/"] }

[analyzer]
baseline = "analyzer-baseline.toml"
class-initializers = [
Expand Down
20 changes: 5 additions & 15 deletions src/Sql/AbstractSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PhpDb\Sql\Argument\Value;
use PhpDb\Sql\Argument\Values;
use PhpDb\Sql\Platform\PlatformDecoratorInterface;
use ValueError;

use function count;
use function current;
Expand All @@ -26,7 +25,6 @@
use function is_string;
use function key;
use function rtrim;
use function sprintf;
use function str_replace;
use function strtoupper;
use function vsprintf;
Expand Down Expand Up @@ -108,9 +106,7 @@ protected function createSqlFromSpecificationAndParameters(array|string $specifi
}

if (! isset($specificationString)) {
throw new Exception\RuntimeException(
'A number of parameters was found that is not supported by this specification',
);
throw Exception\RuntimeException::forUnsupportedParameterCount();
}

$topParameters = [];
Expand All @@ -126,10 +122,7 @@ protected function createSqlFromSpecificationAndParameters(array|string $specifi
}

if (! isset($paramSpecs[$position][$ppCount])) {
throw new Exception\RuntimeException(sprintf(
'A number of parameters (%d) was found that is not supported by this specification',
$ppCount,
));
throw Exception\RuntimeException::forUnsupportedParameterCountOf($ppCount);
}

$multiParamValues[] = vsprintf($paramSpecs[$position][$ppCount], $multiParamsForPosition);
Expand All @@ -139,10 +132,7 @@ protected function createSqlFromSpecificationAndParameters(array|string $specifi
} elseif (null !== $paramSpecs[$position]) {
$ppCount = count($paramsForPosition);
if (! isset($paramSpecs[$position][$ppCount])) {
throw new Exception\RuntimeException(sprintf(
'A number of parameters (%d) was found that is not supported by this specification',
$ppCount,
));
throw Exception\RuntimeException::forUnsupportedParameterCountOf($ppCount);
}

$topParameters[] = vsprintf($paramSpecs[$position][$ppCount], $paramsForPosition);
Expand Down Expand Up @@ -261,7 +251,7 @@ protected function processExpression(
$driver,
$parameterContainer,
),
default => throw new Exception\InvalidArgumentException('Unknown argument type'),
default => throw Exception\InvalidArgumentException::forUnknownArgumentType(),
};
}

Expand All @@ -287,7 +277,7 @@ protected function processExpressionOrSelect(
$parameterContainer,
"{$namedParameterPrefix}{$vIndex}subpart",
),
default => throw new ValueError('Invalid Argument type'),
default => throw Exception\InvalidArgumentException::forInvalidArgumentType(),
};
}

Expand Down
7 changes: 1 addition & 6 deletions src/Sql/Ddl/Column/AbstractLengthColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PhpDb\Sql\Exception\InvalidArgumentException;

use function array_splice;
use function sprintf;
use function strlen;
use function substr;

Expand Down Expand Up @@ -48,11 +47,7 @@ public function getExpressionData(): array
$hasLength = '' !== $lengthExpression && '0' !== $lengthExpression;

if (! $hasLength && $this->lengthRequired) {
throw new InvalidArgumentException(sprintf(
'Column "%s" of type %s requires a length',
$this->name,
$this->type,
));
throw InvalidArgumentException::forMissingColumnLength($this->name, $this->type);
}

$expressionData = parent::getExpressionData();
Expand Down
8 changes: 1 addition & 7 deletions src/Sql/Ddl/Column/AbstractPrecisionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Override;
use PhpDb\Sql\Exception\InvalidArgumentException;

use function sprintf;

abstract class AbstractPrecisionColumn extends AbstractLengthColumn
{
protected ?int $decimal;
Expand Down Expand Up @@ -59,11 +57,7 @@ protected function getLengthExpression(): string
}

if (null === $this->length) {
throw new InvalidArgumentException(sprintf(
'Column "%s" of type %s has a decimal scale but no digits',
$this->name,
$this->type,
));
throw InvalidArgumentException::forMissingDecimalDigits($this->name, $this->type);
}

return "{$this->length},{$this->decimal}";
Expand Down
6 changes: 1 addition & 5 deletions src/Sql/Ddl/Column/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use function ctype_digit;
use function is_int;
use function is_string;
use function sprintf;
use function strlen;
use function substr;

Expand Down Expand Up @@ -57,9 +56,6 @@ private function normaliseDisplayWidth(mixed $length): string
return $length;
}

throw new InvalidArgumentException(sprintf(
'Column "%s" length option must be a non-negative integer',
$this->name,
));
throw InvalidArgumentException::forInvalidColumnLength($this->name);
}
}
2 changes: 1 addition & 1 deletion src/Sql/Ddl/Constraint/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Check extends AbstractConstraint
public function __construct(string|ExpressionInterface $expression, ?string $name = null)
{
if ('' === $expression) {
throw new InvalidArgumentException('Check constraint expression must not be an empty string.');
throw InvalidArgumentException::forEmptyCheckExpression();
}

parent::__construct(null, $name);
Expand Down
Loading
Loading