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

Added return types, removed unused Yii from model.php, replaced imports #546

Closed
wants to merge 1 commit into from
Closed

Conversation

Erkinbek
Copy link

Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues Added return types

Copy link

what-the-diff bot commented Feb 10, 2024

PR Summary

  • Modification on controller.php in generators/crud/default directory

    • The usage of the yii\web\Response library has been introduced. This could facilitate handling of HTTP requests and responses within the CRUD operations.
    • The return types for several important operations, dealing with display (actionIndex, actionView), manipulation (actionCreate, actionUpdate, actionDelete) and retrieval (findModel) of data, were updated. This could enable more controlled response management, providing flexibility in responses, adapting as either string , Response or array type.
  • Updates to model.php in generators/model/default directory

    • New return types for several core functions responsible for database interaction and data representation in the application have been introduced. These will establish a clear contract for what these functions are expected to return, possibly improving code readability and maintenance.
  • Changes in controller.php in generators/module/default directory

    • The return type for the primary display function, actionIndex(), has been changed to string. This change is expected to provide better control and management of the output generated by this function.

From a less-technical perspective, these changes should enhance the reliability and consistency of the application, and potentially make it less prone to errors related to mismatched or unexpected return types.

@samdark
Copy link
Member

samdark commented Feb 10, 2024

It won't work with older PHP versions.

@uldisn
Copy link
Contributor

uldisn commented Feb 11, 2024

It won't work with older PHP versions.

If create own templates for each PHP version, it will work.

@Erkinbek
Copy link
Author

All time when i generate code with gii, my idea (PHPStorm) will shows this lines as not optimized code. So if people are using old versions of php, just need close this PR. Thank you for your attention :)

@Erkinbek Erkinbek closed this Feb 12, 2024
@uldisn
Copy link
Contributor

uldisn commented Feb 12, 2024

Idea no bad! In https://github.com/yiisoft/yii2-gii/blob/master/src/generators/model/Generator.php#L313

if (phpversion() < '5.2' ) {
    $template = 'model_52.php';
} elseif {phpversion() >= '5.2' &&  phpversion() < '5.7'} {
   $template = 'model_52_57.php';
} elseif {phpversion() >= '5.7' &&  phpversion() < '7.4'} {
   $template = 'model_57_74.php';
} {
   $template = 'model_74.php';
}
$files[] = new CodeFile(
    Yii::getAlias('@' . str_replace('\\', '/', $this->ns)) . '/' . $modelClassName . '.php',
    $this->render($template, $params)
);

For each PHP version own model_*php.

@Erkinbek
Copy link
Author

OK. I'll fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants