Skip to content
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

Minor CS cleanup #1057

Merged
merged 11 commits into from
Aug 25, 2022
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
9 changes: 1 addition & 8 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

$finder = PhpCsFixer\Finder::create()
->in([__DIR__])
->exclude([
'cache',
'build',
'vendor',
]);
->exclude(['vendor']);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
Expand Down Expand Up @@ -43,9 +39,6 @@
'no_superfluous_elseif' => false,
'ordered_class_elements' => false,
'php_unit_internal_class' => false,
'php_unit_test_case_static_method_calls' => [
'call_type' => 'this',
],
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => false,
'return_assignment' => false,
Expand Down
3 changes: 2 additions & 1 deletion docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ store extra fields there. In your code::

class Transaction_Transfer extends Transaction
{
protected function init(): void {
protected function init(): void
{
parent::init();

$j = $this->join('transaction_transfer.transaction_id');
Expand Down
5 changes: 0 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ parameters:
paths:
- ./
excludePaths:
- cache/
- build/
- vendor/

# TODO review once we drop PHP 7.x support
treatPhpDocTypesAsCertain: false

# some extra rules
checkAlwaysTrueCheckTypeFunctionCall: true
checkAlwaysTrueInstanceof: true
Expand Down
6 changes: 4 additions & 2 deletions src/Model/Scope/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function __construct($key, $operator = null, $value = null)
throw new Exception('Only Scope can contain another conditions');
} elseif ($key instanceof Field) { // for BC
$key = $key->shortName;
} elseif (!is_string($key) && !($key instanceof Expressionable)) {
} elseif (!is_string($key) && !$key instanceof Expressionable) { // @phpstan-ignore-line
throw new Exception('Field must be a string or an instance of Expressionable');
}

Expand Down Expand Up @@ -274,7 +274,9 @@ public function negate()

public function toWords(Model $model = null): string
{
$model = $model ?: $this->getModel();
if ($model === null) {
$model = $this->getModel();
}

if ($model === null) {
throw new Exception('Condition must be associated with Model to convert to words');
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function typecastLoadField(Field $field, $value)
{
if ($value === null) {
return null;
} elseif (!is_scalar($value)) {
} elseif (!is_scalar($value)) { // @phpstan-ignore-line
throw new Exception('Unexpected non-scalar value');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/Array_/Db/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __debugInfo(): array
*/
protected function assertValidIdentifier($name): void
{
if (!is_string($name) || !$name || is_numeric($name)) {
if (!is_string($name) || $name === '' || is_numeric($name)) { // @phpstan-ignore-line
throw (new Exception('Name must be a non-empty non-numeric string'))
->addMoreInfo('name', $name);
}
Expand Down
13 changes: 3 additions & 10 deletions src/Persistence/Sql/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,7 @@ protected function consume($expr, string $escapeMode = self::ESCAPE_PARAM)
->addMoreInfo('escapeMode', $escapeMode);
}

if ($expr instanceof Expressionable) {
$expr = $expr->getDsqlExpression($this);
}

if (!$expr instanceof self) {
throw (new Exception('Only Expressionable object can be used in Expression'))
->addMoreInfo('object', $expr);
}
$expr = $expr->getDsqlExpression($this);

// render given expression into params of the current expression
$expressionParamBaseBackup = $expr->paramBase;
Expand Down Expand Up @@ -599,7 +592,7 @@ protected function _execute(?object $connection, bool $fromExecuteStatement)
$type = ParameterType::BINARY;
}
}
} elseif (is_resource($val)) {
} elseif (is_resource($val)) { // phpstan-ignore-line
throw new Exception('Resource type is not supported, set value as string instead');
} else {
throw (new Exception('Incorrect param type'))
Expand Down Expand Up @@ -703,7 +696,7 @@ private function castGetValue($v): ?string
}

// for PostgreSQL/Oracle CLOB/BLOB datatypes and PDO driver
if (is_resource($v) && get_resource_type($v) === 'stream') {
if (is_resource($v) && get_resource_type($v) === 'stream') { // @phpstan-ignore-line
$platform = $this->connection->getDatabasePlatform();
if ($platform instanceof PostgreSQLPlatform || $platform instanceof OraclePlatform) {
$v = stream_get_contents($v);
Expand Down
7 changes: 1 addition & 6 deletions src/Persistence/Sql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,7 @@ public function set($field, $value = null)
->addMoreInfo('value', $value);
}

if (is_string($field) || $field instanceof Expressionable) {
$this->args['set'][] = [$field, $value];
} else {
throw (new Exception('Field name should be string or Expressionable'))
->addMoreInfo('field', $field);
}
$this->args['set'][] = [$field, $value];

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(object $source)
$this->_connection = $source;
} elseif ($source instanceof Persistence\Sql) {
$this->_connection = $source->getConnection();
} elseif ($source instanceof Model && $source->getPersistence() instanceof Persistence\Sql) {
} elseif ($source instanceof Model && $source->getPersistence() instanceof Persistence\Sql) { // @phpstan-ignore-line
$this->_connection = $source->getPersistence()->getConnection();
} else {
throw (new Exception('Source must be SQL connection, persistence or initialized model'))
Expand Down
28 changes: 14 additions & 14 deletions src/Schema/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ function ($matches) use ($platform) {
);

if ($platform instanceof SqlitePlatform && $convertedSql !== $sql) {
$this->assertSame($sql, $convertedSql);
static::assertSame($sql, $convertedSql);
}

return $convertedSql;
}

protected function assertSameSql(string $expectedSqliteSql, string $actualSql, string $message = ''): void
{
$this->assertSame($this->convertSqlFromSqlite($expectedSqliteSql), $actualSql, $message);
static::assertSame($this->convertSqlFromSqlite($expectedSqliteSql), $actualSql, $message);
}

/**
* @param mixed $a
* @param mixed $b
*/
private function compareExportUnorderedValue($a, $b): int
private static function compareExportUnorderedValue($a, $b): int
{
if ($a === $b) {
return 0;
Expand Down Expand Up @@ -170,17 +170,17 @@ private function compareExportUnorderedValue($a, $b): int

if ($is2d) {
if (array_is_list($a) && array_is_list($b)) {
usort($a, fn ($a, $b) => $this->compareExportUnorderedValue($a, $b));
usort($b, fn ($a, $b) => $this->compareExportUnorderedValue($a, $b));
usort($a, fn ($a, $b) => self::compareExportUnorderedValue($a, $b));
usort($b, fn ($a, $b) => self::compareExportUnorderedValue($a, $b));
} else {
uasort($a, fn ($a, $b) => $this->compareExportUnorderedValue($a, $b));
uasort($b, fn ($a, $b) => $this->compareExportUnorderedValue($a, $b));
uasort($a, fn ($a, $b) => self::compareExportUnorderedValue($a, $b));
uasort($b, fn ($a, $b) => self::compareExportUnorderedValue($a, $b));
}
}

if (array_keys($a) === array_keys($b)) {
foreach ($a as $k => $v) {
$cmp = $this->compareExportUnorderedValue($v, $b[$k]);
$cmp = self::compareExportUnorderedValue($v, $b[$k]);
if ($cmp !== 0) {
return $cmp;
}
Expand All @@ -198,15 +198,15 @@ private function compareExportUnorderedValue($a, $b): int
* - 2D arrays (rows) are recursively compared without any order
* - objects implementing DateTimeInterface are compared by formatted output.
*/
protected function assertSameExportUnordered(array $expected, array $actual, string $message = ''): void
protected static function assertSameExportUnordered(array $expected, array $actual, string $message = ''): void
{
if ($this->compareExportUnorderedValue($expected, $actual) === 0) {
$this->assertTrue(true);
if (self::compareExportUnorderedValue($expected, $actual) === 0) {
static::assertTrue(true);

return;
}

$this->assertSame($expected, $actual, $message);
static::assertSame($expected, $actual, $message);
}

public function createMigrator(Model $model = null): Migrator
Expand Down Expand Up @@ -333,10 +333,10 @@ public function markTestIncompleteWhenCreateUniqueIndexIsNotSupportedByPlatform(
{
if ($this->getDatabasePlatform() instanceof SQLServerPlatform) {
// https://github.com/doctrine/dbal/issues/5507
$this->markTestIncomplete('TODO MSSQL: DBAL must setup unique index without WHERE clause');
static::markTestIncomplete('TODO MSSQL: DBAL must setup unique index without WHERE clause');
} elseif ($this->getDatabasePlatform() instanceof OraclePlatform) {
// https://github.com/doctrine/dbal/issues/5508
$this->markTestIncomplete('TODO Oracle: DBAL must setup unique index on table column too');
static::markTestIncomplete('TODO Oracle: DBAL must setup unique index on table column too');
}
}
}
Loading