Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reformat code to be PSR-2 compatible
b5f8a4dc22d5f8188405a2099d85fc154226c9b2
# Added php-cs-fixer coding standards validation to Travis CI
ba0ab403b52124c941dbeb46fbd9efdc12252a5d
17 changes: 9 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
*.ttf binary

# Ignore some meta files when creating an archive of this repository
# We do not ignore any content, because this repo represents the
# We do not ignore any content, because this repo represents the
# `yiisoft/yii2-dev` package, which is expected to ship all tests and docs.
/.appveyor.yml export-ignore
/.github export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/.appveyor.yml export-ignore
/.github export-ignore
/.editorconfig export-ignore
/.git-blame-ignore-revs export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore

# Avoid merge conflicts in CHANGELOG
# https://about.gitlab.com/2015/02/10/gitlab-reduced-merge-conflicts-by-90-percent-with-changelog-placeholders/
Expand Down
6 changes: 3 additions & 3 deletions build/controllers/MimeTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private function generateMimeTypesFile($outFile, $content)
* https://raw.githubusercontent.com/apache/httpd/refs/heads/trunk/docs/conf/mime.types
* This file has been placed in the public domain for unlimited redistribution.
*
* All extra changes made to this file must be comitted to /build/controllers/MimeTypeController.php
* All extra changes made to this file must be committed to /build/controllers/MimeTypeController.php
* otherwise they will be lost on next build.
*/
\$mimeTypes = $array;
Expand Down Expand Up @@ -153,7 +153,7 @@ private function generateMimeAliasesFile($outFile)
*
* This file contains aliases for MIME types.
*
* All extra changes made to this file must be comitted to /build/controllers/MimeTypeController.php
* All extra changes made to this file must be committed to /build/controllers/MimeTypeController.php
* otherwise they will be lost on next build.
*/
return $array;
Expand Down Expand Up @@ -217,7 +217,7 @@ private function generateMimeExtensionsFile($outFile, $content)
* https://raw.githubusercontent.com/apache/httpd/refs/heads/trunk/docs/conf/mime.types
* This file has been placed in the public domain for unlimited redistribution.
*
* All extra changes made to this file must be comitted to /build/controllers/MimeTypeController.php
* All extra changes made to this file must be committed to /build/controllers/MimeTypeController.php
* otherwise they will be lost on next build.
*/
return $array;
Expand Down
111 changes: 90 additions & 21 deletions build/controllers/PhpDocController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
namespace yii\build\controllers;

use Yii;
use yii\console\Controller;
use yii\base\Model;
use yii\base\Module;
use yii\console\Controller as ConsoleController;
use yii\db\QueryBuilder;
use yii\helpers\Console;
use yii\helpers\FileHelper;
use yii\helpers\Json;
use yii\log\Dispatcher;
use yii\log\Target;
use yii\web\Controller as WebController;
use yii\web\Request as WebRequest;

/**
* PhpDocController is there to help to maintain PHPDoc annotation in class files.
Expand All @@ -21,10 +27,10 @@
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class PhpDocController extends Controller
class PhpDocController extends ConsoleController
{
/**
* Manually added PHPDoc properties that do not need to be removed.
* Manually added PHPDoc properties that do not need to be removed or changed.
*
* @phpstan-var array<class-string, string[]>
*/
Expand All @@ -34,8 +40,33 @@ class PhpDocController extends Controller
'response',
'view',
],
ConsoleController::class => [
'request',
'response',
],
Model::class => [
'errors',
],
Module::class => [
'aliases',
],
Dispatcher::class => [
'flushInterval',
'logger',
],
Target::class => [
'enabled',
],
WebRequest::class => [
'hostInfo',
],
QueryBuilder::class => [
'conditionClasses',
],
];

private const PROPERTIES_ENCLOSURE = " *\n";

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -634,6 +665,9 @@ protected function updateDocComment($doc, $properties, $className)
$lines = explode("\n", $doc);
$propertyPart = false;
$propertyPosition = false;
$lastPropertyName = null;
$hasManuallyAddedProperties = false;

foreach ($lines as $i => $line) {
$line = trim($line);
if (strncmp($line, '* @property', 11) === 0) {
Expand All @@ -647,21 +681,44 @@ protected function updateDocComment($doc, $properties, $className)
$propertyPart = false;
}
if ($propertyPart) {
preg_match('/@property\s+\w+\s+\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/', $line, $matches);
if (!isset($matches[1]) || !in_array($matches[1], $manuallyAddedProperties)) {
preg_match(
'/@property(?:-read|-write)?\s+([\\\\\w\|\[\]]+)\s+\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/',
$line,
$matches
);

if (isset($matches[2])) {
$lastPropertyName = $matches[2];
}

if (in_array($lastPropertyName, $manuallyAddedProperties)) {
$hasManuallyAddedProperties = true;
} else {
unset($lines[$i]);
}
}
}

if ($properties === '') {
return implode("\n", $lines);
}

// if no properties or other tags were present add properties at the end
if ($propertyPosition === false) {
$propertyPosition = \count($lines) - 2;
}

// if there are properties that were added manually, remove start enclosure
if ($hasManuallyAddedProperties) {
$properties = substr($properties, strlen(self::PROPERTIES_ENCLOSURE));
}

$finalDoc = '';
foreach ($lines as $i => $line) {
$finalDoc .= $line . "\n";
if (!$hasManuallyAddedProperties || $i !== $propertyPosition) {
$finalDoc .= $line . "\n";
}

if ($i == $propertyPosition) {
$finalDoc .= $properties;
}
Expand Down Expand Up @@ -717,23 +774,33 @@ protected function generateClassPropertyDocs($fileName)
$className = $namespace . '\\' . $class['name'];

$gets = $this->match(
'#\* @return (?<type>[\w\\|\\\\\\[\\]]+)(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/' .
'[\s\n]{2,}(\#\[\\\\*.+\])*[\s\n]{2,}public function (?<kind>get)(?<name>\w+)\((?:,? ?\$\w+ ?= ?[^,]+)*\)#',
$class['content'], true);
$sets = $this->match(
'#\* @param (?<type>[\w\\|\\\\\\[\\]]+) \$\w+(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/' .
'[\s\n]{2,}(\#\[\\\\*.+\])*[\s\n]{2,}public function (?<kind>set)(?<name>\w+)\(\$\w+(?:, ?\$\w+ ?= ?[^,]+)*\)#',
$class['content'], true);
// check for @property annotations in getter and setter
$properties = $this->match(
'#\* @(?<kind>property) (?<type>[\w\\|\\\\\\[\\]]+)(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/' .
'[\s\n]{2,}(\#\[\\\\*.+\])*[\s\n]{2,}public function [g|s]et(?<name>\w+)\(((?:,? ?\$\w+ ?= ?[^,]+)*|\$\w+(?:, ?\$\w+ ?= ?[^,]+)*)\)#',
$class['content']);
$acrs = array_merge($properties, $gets, $sets);
'#\* @return (?<type>[\w\\|\\\\\\[\\]]+)'
. '(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)((\*\n)|(\*\s.+))*\*/'
. '[\s\n]{2,}(\#\[\\\\*.+\])*[\s\n]{2,}'
. 'public function (?<kind>get)(?<name>\w+)\((?:,? ?\$\w+ ?= ?[^,]+)*\)(\:\s*[\w\\|\\\\\\[\\]]+)?#',
$class['content'],
true
);

$sets = $this->match(
'#\* @param (?<type>[\w\\|\\\\\\[\\]]+) \$\w+'
. '(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)((\*\n)|(\*\s.+))*\*/'
. '[\s\n]{2,}(\#\[\\\\*.+\])*[\s\n]{2,}'
. 'public function (?<kind>set)(?<name>\w+)\(([\w\\|\\\\\\[\\]]+\s*)?\$\w+(?:, ?\$\w+ ?= ?[^,]+)*\)(\:\s*[\w\\|\\\\\\[\\]]+)?#',
$class['content'],
true
);

$acrs = array_merge($gets, $sets);
$manuallyAddedProperties = self::MANUALLY_ADDED_PROPERTIES[$className] ?? [];
$props = [];

foreach ($acrs as &$acr) {
$acr['name'] = lcfirst($acr['name']);
if (in_array($acr['name'], $manuallyAddedProperties)) {
continue;
}

$acr['comment'] = trim(preg_replace('#(^|\n)\s+\*\s?#', '$1 * ', $acr['comment']));
$props[$acr['name']][$acr['kind']] = [
'type' => $acr['type'],
Expand All @@ -747,7 +814,6 @@ protected function generateClassPropertyDocs($fileName)

ksort($props);

$phpdoc .= " *\n";
foreach ($props as $propName => &$prop) {
$docLine = ' * @property';
$note = '';
Expand Down Expand Up @@ -777,7 +843,10 @@ protected function generateClassPropertyDocs($fileName)

$phpdoc .= $docLine;
}
$phpdoc .= " *\n";
}

if ($phpdoc !== '') {
$phpdoc = self::PROPERTIES_ENCLOSURE . $phpdoc . self::PROPERTIES_ENCLOSURE;
}

return [$className, $phpdoc];
Expand Down
2 changes: 1 addition & 1 deletion build/controllers/ReleaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ protected function releaseFramework($frameworkPath, $version)
$this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);

$this->stdout('updating mimetype magic file and mime aliases...', Console::BOLD);
$this->dryRun || Yii::$app->runAction('mime-type', ["$frameworkPath/helpers/mimeTypes.php"], ["$frameworkPath/helpers/mimeAliases.php"]);
$this->dryRun || Yii::$app->runAction('mime-type', ["$frameworkPath/helpers/mimeTypes.php"]);
$this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);

$this->stdout("fixing various PHPDoc style issues...\n", Console::BOLD);
Expand Down
4 changes: 4 additions & 0 deletions build/controllers/views/translation/report_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* @var string $sourcePath
* @var string $translationPath
* @var array $results
*
* @phpstan-var \yii\web\View&object{
* context: \yii\build\controllers\TranslationController,
* } $this
*/

?><!doctype html>
Expand Down
29 changes: 29 additions & 0 deletions docs/internals-ru/core-code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,35 @@ public function getEventHandlers($name)
[Раздел руководства](guide:file-name.md#subsection)
```

##### Примеры кода

В примерах кода должен использоваться синтаксис Markdown, но не должен указываться язык.
Указание языка в примерах кода может привести к нарушению их отображения в некоторых IDE. Пример:

```php
/**
* Correct code example:
*
* ```
* $object->doMagic();
* ```
*/
public function doMagic()
{
}

/**
* Incorrect code example:
*
* ```php
* $object->doMagic();
* ```
*/
public function doMagic()
{
}
```


#### Комментарии

Expand Down
29 changes: 29 additions & 0 deletions docs/internals/core-code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,35 @@ It is also possible to link to the Guide using the following syntax:
[link to guide](guide:file-name.md#subsection)
```

##### Code examples

Code examples should use Markdown syntax, but they should not specify the language.
Specifying a language in code examples may break their display in some IDEs. Here is an example:

```php
/**
* Correct code example:
*
* ```
* $object->doMagic();
* ```
*/
function doMagic()
{
}

/**
* Incorrect code example:
*
* ```php
* $object->doMagic();
* ```
*/
function doMagic()
{
}
```


#### Comments

Expand Down
10 changes: 5 additions & 5 deletions framework/BaseYii.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public static function autoload($className)
*
* Below are some usage examples:
*
* ```php
* ```
* // create an object using a class name
* $object = Yii::createObject('yii\db\Connection');
*
Expand Down Expand Up @@ -343,8 +343,8 @@ public static function autoload($className)
* @see \yii\di\Container
*
* @template T
* @phpstan-param class-string<T>|array{class: class-string<T>, ...}|callable(): T $type
* @psalm-param class-string<T>|array{class: class-string<T>, ...}|callable(): T $type
* @phpstan-param class-string<T>|array{class?: class-string<T>, __class?: class-string<T>, ...}|callable(): T $type
* @psalm-param class-string<T>|array{class?: class-string<T>, __class?: class-string<T>, ...}|callable(): T $type
* @phpstan-return T
* @psalm-return T
*/
Expand Down Expand Up @@ -462,7 +462,7 @@ public static function info($message, $category = 'application')
* This has to be matched with a call to [[endProfile]] with the same category name.
* The begin- and end- calls must also be properly nested. For example,
*
* ```php
* ```
* \Yii::beginProfile('block1');
* // some code to be profiled
* \Yii::beginProfile('block2');
Expand Down Expand Up @@ -501,7 +501,7 @@ public static function endProfile($token, $category = 'application')
* You can add parameters to a translation message that will be substituted with the corresponding value after
* translation. The format for this is to use curly brackets around the parameter name as you can see in the following example:
*
* ```php
* ```
* $username = 'Alexander';
* echo \Yii::t('app', 'Hello, {username}!', ['username' => $username]);
* ```
Expand Down
9 changes: 9 additions & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ Yii Framework 2 Change Log
- Bug #20485: Fix error `Cannot unset string offsets` in `yii\di\Instance:ensure(['__class' => ...], 'some\class\name')` (max-s-lab)
- Enh #20505: `ArrayDataProvider` key handling with flexible path support (fetus-hina)
- Bug #20508: Fix PHPDoc, add PHPStan/Psalm annotations for `yii\web\CookieCollection::getIterator`. Add missing `@property` annotation in `yii\base\Model` (max-s-lab)
- Bug #20513: Fix code examples in PHPDoc (max-s-lab)
- Enh #20514: Add `@property` annotations for `yii\console\Controller` (max-s-lab)
- Bug #20515: Fix `@param` annotations in `BetweenColumnsCondition`, `InCondition` and `LikeCondition` (max-s-lab)
- Bug #20516: Fix `@template` annotations in `ActiveRecord` (max-s-lab)
- Bug #19506: Fix `@property` annotations in `yii\console\widgets\Table`, `yii\di\Container` and `yii\web\Session` (max-s-lab)
- Enh #20525: Add `@template` annotations for all actions (max-s-lab)
- Bug #20524: Fix PHPStan/Psalm annotations in `Yii::createObject` (max-s-lab)
- Bug #20530: Fix notice "Object of class DateTimeImmutable could not be converted to int" in `CookieCollection::has` (max-s-lab)


2.0.53 June 27, 2025
--------------------
Expand Down
Loading
Loading