yiisoft / yii2-gii

Yii 2 Gii Extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
202 stars 192 forks source link

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

Closed Erkinbek closed 9 months ago

Erkinbek commented 9 months ago
Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues Added return types
what-the-diff[bot] commented 9 months ago

PR Summary

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 commented 9 months ago

It won't work with older PHP versions.

uldisn commented 9 months ago

It won't work with older PHP versions.

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

Erkinbek commented 9 months ago

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 :)

uldisn commented 9 months ago

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 commented 9 months ago

OK. I'll fix it