本文整理汇总了PHP中Phan\Log::err方法的典型用法代码示例。如果您正苦于以下问题:PHP Log::err方法的具体用法?PHP Log::err怎么用?PHP Log::err使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phan\Log
的用法示例。
在下文中一共展示了Log::err方法的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()) {
Log::err(Log::EREDEF, "{$clazz} defined at " . "{$clazz->getContext()->getFile()}:{$clazz->getContext()->getLineNumberStart()} " . "was previously defined as {$original_class} internally", $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart());
// Otherwise, print the coordinates of the original
// definition
} else {
Log::err(Log::EREDEF, "{$clazz} defined at " . "{$clazz->getContext()->getFile()}:{$clazz->getContext()->getLineNumberStart()} " . "was previously defined as {$original_class} at " . "{$original_class->getContext()->getFile()}:{$original_class->getContext()->getLineNumberStart()}", $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart());
}
return;
}
示例2: 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()) {
Log::err(Log::ETYPE, "{$clazz->getFQSEN()} extends {$parent_clazz->getFQSEN()} but doesn't call parent::__construct()", $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart());
}
}
示例3: 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 $message_template) : bool
{
if (!$code_base->hasClassWithFQSEN($fqsen)) {
Log::err(Log::EUNDEF, sprintf($message_template, $fqsen), $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart());
return false;
}
return true;
}
示例4: 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) : bool
{
if (!$code_base->hasClassWithFQSEN($fqsen)) {
Log::err(Log::EUNDEF, "Trying to inherit from unknown class {$fqsen}", $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart());
return false;
}
return true;
}
示例5: 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->getTypeList() 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)) {
Log::err(Log::EUNDEF, "property of undeclared type {$type_fqsen}", $property->getContext()->getFile(), $property->getContext()->getLineNumberStart());
}
}
}
}
示例6: analyzeDuplicateFunction
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzeDuplicateFunction(CodeBase $code_base, Method $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 ('internal' === $original_method->getContext()->getFile()) {
// If its in an conditional and the original is an
// internal method, presume its all OK.
if ($method->getContext()->getIsConditional()) {
return;
}
Log::err(Log::EREDEF, "Function {$method_name} defined at {$method->getContext()->getFile()}:{$method->getContext()->getLineNumberStart()} was previously defined internally", $method->getContext()->getFile(), $method->getContext()->getLineNumberStart());
} else {
Log::err(Log::EREDEF, "Function {$method_name} defined at {$method->getContext()->getFile()}:{$method->getContext()->getLineNumberStart()} was previously defined at {$original_method->getContext()->getFile()}:{$original_method->getContext()->getLineNumberStart()}", $method->getContext()->getFile(), $method->getContext()->getLineNumberStart());
}
}
示例7: visitNew
/**
* @param Node $node
* A node of the type indicated by the method name that we'd
* like to figure out the type that it produces.
*
* @return string
* The class name represented by the given call
*/
public function visitNew(Node $node) : string
{
// Things of the form `new $class_name();`
if ($node->children['class']->kind == \ast\AST_VAR) {
return '';
}
// Things of the form `new $method->name()`
if ($node->children['class']->kind !== \ast\AST_NAME) {
return '';
}
$class_name = $node->children['class']->children['name'];
if (!in_array($class_name, ['self', 'static', 'parent'])) {
return AST::qualifiedName($this->context, $node->children['class']);
}
if (!$this->context->isInClassScope()) {
Log::err(Log::ESTATIC, "Cannot access {$class_name}:: when no class scope is active", $this->context->getFile(), $node->lineno);
return '';
}
if ($class_name == 'static') {
return (string) $this->context->getClassFQSEN();
}
if ($class_name == 'self') {
if ($this->context->isGlobalScope()) {
assert(false, "Unimplemented branch is required for {$this->context}");
} else {
return (string) $this->context->getClassFQSEN();
}
}
if ($class_name == 'parent') {
$clazz = $this->context->getClassInScope($this->code_base);
if (!$clazz->hasParentClassFQSEN()) {
return '';
}
return (string) $clazz->getParentClassFQSEN();
}
return '';
}
示例8: __construct
/**
* Create and read command line arguments, configuring
* \Phan\Config as a side effect.
*/
public function __construct()
{
global $argv;
// file_put_contents('/tmp/file', implode("\n", $argv));
// Parse command line args
$opts = getopt("f:m:o:c:haqbrpid:s:3:t::");
// Determine the root directory of the project from which
// we root all relative paths passed in as args
Config::get()->setProjectRootDirectory($opts['d'] ?? getcwd());
// Now that we have a root directory, attempt to read a
// configuration file `.phan/config.php` if it exists
$this->maybeReadConfigFile();
foreach ($opts ?? [] as $key => $value) {
switch ($key) {
case 'h':
$this->usage();
break;
case 'f':
if (is_file($value) && is_readable($value)) {
$this->file_list = file($value, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
} else {
Log::err(Log::EFATAL, "Unable to open {$value}");
}
break;
case 'm':
if (!in_array($value, ['text', 'codeclimate'])) {
$this->usage("Unknown output mode: {$value}");
}
Log::setOutputMode($value);
break;
case 'c':
Config::get()->parent_constructor_required = explode(',', $value);
break;
case 'q':
Config::get()->quick_mode = true;
break;
case 'b':
Config::get()->backward_compatibility_checks = true;
break;
case 'p':
Config::get()->progress_bar = true;
break;
case 'a':
Config::get()->dump_ast = true;
break;
case 'o':
Log::setFilename($value);
break;
case 'i':
Log::setOutputMask(Log::getOutputMask() ^ Log::EUNDEF);
break;
case 't':
Config::get()->emit_trace_id = true;
break;
case '3':
Config::get()->exclude_analysis_directory_list = explode(',', $value);
break;
case 's':
Config::get()->stored_state_file_path = $value;
break;
case 'r':
Config::get()->reanalyze_file_list = true;
break;
case 'd':
// We handle this flag before parsing options so
// that we can get the project root directory to
// base other config flags values on
break;
default:
$this->usage("Unknown option '-{$key}'");
break;
}
}
$pruneargv = array();
foreach ($opts ?? [] as $opt => $value) {
foreach ($argv as $key => $chunk) {
$regex = '/^' . (isset($opt[1]) ? '--' : '-') . $opt . '/';
if ($chunk == $value && $argv[$key - 1][0] == '-' || preg_match($regex, $chunk)) {
array_push($pruneargv, $key);
}
}
}
while ($key = array_pop($pruneargv)) {
unset($argv[$key]);
}
if (empty($this->file_list) && count($argv) < 2) {
// Log::err(Log::EFATAL, "No files to analyze");
}
foreach ($argv as $arg) {
if ($arg[0] == '-') {
$this->usage("Unknown option '{$arg}'");
}
}
$this->file_list = array_merge($this->file_list, array_slice($argv, 1));
}
示例9: analyzeElementReferenceCounts
/**
* Check to see if the given Clazz is a duplicate
*
* @return null
*/
public static function analyzeElementReferenceCounts(CodeBase $code_base, TypedStructuralElement $element)
{
// Don't worry about internal elements
if ($element->getContext()->isInternal()) {
return;
}
if ($element->getReferenceCount($code_base) < 1) {
if ($element instanceof Addressable) {
Log::err(Log::ENOOP, "{$element->getFQSEN()} may have zero references", $element->getContext()->getFile(), $element->getContext()->getLineNumberStart());
} else {
Log::err(Log::ENOOP, "{$element} may have zero references", $element->getContext()->getFile(), $element->getContext()->getLineNumberStart());
}
}
}
示例10: classExistsOrIsNative
/**
* @return bool
* False if the class name doesn't point to a known class
*/
private function classExistsOrIsNative(Node $node) : bool
{
if ($this->classExists()) {
return true;
}
$type = UnionType::fromStringInContext($this->class_name, $this->context);
if ($type->isNativeType()) {
return true;
}
Log::err(Log::EUNDEF, "reference to undeclared class {$this->class_fqsen}", $this->context->getFile(), $node->lineno);
return false;
}
示例11: visitNew
/**
* @param Node $node
* A node of the type indicated by the method name that we'd
* like to figure out the type that it produces.
*
* @return string
* The class name represented by the given call
*/
public function visitNew(Node $node) : string
{
// Things of the form `new $class_name();`
if ($node->children['class']->kind == \ast\AST_VAR) {
return '';
}
// Anonymous class
// $v = new class { ... }
if ($node->children['class']->kind == \ast\AST_CLASS && $node->children['class']->flags & \ast\flags\CLASS_ANONYMOUS) {
return (new ContextNode($this->code_base, $this->context, $node->children['class']))->getUnqualifiedNameForAnonymousClass();
}
// Things of the form `new $method->name()`
if ($node->children['class']->kind !== \ast\AST_NAME) {
return '';
}
$class_name = $node->children['class']->children['name'];
if (!in_array($class_name, ['self', 'static', 'parent'])) {
return (string) UnionTypeVisitor::unionTypeFromClassNode($this->code_base, $this->context, $node->children['class']);
}
if (!$this->context->isInClassScope()) {
Log::err(Log::ESTATIC, "Cannot access {$class_name}:: when no class scope is active", $this->context->getFile(), $node->lineno);
return '';
}
if ($class_name == 'static') {
return (string) $this->context->getClassFQSEN();
}
if ($class_name == 'self') {
if ($this->context->isGlobalScope()) {
assert(false, "Unimplemented branch is required for {$this->context}");
} else {
return (string) $this->context->getClassFQSEN();
}
}
if ($class_name == 'parent') {
$clazz = $this->context->getClassInScope($this->code_base);
if (!$clazz->hasParentClassFQSEN()) {
return '';
}
return (string) $clazz->getParentClassFQSEN();
}
return '';
}
示例12: __construct
/**
* Create and read command line arguments, configuring
* \Phan\Config as a side effect.
*/
public function __construct()
{
global $argv;
// Parse command line args
$opts = getopt("f:m:o:c:haqbrpis:3:t::");
foreach ($opts ?? [] as $key => $value) {
switch ($key) {
case 'h':
$this->usage();
break;
case 'f':
if (is_file($value) && is_readable($value)) {
$this->file_list = file($value, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
} else {
Log::err(Log::EFATAL, "Unable to open {$value}");
}
break;
case 'm':
if (!in_array($value, ['verbose', 'short', 'json', 'csv'])) {
$this->usage("Unknown output mode: {$value}");
}
Log::setOutputMode($value);
break;
case 'c':
Config::get()->parent_constructor_required = explode(',', $value);
break;
case 'q':
Config::get()->quick_mode = true;
break;
case 'b':
Config::get()->backward_compatibility_checks = true;
break;
case 'p':
Config::get()->progress_bar = true;
break;
case 'a':
Config::get()->dump_ast = true;
break;
case 'o':
Log::setFilename($value);
break;
case 'i':
Log::setOutputMask(Log::getOutputMask() ^ Log::EUNDEF);
break;
case 't':
Config::get()->emit_trace_id = true;
break;
case '3':
Config::get()->third_party_directory_list = explode(',', $value);
break;
case 's':
Config::get()->serialized_code_base_file = $value;
break;
case 'r':
Config::get()->reanalyze_file_list = true;
break;
default:
$this->usage("Unknown option '-{$key}'");
break;
}
}
$pruneargv = array();
foreach ($opts ?? [] as $opt => $value) {
foreach ($argv as $key => $chunk) {
$regex = '/^' . (isset($opt[1]) ? '--' : '-') . $opt . '/';
if ($chunk == $value && $argv[$key - 1][0] == '-' || preg_match($regex, $chunk)) {
array_push($pruneargv, $key);
}
}
}
while ($key = array_pop($pruneargv)) {
unset($argv[$key]);
}
if (empty($this->file_list) && count($argv) < 2) {
Log::err(Log::EFATAL, "No files to analyze");
}
foreach ($argv as $arg) {
if ($arg[0] == '-') {
$this->usage("Unknown option '{$arg}'");
}
}
$this->file_list = array_merge($this->file_list, array_slice($argv, 1));
}
示例13: fromNode
/**
* @param Context $context
* The context in which the node appears
*
* @param CodeBase $code_base
*
* @param Node $node
* An AST node representing a method
*
* @return Method
* A Method representing the AST node in the
* given context
*
*
* @see \Phan\Deprecated\Pass1::node_func
* Formerly 'function node_func'
*/
public static function fromNode(Context $context, CodeBase $code_base, Node $node) : Method
{
// Parse the comment above the method to get
// extra meta information about the method.
$comment = Comment::fromStringInContext($node->docComment ?? '', $context);
// @var Parameter[]
// The list of parameters specified on the
// method
$parameter_list = Parameter::listFromNode($context, $code_base, $node->children['params']);
// Add each parameter to the scope of the function
foreach ($parameter_list as $parameter) {
$context = $context->withScopeVariable($parameter);
}
// Create the skeleton method object from what
// we know so far
$method = new Method($context, $node->name, new UnionType(), $node->flags ?? 0);
// If the method is Analyzable, set the node so that
// we can come back to it whenever we like and
// rescan it
$method->setNode($node);
// Set the parameter list on the method
$method->setParameterList($parameter_list);
$method->setNumberOfRequiredParameters(array_reduce($parameter_list, function (int $carry, Parameter $parameter) : int {
return $carry + ($parameter->isRequired() ? 1 : 0);
}, 0));
$method->setNumberOfOptionalParameters(array_reduce($parameter_list, function (int $carry, Parameter $parameter) : int {
return $carry + ($parameter->isOptional() ? 1 : 0);
}, 0));
// Check to see if the comment specifies that the
// method is deprecated
$method->setIsDeprecated($comment->isDeprecated());
// Take a look at method return types
if ($node->children['returnType'] !== null) {
$union_type = UnionType::fromSimpleNode($context, $node->children['returnType']);
$method->getUnionType()->addUnionType($union_type);
} else {
if ($comment->hasReturnUnionType()) {
// See if we have a return type specified in the comment
$union_type = $comment->getReturnType();
if ($union_type->hasSelfType()) {
// We can't actually figure out 'static' at this
// point, but fill it in regardless. It will be partially
// correct
if ($context->hasClassFQSEN()) {
// n.b.: We're leaving the reference to self, static
// or $this in the type because I'm guessing
// it doesn't really matter. Apologies if it
// ends up being an issue.
$union_type->addUnionType($context->getClassFQSEN()->asUnionType());
}
}
$method->getUnionType()->addUnionType($union_type);
}
}
// Add params to local scope for user functions
if ($context->getFile() != 'internal') {
$parameter_offset = 0;
foreach ($method->getParameterList() as $i => $parameter) {
if ($parameter->getUnionType()->isEmpty()) {
// If there is no type specified in PHP, check
// for a docComment with @param declarations. We
// assume order in the docComment matches the
// parameter order in the code
if ($comment->hasParameterWithNameOrOffset($parameter->getName(), $parameter_offset)) {
$comment_type = $comment->getParameterWithNameOrOffset($parameter->getName(), $parameter_offset)->getUnionType();
$parameter->getUnionType()->addUnionType($comment_type);
}
}
// If there's a default value on the parameter, check to
// see if the type of the default is cool with the
// specified type.
if ($parameter->hasDefaultValue()) {
$default_type = $parameter->getDefaultValueType();
if (!$default_type->canCastToUnionType($parameter->getUnionType())) {
Log::err(Log::ETYPE, "Default value for {$parameter->getUnionType()} \${$parameter->getName()} can't be {$default_type}", $context->getFile(), $node->lineno);
}
// If we have no other type info about a parameter,
// just because it has a default value of null
// doesn't mean that is its type. Any type can default
// to null
if ((string) $default_type === 'null' && !$parameter->getUnionType()->isEmpty()) {
$parameter->getUnionType()->addType(NullType::instance());
}
//.........这里部分代码省略.........
示例14: getClassInScope
/**
* @param CodeBase $code_base
* The global code base holding all state
*
* @return Clazz
* Get the class in this scope, or fail real hard
*/
public function getClassInScope(CodeBase $code_base) : Clazz
{
assert($this->isInClassScope(), "Must be in class scope to get class");
if (!$code_base->hasClassWithFQSEN($this->getClassFQSEN())) {
Log::err(Log::EFATAL, "Cannot find class with FQSEN {$this->getClassFQSEN()} in context {$this}", $this->getFile(), 0);
}
return $code_base->getClassByFQSEN($this->getClassFQSEN());
}
示例15: visitCatch
/**
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitCatch(Node $node) : Context
{
// Get the name of the class
$class_name = $node->children['class']->children['name'];
$clazz = null;
// If we can't figure out the class name (which happens
// from time to time), then give up
if (!empty($class_name)) {
$class_fqsen = FullyQualifiedClassName::fromStringInContext($class_name, $this->context);
// Check to see if the class actually exists
if ($this->code_base->hasClassWithFQSEN($class_fqsen)) {
$clazz = $this->code_base->getClassByFQSEN($class_fqsen);
} else {
Log::err(Log::EUNDEF, "call to method on undeclared class {$class_name}", $this->context->getFile(), $node->lineno);
}
}
$variable_name = AST::variableName($node->children['var']);
if (!empty($variable_name)) {
$variable = Variable::fromNodeInContext($node->children['var'], $this->context, $this->code_base, false);
if ($clazz) {
$variable->setUnionType($clazz->getUnionType());
}
$this->context->addScopeVariable($variable);
}
return $this->context;
}