View source
<?php
namespace Drupal\drupalmoduleupgrader;
use Drupal\Core\Plugin\PluginBase as CorePluginBase;
use Pharborist\NodeInterface;
abstract class FixerBase extends CorePluginBase implements FixerInterface {
protected $target;
public function setTarget(TargetInterface $target) {
$this->target = $target;
}
protected function getUnaliasedPath($path) {
return preg_replace('/^~/', $this->target
->getBasePath(), $path);
}
protected function usesTrait($trait, NodeInterface $node) {
$hierarchy = class_parents($node);
array_unshift($hierarchy, get_class($node));
$traits = [];
foreach ($hierarchy as $parent) {
$this
->collectTraits($parent, $traits);
}
return in_array($trait, $traits);
}
private function collectTraits($class, array &$all_traits = []) {
$traits = class_uses($class);
foreach ($traits as $trait) {
$this
->collectTraits($trait, $traits);
}
$all_traits += $traits;
}
}