Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
33 changes: 27 additions & 6 deletions build/controllers/PhpDocController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use yii\helpers\Console;
use yii\helpers\FileHelper;
use yii\helpers\Json;
use yii\web\Controller as WebController;

/**
* PhpDocController is there to help to maintain PHPDoc annotation in class files.
Expand All @@ -22,6 +23,19 @@
*/
class PhpDocController extends Controller
{
/**
* Manually added PHPDoc properties that do not need to be removed.
*
* @phpstan-var array<class-string, string[]>
*/
private const MANUALLY_ADDED_PROPERTIES = [
WebController::class => [
'request',
'response',
'view',
],
];

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -535,7 +549,7 @@ protected function updateClassPropertyDocs($file, $className, $propertyDoc)
}

$oldDoc = $ref->getDocComment();
$newDoc = $this->cleanDocComment($this->updateDocComment($oldDoc, $propertyDoc));
$newDoc = $this->cleanDocComment($this->updateDocComment($oldDoc, $propertyDoc, $className));

$seenSince = false;
$seenAuthor = false;
Expand Down Expand Up @@ -614,8 +628,9 @@ protected function cleanDocComment($doc)
* @param $properties
* @return string
*/
protected function updateDocComment($doc, $properties)
protected function updateDocComment($doc, $properties, $className)
{
$manuallyAddedProperties = self::MANUALLY_ADDED_PROPERTIES[$className] ?? [];
$lines = explode("\n", $doc);
$propertyPart = false;
$propertyPosition = false;
Expand All @@ -632,7 +647,10 @@ protected function updateDocComment($doc, $properties)
$propertyPart = false;
}
if ($propertyPart) {
unset($lines[$i]);
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)) {
unset($lines[$i]);
}
}
}

Expand Down Expand Up @@ -700,16 +718,16 @@ protected function generateClassPropertyDocs($fileName)

$gets = $this->match(
'#\* @return (?<type>[\w\\|\\\\\\[\\]]+)(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/' .
'[\s\n]{2,}public function (?<kind>get)(?<name>\w+)\((?:,? ?\$\w+ ?= ?[^,]+)*\)#',
'[\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,}public function (?<kind>set)(?<name>\w+)\(\$\w+(?:, ?\$\w+ ?= ?[^,]+)*\)#',
'[\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,}public function [g|s]et(?<name>\w+)\(((?:,? ?\$\w+ ?= ?[^,]+)*|\$\w+(?:, ?\$\w+ ?= ?[^,]+)*)\)#',
'[\s\n]{2,}(\#\[\\\\*.+\])*[\s\n]{2,}public function [g|s]et(?<name>\w+)\(((?:,? ?\$\w+ ?= ?[^,]+)*|\$\w+(?:, ?\$\w+ ?= ?[^,]+)*)\)#',
$class['content']);
$acrs = array_merge($properties, $gets, $sets);

Expand Down Expand Up @@ -791,6 +809,9 @@ protected function match($pattern, $subject, $split = false)

protected function fixSentence($str)
{
$str = rtrim($str, '*');
$str = rtrim($str);

// TODO fix word wrap
if ($str == '') {
return '';
Expand Down
8 changes: 5 additions & 3 deletions framework/base/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
*
* For more details and usage information on Action, see the [guide article on actions](guide:structure-controllers).
*
* @template T of Controller
* @property-read string $uniqueId The unique ID of this action among the whole application.
* @phpstan-property T $controller
* @psalm-property T $controller
*
* @author Qiang Xue <[email protected]>
* @since 2.0
*
* @template T of Controller
*
* @phpstan-property T $controller
* @psalm-property T $controller
*/
class Action extends Component
{
Expand Down
3 changes: 2 additions & 1 deletion framework/base/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
* @property-read array $errors Errors for all attributes or the specified attribute. Empty array is returned
* if no error. See [[getErrors()]] for detailed description. Note that when returning errors for all attributes,
* the result is a two-dimensional array, like the following: ```php [ 'username' => [ 'Username is required.',
* 'Username must contain only word characters.', ], 'email' => [ 'Email address is invalid.', ] ] ``` .
* 'Username must contain only word characters.', ], 'email' => [ 'Email address is invalid.', ] ] ```.
* @property-read array $firstErrors The first errors. The array keys are the attribute names, and the array
* values are the corresponding error messages. An empty array will be returned if there is no error.
* @property-read ArrayIterator $iterator An iterator for traversing the items in the list.
* @property string $scenario The scenario that this model is in. Defaults to [[SCENARIO_DEFAULT]].
* @property-read ArrayObject|\yii\validators\Validator[] $validators All the validators declared in the
* model.
Expand Down
4 changes: 2 additions & 2 deletions framework/console/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public function getPassedOptionValues()
* You may override this method to return customized summary.
* The default implementation returns first line from the PHPDoc comment.
*
* @return string
* @return string the one-line short summary describing this controller
*/
public function getHelpSummary()
{
Expand All @@ -532,7 +532,7 @@ public function getHelpSummary()
*
* You may override this method to return customized help.
* The default implementation returns help information retrieved from the PHPDoc comment.
* @return string
* @return string the help information for this controller
*/
public function getHelp()
{
Expand Down
2 changes: 1 addition & 1 deletion framework/db/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* For more details and usage information on QueryBuilder, see the [guide article on query builders](guide:db-query-builder).
*
* @property-write string[] $conditionClasses Map of condition aliases to condition classes. For example:
* ```php ['LIKE' => yii\db\condition\LikeCondition::class] ``` .
* ```php ['LIKE' => yii\db\condition\LikeCondition::class] ```.
* @property-write string[] $expressionBuilders Array of builders that should be merged with the pre-defined
* ones in [[expressionBuilders]] property.
*
Expand Down
5 changes: 4 additions & 1 deletion framework/web/CookieCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public function __construct($cookies = [], $config = [])
* Returns an iterator for traversing the cookies in the collection.
* This method is required by the SPL interface [[\IteratorAggregate]].
* It will be implicitly called when you use `foreach` to traverse the collection.
* @return ArrayIterator<string, Cookie> an iterator for traversing the cookies in the collection.
* @return ArrayIterator an iterator for traversing the cookies in the collection.
*
* @phpstan-return ArrayIterator<string, Cookie>
* @psalm-return ArrayIterator<string, Cookie>
*/
#[\ReturnTypeWillChange]
public function getIterator()
Expand Down
Loading