本文整理汇总了PHP中Phan\Issue类的典型用法代码示例。如果您正苦于以下问题:PHP Issue类的具体用法?PHP Issue怎么用?PHP Issue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Issue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: analyzeDuplicateClass
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzeDuplicateClass(CodeBase $code_base, Clazz $clazz)
{
// Determine if its a duplicate by looking to see if
// the FQSEN is suffixed with an alternate ID.
if (!$clazz->getFQSEN()->isAlternate()) {
return;
}
$original_fqsen = $clazz->getFQSEN()->getCanonicalFQSEN();
if (!$code_base->hasClassWithFQSEN($original_fqsen)) {
// If there's a missing class we'll catch that
// elsewhere
return;
}
// Get the original class
$original_class = $code_base->getClassByFQSEN($original_fqsen);
// Check to see if the original definition was from
// an internal class
if ($original_class->isInternal()) {
Issue::emit(Issue::RedefineClassInternal, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $clazz, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $original_class);
// Otherwise, print the coordinates of the original
// definition
} else {
Issue::emit(Issue::RedefineClass, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $clazz, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $original_class, $original_class->getContext()->getFile(), $original_class->getContext()->getLineNumberStart());
}
return;
}
示例2: analyzeDuplicateFunction
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzeDuplicateFunction(CodeBase $code_base, FunctionInterface $method)
{
$fqsen = $method->getFQSEN();
if (!$fqsen->isAlternate()) {
return;
}
$original_fqsen = $fqsen->getCanonicalFQSEN();
if ($original_fqsen instanceof FullyQualifiedFunctionName) {
if (!$code_base->hasFunctionWithFQSEN($original_fqsen)) {
return;
}
$original_method = $code_base->getFunctionByFQSEN($original_fqsen);
} else {
if (!$code_base->hasMethodWithFQSEN($original_fqsen)) {
return;
}
$original_method = $code_base->getMethodByFQSEN($original_fqsen);
}
$method_name = $method->getName();
if (!$method->hasSuppressIssue(Issue::RedefineFunction)) {
if ($original_method->isInternal()) {
Issue::maybeEmit($code_base, $method->getContext(), Issue::RedefineFunctionInternal, $method->getFileRef()->getLineNumberStart(), $method_name, $method->getFileRef()->getFile(), $method->getFileRef()->getLineNumberStart());
} else {
Issue::maybeEmit($code_base, $method->getContext(), Issue::RedefineFunction, $method->getFileRef()->getLineNumberStart(), $method_name, $method->getFileRef()->getFile(), $method->getFileRef()->getLineNumberStart(), $original_method->getFileRef()->getFile(), $original_method->getFileRef()->getLineNumberStart());
}
}
}
示例3: analyzeParentConstructorCalled
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzeParentConstructorCalled(CodeBase $code_base, Clazz $clazz)
{
// Only look at classes configured to require a call
// to its parent constructor
if (!in_array($clazz->getName(), Config::get()->parent_constructor_required)) {
return;
}
// Don't worry about internal classes
if ($clazz->isInternal()) {
return;
}
// Don't worry if there's no parent class
if (!$clazz->hasParentClassFQSEN()) {
return;
}
if (!$code_base->hasClassWithFQSEN($clazz->getParentClassFQSEN())) {
// This is an error, but its caught elsewhere. We'll
// just roll through looking for other errors
return;
}
$parent_clazz = $code_base->getClassByFQSEN($clazz->getParentClassFQSEN());
if (!$parent_clazz->isAbstract() && !$clazz->getIsParentConstructorCalled()) {
Issue::emit(Issue::TypeParentConstructorCalled, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $clazz->getFQSEN(), (string) $parent_clazz->getFQSEN());
}
}
示例4: analyzePropertyTypes
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzePropertyTypes(CodeBase $code_base, Clazz $clazz)
{
foreach ($clazz->getPropertyList($code_base) as $property) {
try {
$union_type = $property->getUnionType();
} catch (IssueException $exception) {
Issue::maybeEmitInstance($code_base, $property->getContext(), $exception->getIssueInstance());
continue;
}
// Look at each type in the parameter's Union Type
foreach ($union_type->getTypeSet() as $type) {
// If its a native type or a reference to
// self, its OK
if ($type->isNativeType() || $type->isSelfType()) {
continue;
}
if ($type instanceof TemplateType) {
if ($property->isStatic()) {
Issue::maybeEmit($code_base, $property->getContext(), Issue::TemplateTypeStaticProperty, $property->getFileRef()->getLineNumberStart(), (string) $property->getFQSEN());
}
} else {
// Make sure the class exists
$type_fqsen = $type->asFQSEN();
if (!$code_base->hasClassWithFQSEN($type_fqsen) && !$type instanceof TemplateType && (!$property->hasDefiningFQSEN() || $property->getDefiningFQSEN() == $property->getFQSEN())) {
Issue::maybeEmit($code_base, $property->getContext(), Issue::UndeclaredTypeProperty, $property->getFileRef()->getLineNumberStart(), (string) $property->getFQSEN(), (string) $type_fqsen);
}
}
}
}
}
示例5: testUTF8CharactersDoNotCauseDOMAttrToFail
/**
* @param string $string String to check against
*
* @dataProvider invalidUTF8StringsProvider
*/
public function testUTF8CharactersDoNotCauseDOMAttrToFail($string)
{
$output = new BufferedOutput();
$printer = new CheckstylePrinter();
$printer->configureOutput($output);
$printer->print(new IssueInstance(Issue::fromType(Issue::SyntaxError), 'test.php', 0, [$string]));
$printer->flush();
}
示例6: fqsenExistsForClass
/**
* @return bool
* True if the FQSEN exists. If not, a log line is emitted
*/
private static function fqsenExistsForClass(FQSEN $fqsen, CodeBase $code_base, Clazz $clazz, string $issue_type) : bool
{
if (!$code_base->hasClassWithFQSEN($fqsen)) {
Issue::maybeEmit($code_base, $clazz->getContext(), $issue_type, $clazz->getFileRef()->getLineNumberStart(), (string) $fqsen);
return false;
}
return true;
}
示例7: testSpecialCharactersAreProperlyEncoded
/**
* @param string $string String to check against
* @param string $messageExpected Message component of expected CSV line
*
* @dataProvider specialCharacterCasesProvider
*/
public function testSpecialCharactersAreProperlyEncoded($string, $messageExpected)
{
$output = new BufferedOutput();
$printer = new CSVPrinter();
$printer->configureOutput($output);
$printer->print(new IssueInstance(Issue::fromType(Issue::SyntaxError), 'test.php', 0, [$string]));
$printer->flush();
$expected = 'test.php,0,10,critical,UndefError,PhanSyntaxError,' . $messageExpected;
$actual = explode("\n", $output->fetch())[1];
// Ignore header
$this->assertEquals($expected, $actual);
}
示例8: analyzeDuplicateFunction
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzeDuplicateFunction(CodeBase $code_base, FunctionInterface $method)
{
$fqsen = $method->getFQSEN();
if (!$fqsen->isAlternate()) {
return;
}
$original_fqsen = $fqsen->getCanonicalFQSEN();
if (!$code_base->hasMethod($original_fqsen)) {
return;
}
$original_method = $code_base->getMethod($original_fqsen);
$method_name = $method->getName();
if ($original_method->isInternal()) {
Issue::emit(Issue::RedefineFunctionInternal, $method->getFileRef()->getFile(), $method->getFileRef()->getLineNumberStart(), $method_name, $method->getFileRef()->getFile(), $method->getFileRef()->getLineNumberStart());
} else {
Issue::emit(Issue::RedefineFunction, $method->getFileRef()->getFile(), $method->getFileRef()->getLineNumberStart(), $method_name, $method->getFileRef()->getFile(), $method->getFileRef()->getLineNumberStart(), $original_method->getFileRef()->getFile(), $original_method->getFileRef()->getLineNumberStart());
}
}
示例9: analyzePropertyTypes
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzePropertyTypes(CodeBase $code_base, Clazz $clazz)
{
foreach ($clazz->getPropertyList($code_base) as $property) {
$union_type = $property->getUnionType();
// Look at each type in the parameter's Union Type
foreach ($union_type->getTypeSet() as $type) {
// If its a native type or a reference to
// self, its OK
if ($type->isNativeType() || $type->isSelfType()) {
continue;
}
// Otherwise, make sure the class exists
$type_fqsen = $type->asFQSEN();
if (!$code_base->hasClassWithFQSEN($type_fqsen)) {
Issue::emit(Issue::UndeclaredTypeProperty, $property->getContext()->getFile(), $property->getContext()->getLineNumberStart(), (string) $type_fqsen);
}
}
}
}
示例10: analyzeParameterTypes
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzeParameterTypes(CodeBase $code_base, FunctionInterface $method)
{
// Look at each method parameter
foreach ($method->getParameterList() as $parameter) {
$union_type = $parameter->getUnionType();
// Look at each type in the parameter's Union Type
foreach ($union_type->getTypeSet() as $type) {
// If its a native type or a reference to
// self, its OK
if ($type->isNativeType() || $type->isSelfType()) {
continue;
}
// Otherwise, make sure the class exists
$type_fqsen = $type->asFQSEN();
if (!$code_base->hasClassWithFQSEN($type_fqsen)) {
Issue::emit(Issue::UndeclaredTypeParameter, $method->getFileRef()->getFile(), $method->getFileRef()->getLineNumberStart(), (string) $type_fqsen);
}
}
}
}
示例11: classListFromNode
/**
* @return Clazz[]
* A list of classes associated with the given node
*
* @throws IssueException
* An exception is thrown if we can't find a class for
* the given type
*/
private function classListFromNode(Node $node)
{
// Get the types associated with the node
$union_type = self::unionTypeFromNode($this->code_base, $this->context, $node);
// Iterate over each viable class type to see if any
// have the constant we're looking for
foreach ($union_type->nonNativeTypes()->getTypeSet() as $class_type) {
// Get the class FQSEN
$class_fqsen = $class_type->asFQSEN();
// See if the class exists
if (!$this->code_base->hasClassWithFQSEN($class_fqsen)) {
throw new IssueException(Issue::fromType(Issue::UndeclaredClassReference)($this->context->getFile(), $node->lineno ?? 0, [(string) $class_fqsen]));
}
(yield $this->code_base->getClassByFQSEN($class_fqsen));
}
}
示例12: visitProp
/**
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitProp(Node $node) : Context
{
$property_name = $node->children['prop'];
// Things like $foo->$bar
if (!is_string($property_name)) {
return $this->context;
}
assert(is_string($property_name), "Property must be string in context {$this->context}");
try {
$class_list = (new ContextNode($this->code_base, $this->context, $node->children['expr']))->getClassList();
} catch (CodeBaseException $exception) {
// This really shouldn't happen since the code
// parsed cleanly. This should fatal.
// throw $exception;
return $this->context;
} catch (\Exception $exception) {
// If we can't figure out what kind of a class
// this is, don't worry about it
return $this->context;
}
foreach ($class_list as $clazz) {
// Check to see if this class has the property or
// a setter
if (!$clazz->hasPropertyWithName($this->code_base, $property_name)) {
if (!$clazz->hasMethodWithName($this->code_base, '__set')) {
continue;
}
}
try {
$property = $clazz->getPropertyByNameInContext($this->code_base, $property_name, $this->context);
} catch (IssueException $exception) {
Issue::maybeEmitInstance($this->code_base, $this->context, $exception->getIssueInstance());
return $this->context;
}
if (!$this->right_type->canCastToExpandedUnionType($property->getUnionType(), $this->code_base)) {
$this->emitIssue(Issue::TypeMismatchProperty, $node->lineno ?? 0, (string) $this->right_type, "{$clazz->getFQSEN()}::{$property->getName()}", (string) $property->getUnionType());
return $this->context;
}
// After having checked it, add this type to it
$property->getUnionType()->addUnionType($this->right_type);
return $this->context;
}
if (Config::get()->allow_missing_properties) {
try {
// Create the property
(new ContextNode($this->code_base, $this->context, $node))->getOrCreateProperty($property_name);
} catch (\Exception $exception) {
// swallow it
}
} elseif (!empty($class_list)) {
$this->emitIssue(Issue::UndeclaredProperty, $node->lineno ?? 0, $property_name);
} else {
// If we hit this part, we couldn't figure out
// the class, so we ignore the issue
}
return $this->context;
}
示例13: analyzeFile
/**
* Once we know what the universe looks like we
* can scan for more complicated issues.
*
* @param CodeBase $code_base
* The global code base holding all state
*
* @param string $file_path
* A list of files to scan
*
* @return Context
*/
public static function analyzeFile(CodeBase $code_base, string $file_path) : Context
{
// Set the file on the context
$context = (new Context())->withFile($file_path);
// Convert the file to an Abstract Syntax Tree
// before passing it on to the recursive version
// of this method
try {
$node = \ast\parse_file($file_path, Config::get()->ast_version);
} catch (\ParseError $parse_error) {
Issue::maybeEmit($code_base, $context, Issue::SyntaxError, $parse_error->getLine(), $parse_error->getMessage());
return $context;
}
// Ensure we have some content
if (empty($node)) {
Issue::maybeEmit($code_base, $context, Issue::EmptyFile, 0, $file_path);
return $context;
}
// Whenever we enter a file, we copy all global scope
// variables to the local scope
$context->getScope()->copyGlobalToLocal();
// Start recursively analyzing the tree
return self::analyzeNodeInContext($code_base, $context, $node);
}
示例14: analyzeFile
/**
* Once we know what the universe looks like we
* can scan for more complicated issues.
*
* @param CodeBase $code_base
* The global code base holding all state
*
* @param string $file_path
* A list of files to scan
*
* @return Context
*/
public static function analyzeFile(CodeBase $code_base, string $file_path) : Context
{
// Convert the file to an Abstract Syntax Tree
// before passing it on to the recursive version
// of this method
$node = \ast\parse_file($file_path, Config::get()->ast_version);
// Set the file on the context
$context = (new Context())->withFile($file_path);
// Ensure we have some content
if (empty($node)) {
Issue::emit(Issue::EmptyFile, $file_path, 0, $file_path);
return $context;
}
// Start recursively analyzing the tree
return self::analyzeNodeInContext($code_base, $context, $node);
}
示例15: analyzeBackwardCompatibility
/**
* Perform some backwards compatibility checks on a node
*
* @return void
*/
public function analyzeBackwardCompatibility()
{
if (!Config::get()->backward_compatibility_checks) {
return;
}
if (empty($this->node->children['expr'])) {
return;
}
if ($this->node->kind === \ast\AST_STATIC_CALL || $this->node->kind === \ast\AST_METHOD_CALL) {
return;
}
$llnode = $this->node;
if ($this->node->kind !== \ast\AST_DIM) {
if (!$this->node->children['expr'] instanceof Node) {
return;
}
if ($this->node->children['expr']->kind !== \ast\AST_DIM) {
(new ContextNode($this->code_base, $this->context, $this->node->children['expr']))->analyzeBackwardCompatibility();
return;
}
$temp = $this->node->children['expr']->children['expr'];
$llnode = $this->node->children['expr'];
$lnode = $temp;
} else {
$temp = $this->node->children['expr'];
$lnode = $temp;
}
if (!($temp->kind == \ast\AST_PROP || $temp->kind == \ast\AST_STATIC_PROP)) {
return;
}
while ($temp instanceof Node && ($temp->kind == \ast\AST_PROP || $temp->kind == \ast\AST_STATIC_PROP)) {
$llnode = $lnode;
$lnode = $temp;
// Lets just hope the 0th is the expression
// we want
$temp = array_values($temp->children)[0];
}
if (!$temp instanceof Node) {
return;
}
// Foo::$bar['baz'](); is a problem
// Foo::$bar['baz'] is not
if ($lnode->kind === \ast\AST_STATIC_PROP && $this->node->kind !== \ast\AST_CALL) {
return;
}
// $this->$bar['baz']; is a problem
// $this->bar['baz'] is not
if ($lnode->kind === \ast\AST_PROP && !$lnode->children['prop'] instanceof Node && !$llnode->children['prop'] instanceof Node) {
return;
}
if (($lnode->children['prop'] instanceof Node && $lnode->children['prop']->kind == \ast\AST_VAR || !empty($lnode->children['class']) && $lnode->children['class'] instanceof Node && ($lnode->children['class']->kind == \ast\AST_VAR || $lnode->children['class']->kind == \ast\AST_NAME) || !empty($lnode->children['expr']) && $lnode->children['expr'] instanceof Node && ($lnode->children['expr']->kind == \ast\AST_VAR || $lnode->children['expr']->kind == \ast\AST_NAME)) && ($temp->kind == \ast\AST_VAR || $temp->kind == \ast\AST_NAME)) {
$ftemp = new \SplFileObject($this->context->getFile());
$ftemp->seek($this->node->lineno - 1);
$line = $ftemp->current();
unset($ftemp);
if (strpos($line, '}[') === false || strpos($line, ']}') === false || strpos($line, '>{') === false) {
Issue::maybeEmit($this->code_base, $this->context, Issue::CompatiblePHP7, $this->node->lineno ?? 0);
}
}
}