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

Improve typehint #382

Merged
merged 3 commits into from
Apr 8, 2021
Merged

Conversation

VincentLanglet
Copy link
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
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
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 phansys and a team April 6, 2021 09:58
@phansys
Copy link
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
Member Author

@phansys There is the following code:

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

Would it work with string ?

@phansys
Copy link
Member

phansys commented Apr 6, 2021

Would it work with string ?

I think the autoincrement option is ignored for other types.

src/DependencyInjection/Configuration.php Outdated Show resolved Hide resolved
src/DependencyInjection/Configuration.php Outdated Show resolved Hide resolved
src/DependencyInjection/Configuration.php Show resolved Hide resolved
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
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
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
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
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