1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-14 18:36:58 +01:00
psalm/src/Psalm/Checker/TraitChecker.php

86 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Checker;
use PhpParser;
use Psalm\StatementsSource;
use Psalm\Context;
class TraitChecker extends ClassLikeChecker
{
2016-11-02 07:29:00 +01:00
/**
* @var array<string, string>
*/
2016-11-01 05:39:41 +01:00
protected $method_map = [];
2016-08-15 20:20:06 +02:00
2016-11-02 07:29:00 +01:00
/**
2016-11-05 02:14:04 +01:00
* @param PhpParser\Node\Stmt\ClassLike $class
* @param StatementsSource $source
* @param string $fq_class_name
2016-11-02 07:29:00 +01:00
*/
public function __construct(PhpParser\Node\Stmt\ClassLike $class, StatementsSource $source, $fq_class_name)
{
2016-11-05 02:14:04 +01:00
if (!$class instanceof PhpParser\Node\Stmt\Trait_) {
throw new \InvalidArgumentException('Trait checker must be passed a trait');
}
$this->class = $class;
$this->namespace = $source->getNamespace();
$this->aliased_classes = $source->getAliasedClasses();
$this->file_name = $source->getFileName();
$this->file_path = $source->getFilePath();
$this->fq_class_name = $fq_class_name;
$this->parent_class = null;
$this->suppressed_issues = $source->getSuppressedIssues();
2016-08-08 20:36:18 +02:00
self::$class_checkers[$fq_class_name] = $this;
2016-08-08 20:36:18 +02:00
}
2016-11-02 07:29:00 +01:00
/**
* @param bool $check_methods
* @param Context|null $class_context
2016-11-21 19:37:27 +01:00
* @param bool $update_docblocks
2016-11-02 07:29:00 +01:00
* @return void
*/
2016-11-13 00:51:48 +01:00
public function check($check_methods = true, Context $class_context = null, $update_docblocks = false)
2016-08-08 20:36:18 +02:00
{
if (!$class_context) {
throw new \InvalidArgumentException('TraitChecker::check must be called with a $class_context');
}
2016-08-08 20:36:18 +02:00
parent::check($check_methods, $class_context);
}
2016-08-15 20:20:06 +02:00
2016-11-02 07:29:00 +01:00
/**
* @param array $method_map
* @return void
*/
2016-08-15 20:20:06 +02:00
public function setMethodMap(array $method_map)
{
$this->method_map = $method_map;
}
2016-11-01 05:39:41 +01:00
/**
* @param string $method_name
* @return string
*/
2016-08-15 20:20:06 +02:00
protected function getMappedMethodName($method_name)
{
if (isset($this->method_map[$method_name])) {
return $this->method_map[$method_name];
}
return $method_name;
}
2016-10-30 17:46:18 +01:00
/**
* @param string $trait_name
* @return boolean
*/
public static function traitExists($trait_name)
{
return trait_exists($trait_name);
}
}