PhpDocController.php 23.3 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\build\controllers;

10
use Yii;
11 12
use yii\console\Controller;
use yii\helpers\Console;
13
use yii\helpers\FileHelper;
14 15 16

/**
 * PhpDocController is there to help maintaining PHPDoc annotation in class files
17
 *
18 19 20 21 22 23
 * @author Carsten Brandt <mail@cebe.cc>
 * @author Alexander Makarov <sam@rmcreative.ru>
 * @since 2.0
 */
class PhpDocController extends Controller
{
24 25 26 27 28 29 30
    public $defaultAction = 'property';
    /**
     * @var boolean whether to update class docs directly. Setting this to false will just output docs
     * for copy and paste.
     */
    public $updateFiles = true;

Carsten Brandt committed
31

32
    /**
Carsten Brandt committed
33
     * Generates `@property` annotations in class files from getters and setters
34
     *
Carsten Brandt committed
35
     * Property description will be taken from getter or setter or from an `@property` annotation
36 37 38 39
     * in the getters docblock if there is one defined.
     *
     * See https://github.com/yiisoft/yii2/wiki/Core-framework-code-style#documentation for details.
     *
40
     * @param string $root the directory to parse files from. Defaults to YII2_PATH.
41 42
     */
    public function actionProperty($root = null)
Carsten Brandt committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    {
        $files = $this->findFiles($root);

        $nFilesTotal = 0;
        $nFilesUpdated = 0;
        foreach ($files as $file) {
            $result = $this->generateClassPropertyDocs($file);
            if ($result !== false) {
                list($className, $phpdoc) = $result;
                if ($this->updateFiles) {
                    if ($this->updateClassPropertyDocs($file, $className, $phpdoc)) {
                        $nFilesUpdated++;
                    }
                } elseif (!empty($phpdoc)) {
                    $this->stdout("\n[ " . $file . " ]\n\n", Console::BOLD);
                    $this->stdout($phpdoc);
                }
            }
            $nFilesTotal++;
        }

        $this->stdout("\nParsed $nFilesTotal files.\n");
        $this->stdout("Updated $nFilesUpdated files.\n");
    }

    /**
     * Fix some issues with PHPdoc in files
     *
71
     * @param string $root the directory to parse files from. Defaults to YII2_PATH.
Carsten Brandt committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
     */
    public function actionFix($root = null)
    {
        $files = $this->findFiles($root);

        $nFilesTotal = 0;
        $nFilesUpdated = 0;
        foreach ($files as $file) {
            $contents = file_get_contents($file);
            $sha = sha1($contents);

            // fix line endings
            $lines = preg_split('/(\r\n|\n|\r)/', $contents);

            $this->fixFileDoc($lines);
Carsten Brandt committed
87
            $this->fixDocBlockIndentation($lines);
88
            $lines = array_values($this->fixLineSpacing($lines));
Carsten Brandt committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

            $newContent = implode("\n", $lines);
            if ($sha !== sha1($newContent)) {
                $nFilesUpdated++;
            }
            file_put_contents($file, $newContent);
            $nFilesTotal++;
        }

        $this->stdout("\nParsed $nFilesTotal files.\n");
        $this->stdout("Updated $nFilesUpdated files.\n");

    }

    /**
     * @inheritdoc
     */
Alexander Makarov committed
106
    public function options($actionID)
Carsten Brandt committed
107
    {
Alexander Makarov committed
108
        return array_merge(parent::options($actionID), ['updateFiles']);
Carsten Brandt committed
109 110 111
    }

    protected function findFiles($root)
112 113 114
    {
        $except = [];
        if ($root === null) {
115
            $root = dirname(YII2_PATH);
116 117 118 119 120 121 122 123 124 125 126 127 128
            $extensionPath = "$root/extensions";
            foreach (scandir($extensionPath) as $extension) {
                if (ctype_alpha($extension) && is_dir($extensionPath . '/' . $extension)) {
                    Yii::setAlias("@yii/$extension", "$extensionPath/$extension");
                }
            }

            $except = [
                '.git/',
                '/apps/',
                '/build/',
                '/docs/',
                '/extensions/apidoc/helpers/PrettyPrinter.php',
Carsten Brandt committed
129
                '/extensions/apidoc/helpers/ApiIndexer.php',
130
                '/extensions/apidoc/helpers/ApiMarkdownLaTeX.php',
131 132 133 134
                '/extensions/codeception/TestCase.php',
                '/extensions/codeception/DbTestCase.php',
                '/extensions/composer/',
                '/extensions/gii/components/DiffRendererHtmlInline.php',
135
                '/extensions/gii/generators/extension/default/*',
136 137 138
                '/extensions/twig/TwigSimpleFileLoader.php',
                '/framework/BaseYii.php',
                '/framework/Yii.php',
Carsten Brandt committed
139
                'assets/',
140 141 142 143 144 145 146
                'tests/',
                'vendor/',
            ];
        }
        $root = FileHelper::normalizePath($root);
        $options = [
            'filter' => function ($path) {
Carsten Brandt committed
147 148 149 150 151
                    if (is_file($path)) {
                        $file = basename($path);
                        if ($file[0] < 'A' || $file[0] > 'Z') {
                            return false;
                        }
152 153
                    }

Carsten Brandt committed
154 155
                    return null;
                },
156 157 158 159 160 161 162 163
            'only' => ['*.php'],
            'except' => array_merge($except, [
                'views/',
                'requirements/',
                'gii/generators/',
                'vendor/',
            ]),
        ];
Carsten Brandt committed
164
        return FileHelper::findFiles($root, $options);
165 166
    }

167 168 169
    /**
     * Fix file PHPdoc
     */
Carsten Brandt committed
170
    protected function fixFileDoc(&$lines)
171
    {
Carsten Brandt committed
172 173 174 175 176
        // find namespace
        $namespace = false;
        $namespaceLine = '';
        $contentAfterNamespace = false;
        foreach($lines as $i => $line) {
177 178
            $line = trim($line);
            if (!empty($line)) {
179
                if (strncmp($line, 'namespace', 9) === 0) {
180 181 182 183 184 185
                    $namespace = $i;
                    $namespaceLine = $line;
                } elseif ($namespace !== false) {
                    $contentAfterNamespace = $i;
                    break;
                }
Carsten Brandt committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
            }
        }

        if ($namespace !== false && $contentAfterNamespace !== false) {
            while($contentAfterNamespace > 0) {
                array_shift($lines);
                $contentAfterNamespace--;
            }
            $lines = array_merge([
                "<?php",
                "/**",
                " * @link http://www.yiiframework.com/",
                " * @copyright Copyright (c) 2008 Yii Software LLC",
                " * @license http://www.yiiframework.com/license/",
                " */",
                "",
                $namespaceLine,
                ""
            ], $lines);
        }
206 207
    }

Carsten Brandt committed
208 209 210 211 212 213 214
    /**
     * Markdown aware fix of whitespace issues in doc comments
     */
    protected function fixDocBlockIndentation(&$lines)
    {
        $docBlock = false;
        $codeBlock = false;
215 216
        $listIndent = '';
        $tag = false;
Carsten Brandt committed
217 218
        $indent = '';
        foreach($lines as $i => $line) {
219
            if (preg_match('~^(\s*)/\*\*$~', $line, $matches)) {
Carsten Brandt committed
220 221
                $docBlock = true;
                $indent = $matches[1];
222
            } elseif (preg_match('~^(\s*)\*+/~', $line)) {
223 224 225
                if ($docBlock) { // could be the end of normal comment
                    $lines[$i] = $indent . ' */';
                }
Carsten Brandt committed
226 227 228
                $docBlock = false;
                $codeBlock = false;
                $listIndent = '';
229
                $tag = false;
Carsten Brandt committed
230
            } elseif ($docBlock) {
231 232 233 234 235 236 237 238
                $line = ltrim($line);
                if (isset($line[0]) && $line[0] === '*') {
                    $line = substr($line, 1);
                }
                if (isset($line[0]) && $line[0] === ' ') {
                    $line = substr($line, 1);
                }
                $docLine = str_replace("\t", '    ', rtrim($line));
Carsten Brandt committed
239 240 241 242 243
                if (empty($docLine)) {
                    $listIndent = '';
                } elseif ($docLine[0] === '@') {
                    $listIndent = '';
                    $codeBlock = false;
244
                    $tag = true;
Carsten Brandt committed
245 246 247
                    $docLine = preg_replace('/\s+/', ' ', $docLine);
                } elseif (preg_match('/^(~~~|```)/', $docLine)) {
                    $codeBlock = !$codeBlock;
248 249
                    $listIndent = '';
                } elseif (preg_match('/^(\s*)([0-9]+\.|-|\*|\+) /', $docLine, $matches)) {
Carsten Brandt committed
250
                    $listIndent = str_repeat(' ', strlen($matches[0]));
251
                    $tag = false;
Carsten Brandt committed
252 253 254 255
                    $lines[$i] = $indent . ' * ' . $docLine;
                    continue;
                }
                if ($codeBlock) {
256
                    $lines[$i] = rtrim($indent . ' * ' . $docLine);
Carsten Brandt committed
257
                } else {
258
                    $lines[$i] = rtrim($indent . ' * ' . (empty($listIndent) && !$tag ? $docLine : ($listIndent . ltrim($docLine))));
Carsten Brandt committed
259 260 261 262 263
                }
            }
        }
    }

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    /**
     * Fixes line spacing code style for properties and constants
     */
    protected function fixLineSpacing($lines)
    {
        $propertiesOnly = false;
        // remove blank lines between properties
        $skip = true;
        foreach($lines as $i => $line) {
            if (strpos($line, 'class ') !== false) {
                $skip = false;
            }
            if ($skip) {
                continue;
            }
            if (trim($line) === '') {
                unset($lines[$i]);
281
            } elseif (ltrim($line)[0] !== '*' && strpos($line, 'function ') !== false) {
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
                break;
            } elseif (trim($line) === '}') {
                $propertiesOnly = true;
                break;
            }
        }
        $lines = array_values($lines);

        // add back some
        $endofUse = false;
        $endofConst = false;
        $endofPublic = false;
        $endofProtected = false;
        $endofPrivate = false;
        $skip = true;
        $level = 0; // track array properties
        $property = '';
        foreach($lines as $i => $line) {
            if (strpos($line, 'class ') !== false) {
                $skip = false;
            }
            if ($skip) {
                continue;
            }
306 307

            // check for multi line array
308 309 310 311
            if ($level > 0) {
                ${'endof'.$property} = $i;
            }

312 313
            $line = trim($line);
            if (strncmp($line, 'public $', 8) === 0 || strncmp($line, 'public static $', 15) === 0) {
314 315
                $endofPublic = $i;
                $property = 'Public';
316
                $level = 0;
317
            } elseif (strncmp($line, 'protected $', 11) === 0 || strncmp($line, 'protected static $', 18) === 0) {
318 319
                $endofProtected = $i;
                $property = 'Protected';
320
                $level = 0;
321
            } elseif (strncmp($line, 'private $', 9) === 0 || strncmp($line, 'private static $', 16) === 0) {
322 323
                $endofPrivate = $i;
                $property = 'Private';
324
                $level = 0;
325
            } elseif (substr($line,0 , 6) === 'const ') {
326 327
                $endofConst = $i;
                $property = false;
328
            } elseif (substr($line,0 , 4) === 'use ') {
329 330
                $endofUse = $i;
                $property = false;
331
            } elseif (!empty($line) && $line[0] === '*') {
332
                $property = false;
333
            } elseif (!empty($line) && $line[0] !== '*' && strpos($line, 'function ') !== false || $line === '}') {
334 335
                break;
            }
336

337
            // check for multi line array
338
            if ($property !== false && strncmp($line, "'SQLSTATE[", 10) !== 0) {
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
                $level += substr_count($line, '[') - substr_count($line, ']');
            }
        }

        $endofAll = false;
        foreach(['Private', 'Protected', 'Public', 'Const', 'Use'] as $var) {
            if (${'endof'.$var} !== false) {
                $endofAll = ${'endof'.$var};
                break;
            }
        }

//        $this->checkPropertyOrder($lineInfo);
        $result = [];
        foreach($lines as $i => $line) {
            $result[] = $line;
            if (!($propertiesOnly && $i === $endofAll)) {
                if ($i === $endofUse || $i === $endofConst || $i === $endofPublic ||
                    $i === $endofProtected || $i === $endofPrivate) {
                    $result[] = '';
                }
                if ($i === $endofAll) {
                    $result[] = '';
                }
            }
        }

        return $result;
    }

    protected function checkPropertyOrder($lineInfo)
    {
        // TODO
    }

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
    protected function updateClassPropertyDocs($file, $className, $propertyDoc)
    {
        $ref = new \ReflectionClass($className);
        if ($ref->getFileName() != $file) {
            $this->stderr("[ERR] Unable to create ReflectionClass for class: $className loaded class is not from file: $file\n", Console::FG_RED);
        }

        if (!$ref->isSubclassOf('yii\base\Object') && $className != 'yii\base\Object') {
            $this->stderr("[INFO] Skipping class $className as it is not a subclass of yii\\base\\Object.\n", Console::FG_BLUE, Console::BOLD);

            return false;
        }

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

        $seenSince = false;
        $seenAuthor = false;

        // TODO move these checks to different action
        $lines = explode("\n", $newDoc);
395
        $firstLine = trim($lines[1]);
396
        if ($firstLine === '*' || strncmp($firstLine, '* @', 3) === 0) {
397 398 399
            $this->stderr("[WARN] Class $className has no short description.\n", Console::FG_YELLOW, Console::BOLD);
        }
        foreach ($lines as $line) {
400
            $line = trim($line);
401 402 403 404
            if (strncmp($line, '* @since ', 9) === 0) {
                $seenSince = true;
            } elseif (strncmp($line, '* @author ', 10) === 0) {
                $seenAuthor = true;
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
            }
        }

        if (!$seenSince) {
            $this->stderr("[ERR] No @since found in class doc in file: $file\n", Console::FG_RED);
        }
        if (!$seenAuthor) {
            $this->stderr("[ERR] No @author found in class doc in file: $file\n", Console::FG_RED);
        }

        if (trim($oldDoc) != trim($newDoc)) {

            $fileContent = explode("\n", file_get_contents($file));
            $start = $ref->getStartLine() - 2;
            $docStart = $start - count(explode("\n", $oldDoc)) + 1;

            $newFileContent = [];
            $n = count($fileContent);
            for ($i = 0; $i < $n; $i++) {
                if ($i > $start || $i < $docStart) {
                    $newFileContent[] = $fileContent[$i];
                } else {
                    $newFileContent[] = trim($newDoc);
                    $i = $start;
                }
            }

            file_put_contents($file, implode("\n", $newFileContent));

            return true;
        }

        return false;
    }

    /**
     * remove multi empty lines and trim trailing whitespace
     *
     * @param $doc
     * @return string
     */
    protected function cleanDocComment($doc)
    {
        $lines = explode("\n", $doc);
        $n = count($lines);
        for ($i = 0; $i < $n; $i++) {
            $lines[$i] = rtrim($lines[$i]);
            if (trim($lines[$i]) == '*' && trim($lines[$i + 1]) == '*') {
                unset($lines[$i]);
            }
        }

        return implode("\n", $lines);
    }

    /**
     * Replace property annotations in doc comment
     * @param $doc
     * @param $properties
     * @return string
     */
    protected function updateDocComment($doc, $properties)
    {
        $lines = explode("\n", $doc);
        $propertyPart = false;
        $propertyPosition = false;
        foreach ($lines as $i => $line) {
472
            $line = trim($line);
473
            if (strncmp($line, '* @property ', 12) === 0) {
474
                $propertyPart = true;
475
            } elseif ($propertyPart && $line == '*') {
476 477 478
                $propertyPosition = $i;
                $propertyPart = false;
            }
479
            if (strncmp($line, '* @author ', 10) === 0 && $propertyPosition === false) {
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
                $propertyPosition = $i - 1;
                $propertyPart = false;
            }
            if ($propertyPart) {
                unset($lines[$i]);
            }
        }
        $finalDoc = '';
        foreach ($lines as $i => $line) {
            $finalDoc .= $line . "\n";
            if ($i == $propertyPosition) {
                $finalDoc .= $properties;
            }
        }

        return $finalDoc;
    }

    protected function generateClassPropertyDocs($fileName)
    {
        $phpdoc = "";
        $file = str_replace("\r", "", str_replace("\t", " ", file_get_contents($fileName, true)));
        $ns = $this->match('#\nnamespace (?<name>[\w\\\\]+);\n#', $file);
        $namespace = reset($ns);
        $namespace = $namespace['name'];
        $classes = $this->match('#\n(?:abstract )?class (?<name>\w+)( extends .+)?( implements .+)?\n\{(?<content>.*)\n\}(\n|$)#', $file);

        if (count($classes) > 1) {
            $this->stderr("[ERR] There should be only one class in a file: $fileName\n", Console::FG_RED);

            return false;
        }
        if (count($classes) < 1) {
            $interfaces = $this->match('#\ninterface (?<name>\w+)( extends .+)?\n\{(?<content>.+)\n\}(\n|$)#', $file);
            if (count($interfaces) == 1) {
                return false;
            } elseif (count($interfaces) > 1) {
                $this->stderr("[ERR] There should be only one interface in a file: $fileName\n", Console::FG_RED);
            } else {
                $traits = $this->match('#\ntrait (?<name>\w+)\n\{(?<content>.+)\n\}(\n|$)#', $file);
                if (count($traits) == 1) {
                    return false;
                } elseif (count($traits) > 1) {
                    $this->stderr("[ERR] There should be only one class/trait/interface in a file: $fileName\n", Console::FG_RED);
                } else {
                    $this->stderr("[ERR] No class in file: $fileName\n", Console::FG_RED);
                }
            }

            return false;
        }

        $className = null;
        foreach ($classes as &$class) {

            $className = $namespace . '\\' . $class['name'];

            $gets = $this->match(
                '#\* @return (?<type>[\w\\|\\\\\\[\\]]+)(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/' .
                '[\s\n]{2,}public function (?<kind>get)(?<name>\w+)\((?:,? ?\$\w+ ?= ?[^,]+)*\)#',
540
                $class['content'], true);
541 542 543
            $sets = $this->match(
                '#\* @param (?<type>[\w\\|\\\\\\[\\]]+) \$\w+(?: (?<comment>(?:(?!\*/|\* @).)+?)(?:(?!\*/).)+|[\s\n]*)\*/' .
                '[\s\n]{2,}public function (?<kind>set)(?<name>\w+)\(\$\w+(?:, ?\$\w+ ?= ?[^,]+)*\)#',
544
                $class['content'], true);
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
            // 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+ ?= ?[^,]+)*)\)#',
                $class['content']);
            $acrs = array_merge($properties, $gets, $sets);

            $props = [];
            foreach ($acrs as &$acr) {
                $acr['name'] = lcfirst($acr['name']);
                $acr['comment'] = trim(preg_replace('#(^|\n)\s+\*\s?#', '$1 * ', $acr['comment']));
                $props[$acr['name']][$acr['kind']] = [
                    'type' => $acr['type'],
                    'comment' => $this->fixSentence($acr['comment']),
                ];
            }

            ksort($props);

            if (count($props) > 0) {
                $phpdoc .= " *\n";
                foreach ($props as $propName => &$prop) {
                    $docline = ' * @';
                    $docline .= 'property'; // Do not use property-read and property-write as few IDEs support complex syntax.
                    $note = '';
                    if (isset($prop['get']) && isset($prop['set'])) {
                        if ($prop['get']['type'] != $prop['set']['type']) {
                            $note = ' Note that the type of this property differs in getter and setter.'
                                  . ' See [[get' . ucfirst($propName) . '()]] and [[set' . ucfirst($propName) . '()]] for details.';
                        }
                    } elseif (isset($prop['get'])) {
                        // check if parent class has setter defined
                        $c = $className;
                        $parentSetter = false;
                        while ($parent = get_parent_class($c)) {
                            if (method_exists($parent, 'set' . ucfirst($propName))) {
                                $parentSetter = true;
                                break;
                            }
                            $c = $parent;
                        }
                        if (!$parentSetter) {
                            $note = ' This property is read-only.';
588
//							$docline .= '-read';
589 590 591 592 593 594 595 596 597 598 599 600 601 602
                        }
                    } elseif (isset($prop['set'])) {
                        // check if parent class has getter defined
                        $c = $className;
                        $parentGetter = false;
                        while ($parent = get_parent_class($c)) {
                            if (method_exists($parent, 'set' . ucfirst($propName))) {
                                $parentGetter = true;
                                break;
                            }
                            $c = $parent;
                        }
                        if (!$parentGetter) {
                            $note = ' This property is write-only.';
603
//							$docline .= '-write';
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
                        }
                    } else {
                        continue;
                    }
                    $docline .= ' ' . $this->getPropParam($prop, 'type') . " $$propName ";
                    $comment = explode("\n", $this->getPropParam($prop, 'comment') . $note);
                    foreach ($comment as &$cline) {
                        $cline = ltrim($cline, '* ');
                    }
                    $docline = wordwrap($docline . implode(' ', $comment), 110, "\n * ") . "\n";

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

        return [$className, $phpdoc];
    }

624
    protected function match($pattern, $subject, $split = false)
625 626
    {
        $sets = [];
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
        // split subject by double newlines because regex sometimes has problems with matching
        // in the complete set of methods
        // example: yii\di\ServiceLocator setComponents() is not recognized in the whole but in
        // a part of the class.
        $parts = $split ? explode("\n\n", $subject) : [$subject];
        foreach($parts as $part) {
            preg_match_all($pattern . 'suU', $part, $matches, PREG_SET_ORDER);
            foreach ($matches as &$set) {
                foreach ($set as $i => $match)
                    if (is_numeric($i) /*&& $i != 0*/)
                        unset($set[$i]);

                $sets[] = $set;
            }
        }
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
        return $sets;
    }

    protected function fixSentence($str)
    {
        // TODO fix word wrap
        if ($str == '')
            return '';
        return strtoupper(substr($str, 0, 1)) . substr($str, 1) . ($str[strlen($str) - 1] != '.' ? '.' : '');
    }

    protected function getPropParam($prop, $param)
    {
        return isset($prop['property']) ? $prop['property'][$param] : (isset($prop['get']) ? $prop['get'][$param] : $prop['set'][$param]);
    }
Qiang Xue committed
657
}