Skip to content

Improve typehint#382

Merged
VincentLanglet merged 3 commits intosonata-project:1.xfrom
VincentLanglet:PhpdocType
Apr 8, 2021
Merged

Improve typehint#382
VincentLanglet merged 3 commits intosonata-project:1.xfrom
VincentLanglet:PhpdocType

Conversation

@VincentLanglet
Copy link
Copy Markdown
Member

@VincentLanglet VincentLanglet commented Apr 4, 2021

Subject

I am targeting this branch, because BC.

The $revision param is often restrict to int but could work with string too. (and SonataAdmin is using int|string).
The $id seems to only work with int|string|array if I read the code.

I also add some typehint for constructor or Exception/Object we're using.

This will fix some errors from https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1386/checks?check_run_id=2265615169

Changelog

### Added
- Allow `$revisions` param to be a string in `AuditManager` methods.

### Deprecated
- Passing another value than 'string', 'integer', 'smallint', 'bigint' or 'guid' for the `revision_id_field_type` value.

Copy link
Copy Markdown
Member

@phansys phansys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the configuration, the revision id seems to accept anything:

->scalarNode('revision_id_field_type')->defaultValue('integer')->end()

Maybe we could restrict the config to "integer" and "string".

@VincentLanglet
Copy link
Copy Markdown
Member Author

Maybe we could restrict the config to "integer" and "string".

It would be a BC-break no ? I think we will be able to restrict only for the next major...

@VincentLanglet VincentLanglet requested review from a team and phansys April 6, 2021 09:58
@phansys
Copy link
Copy Markdown
Member

phansys commented Apr 6, 2021

It would be a BC-break no ? I think we will be able to restrict only for the next major...

Yes. We should deprecate the types that we consider invalid before.

@VincentLanglet
Copy link
Copy Markdown
Member Author

@phansys There is the following code:

$revisionsTable->addColumn('id', $this->config->getRevisionIdFieldType(), [
            'autoincrement' => true,
        ]);

Would it work with string ?

@phansys
Copy link
Copy Markdown
Member

phansys commented Apr 6, 2021

Would it work with string ?

I think the autoincrement option is ignored for other types.

Comment thread src/DependencyInjection/Configuration.php Outdated
Comment thread src/DependencyInjection/Configuration.php Outdated
Comment thread src/DependencyInjection/Configuration.php
@VincentLanglet VincentLanglet requested review from a team and phansys April 6, 2021 23:29
phansys
phansys previously approved these changes Apr 7, 2021
->scalarNode('revision_id_field_type')->defaultValue('integer')->end()
->scalarNode('revision_id_field_type')
->defaultValue('integer')
// NEXT_MAJOR: Use validate() instead.
Copy link
Copy Markdown
Member

@franmomu franmomu Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about enumNode instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know this.

protected $revision;

public function __construct($className, $id, $revision)
public function __construct(?string $className, ?array $id, $revision)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function __construct(?string $className, ?array $id, $revision)
/**
* @param int|string|null $revision
*/
public function __construct(?string $className, ?array $id, $revision)

franmomu
franmomu previously approved these changes Apr 8, 2021
@VincentLanglet VincentLanglet dismissed stale reviews from franmomu and phansys via b6e7efe April 8, 2021 19:39
@VincentLanglet VincentLanglet merged commit 89fb8b2 into sonata-project:1.x Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants