Browse Source

Build command phpdoc fixer is now compatible with PHP 7.2+

tags/2.0.17
Alexander Makarov 6 years ago
parent
commit
a3f4e855b4
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A
  1. 82
      build/controllers/PhpDocController.php

82
build/controllers/PhpDocController.php

@ -515,7 +515,7 @@ class PhpDocController extends Controller
return false; return false;
} }
if (!$ref->isSubclassOf('yii\base\Object') && $className != 'yii\base\Object' && !$ref->isSubclassOf('yii\base\BaseObject') && $className != 'yii\base\BaseObject') { if ($this->isBaseObject($className, $ref)) {
$this->stderr("[INFO] Skipping class $className as it is not a subclass of yii\\base\\BaseObject.\n", Console::FG_BLUE, Console::BOLD); $this->stderr("[INFO] Skipping class $className as it is not a subclass of yii\\base\\BaseObject.\n", Console::FG_BLUE, Console::BOLD);
return false; return false;
} }
@ -661,13 +661,17 @@ class PhpDocController extends Controller
$interfaces = $this->match('#\ninterface (?<name>\w+)( extends .+)?\n\{(?<content>.*)\n\}(\n|$)#', $file); $interfaces = $this->match('#\ninterface (?<name>\w+)( extends .+)?\n\{(?<content>.*)\n\}(\n|$)#', $file);
if (\count($interfaces) == 1) { if (\count($interfaces) == 1) {
return false; return false;
} elseif (\count($interfaces) > 1) { }
if (\count($interfaces) > 1) {
$this->stderr("[ERR] There should be only one interface in a file: $fileName\n", Console::FG_RED); $this->stderr("[ERR] There should be only one interface in a file: $fileName\n", Console::FG_RED);
} else { } else {
$traits = $this->match('#\ntrait (?<name>\w+)\n\{(?<content>.*)\n\}(\n|$)#', $file); $traits = $this->match('#\ntrait (?<name>\w+)\n\{(?<content>.*)\n\}(\n|$)#', $file);
if (\count($traits) == 1) { if (\count($traits) == 1) {
return false; return false;
} elseif (\count($traits) > 1) { }
if (\count($traits) > 1) {
$this->stderr("[ERR] There should be only one class/trait/interface in a file: $fileName\n", Console::FG_RED); $this->stderr("[ERR] There should be only one class/trait/interface in a file: $fileName\n", Console::FG_RED);
} else { } else {
$this->stderr("[ERR] No class in file: $fileName\n", Console::FG_RED); $this->stderr("[ERR] No class in file: $fileName\n", Console::FG_RED);
@ -720,32 +724,12 @@ class PhpDocController extends Controller
. ' See [[get' . ucfirst($propName) . '()]] and [[set' . ucfirst($propName) . '()]] for details.'; . ' See [[get' . ucfirst($propName) . '()]] and [[set' . ucfirst($propName) . '()]] for details.';
} }
} elseif (isset($prop['get'])) { } elseif (isset($prop['get'])) {
// check if parent class has setter defined if (!$this->hasSetterInParents($className, $propName)) {
$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.'; $note = ' This property is read-only.';
//$docline .= '-read'; //$docline .= '-read';
} }
} elseif (isset($prop['set'])) { } elseif (isset($prop['set'])) {
// check if parent class has getter defined if (!$this->hasGetterInParents($className, $propName)) {
$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.'; $note = ' This property is write-only.';
//$docline .= '-write'; //$docline .= '-write';
} }
@ -819,4 +803,52 @@ class PhpDocController extends Controller
} }
return hash('sha256', $string); return hash('sha256', $string);
} }
/**
* @param string $className
* @param string $propName
* @return bool
*/
protected function hasGetterInParents($className, $propName)
{
$class = $className;
while ($parent = get_parent_class($class)) {
if (method_exists($parent, 'get' . ucfirst($propName))) {
return true;
}
$class = $parent;
}
return false;
}
/**
* @param string $className
* @param string $propName
* @return bool
*/
protected function hasSetterInParents($className, $propName)
{
$class = $className;
while ($parent = get_parent_class($class)) {
if (method_exists($parent, 'set' . ucfirst($propName))) {
return true;
}
$class = $parent;
}
return false;
}
/**
* @param string $className
* @param \ReflectionClass $ref
* @return bool
*/
protected function isBaseObject($className, \ReflectionClass $ref)
{
$isDepreceatedObject = false;
if (PHP_VERSION_ID <= 70100) {
$isDepreceatedObject = $ref->isSubclassOf('yii\base\Object') || $className === 'yii\base\Object';
}
return !$isDepreceatedObject && !$ref->isSubclassOf('yii\base\BaseObject') && $className !== 'yii\base\BaseObject';
}
} }

Loading…
Cancel
Save