Get the ReflectionClass from an argument.
be it an object or a class name.

@param mixed $argument

@return ReflectionClass|ReflectionMethod|ReflectionProperty
430715
protected function getReflectionFrom($argument)
    {
        // Method name to use.
        $reflectionMethodName = Str::camel('getreflection'.$this->target.'from');

        // Return Reflection
        return $this->{$reflectionMethodName}($argument);
    }
280435
private function getMethodArgument($argument)
    {
        $arg = '__unknown__';
        if ($argument instanceof PyStringNode) {
            $arg = 'PyStringNode $string';
        } elseif ($argument instanceof TableNode) {
            $arg = 'TableNode $table';
        }

        return $arg;
    }
1320428
protected static function _getClass($data)
    {
        // check arg
        if (is_object($data)) {
            $className = get_class($data);
        } elseif (is_string($data)) {
            $className = $data;
        } else {
            return false;
        }

        if (!class_exists($className) && !interface_exists($className)) {
            return false;
        }

        // create ReflectionClass object
        $class = new ReflectionClass($data);

        // get basic class info
        $result['name'] = $class->name;
        $result['type'] = ($class->isInterface() ? 'interface' : 'class');
        if ($classComment = $class->getDocComment()) {
            $result['comment'] = $classComment;
        }
        if ($classPath = $class->getFileName()) {
            $result['path'] = $classPath . ' ' . $class->getStartLine() . '/' . $class->getEndLine();
        }
        if ($classExtName = $class->getExtensionName()) {
            $result['extension'] = $classExtName;
        }
        if ($class->isAbstract()) {
            $result['abstract'] = true;
        }
        if ($class->isFinal()) {
            $result['final'] = true;
        }

        // get all parents of class
        $class_tmp         = $class;
        $result['parents'] = array();
        while ($parent = $class_tmp->getParentClass()) {
            if (isset($parent->name)) {
                $result['parents'][] = $parent->name;
                $class_tmp           = $parent;
            }
        }
        if (count($result['parents']) == 0) {
            unset($result['parents']);
        }

        // reflecting class interfaces
        $interfaces = $class->getInterfaces();
        if (is_array($interfaces)) {
            foreach ($interfaces as $property) {
                $result['interfaces'][] = $property->name;
            }
        }

        // reflection class constants
        $constants = $class->getConstants();
        if (is_array($constants)) {
            foreach ($constants as $key => $property) {
                $result['constants'][$key] = $property;
            }
        }

        // reflecting class properties
        $properties = $class->getProperties();
        if (is_array($properties)) {
            foreach ($properties as $key => $property) {

                if ($property->isPublic()) {
                    $visible = "public";
                } elseif ($property->isProtected()) {
                    $visible = "protected";
                } elseif ($property->isPrivate()) {
                    $visible = "private";
                } else {
                    $visible = "public";
                }

                $propertyName = $property->getName();

                $result['properties'][$visible][$propertyName]['comment'] = $property->getDocComment();
                $result['properties'][$visible][$propertyName]['static']  = $property->isStatic();
                $result['properties'][$visible][$propertyName]['default'] = $property->isDefault();
                $result['properties'][$visible][$propertyName]['class']   = $property->class;
            }
        }

        // get source
        $source = null;
        if (isset($result['path']) && $result['path']) {
            $source = @file($class->getFileName());
            if (!empty($source)) {
                $result['source::source'] = implode('', $source);
            }
        }

        // reflecting class methods
        foreach ($class->getMethods() as $key => $method) {

            if ($method->isPublic()) {
                $visible = "public";
            } elseif ($method->isProtected()) {
                $visible = "protected";
            } elseif ($method->isPrivate()) {
                $visible = "protected";
            } else {
                $visible = "public";
            }

            $result['methods'][$visible][$method->name]['name'] = $method->getName();

            if ($method->isAbstract()) {
                $result['methods'][$visible][$method->name]['abstract'] = true;
            }
            if ($method->isFinal()) {
                $result['methods'][$visible][$method->name]['final'] = true;
            }
            if ($method->isInternal()) {
                $result['methods'][$visible][$method->name]['internal'] = true;
            }
            if ($method->isStatic()) {
                $result['methods'][$visible][$method->name]['static'] = true;
            }
            if ($method->isConstructor()) {
                $result['methods'][$visible][$method->name]['constructor'] = true;
            }
            if ($method->isDestructor()) {
                $result['methods'][$visible][$method->name]['destructor'] = true;
            }
            $result['methods'][$visible][$method->name]['declaringClass'] = $method->getDeclaringClass()->name;

            if ($comment = $method->getDocComment()) {
                $result['methods'][$visible][$method->name]['comment'] = $comment;
            }

            $startLine = $method->getStartLine();
            $endLine   = $method->getEndLine();
            if ($startLine && $source) {
                $from    = (int)($startLine - 1);
                $to      = (int)($endLine - $startLine + 1);
                $slice   = array_slice($source, $from, $to);
                $phpCode = implode('', $slice);

                $result['methods'][$visible][$method->name]['source::source'] = $phpCode;
            }

            if ($params = self::_getParams($method->getParameters(), $method->isInternal())) {
                $result['methods'][$visible][$method->name]['parameters'] = $params;
            }
        }

        // get all methods
        $result['all_methods'] = get_class_methods($className);
        sort($result['all_methods']);

        // sorting properties and methods
        if (isset($result['properties']['protected'])) {
            ksort($result['properties']['protected']);
        }
        if (isset($result['properties']['private'])) {
            ksort($result['properties']['private']);
        }
        if (isset($result['properties']['public'])) {
            ksort($result['properties']['public']);
        }
        if (isset($result['methods']['protected'])) {
            ksort($result['methods']['protected']);
        }
        if (isset($result['methods']['private'])) {
            ksort($result['methods']['private']);
        }
        if (isset($result['methods']['public'])) {
            ksort($result['methods']['public']);
        }

        return $result;
    }
357057
public static function getInstance(...$args)
    {
        if(static::isChildClassSingleton())
        {
            $className = static::class;
            if(!isset(static::$instances[$className]))
            {
                static::$instances[$className] = new static(...$args);
            }
            return static::$instances[$className];
        }
        else
        {
            if(null === static::$instance)
            {
                static::$instance = new static(...$args);
            }
            return static::$instance;
        }
    }
1363602
public function makeClass($alias, array $arguments)
    {
        $reflection = new \ReflectionClass($this->getAlias($alias));

        return $reflection->newInstanceArgs($arguments);
    }
1054710
public static function assertInstanceOf($argument, $class)
    {
        if (false == $argument instanceof $class) {
            throw new static(sprintf(
                'The argument must be an instance of %s but got %s.',
                $class,
                is_object($argument) ? get_class($argument) : gettype($argument)
            ));
        }
    }
910924
public function exec($arguments) {
        //parse
        $options = $this->parse();

        // check if help was requested
        if(is_integer($options)) {
            return $options;
        }

        // extract and remove special vars
        $instance = $options["__instance"];
        $method   = $options["__method"];

        unset($options["__instance"]);
        unset($options["__method"]);

        // execute action - print error on failure
        try {
            return (int)Misc::reflectionFunction([ $instance, $method ], self::adjustOptions($options));
        }
        catch(Exception $e) {
            return $this->printError($e->getMessage());
        }
    }
1271047
public function getValue($object)
    {
        $this->reflectionProperty->setAccessible(true);

        return $this->reflectionProperty->getValue($object);
    }
941148
public function getParameterClassObject($object, $method)
    {
        $reflectionClass = new \ReflectionClass(get_class($object));
        $parameters = $reflectionClass->getMethod($method)->getParameters();

        if ($parameters && isset($parameters[0])) {
            $refClass = $parameters[0]->getClass();

            if ($refClass) {
                $class = $refClass->getName();

                return new $class();
            }
        }
    }
959424
public function resolve(\ReflectionMethod $function, array $arguments)
    {
        // No `@ScenarioStateArgument` annotation found
        if (null === $this->reader->getMethodAnnotation($function, ScenarioStateArgument::class)) {
            return $arguments;
        }

        $paramsKeys = array_map(function (\ReflectionParameter $element) {
            return $element->getName();
        }, $function->getParameters());
        $store = $this->store->getStore();

        // Prepare arguments from annotations
        /** @var ScenarioStateArgument[] $annotations */
        $annotations = $this->reader->getMethodAnnotations($function);
        foreach ($annotations as $annotation) {
            if ($annotation instanceof ScenarioStateArgument &&
                in_array($annotation->getArgument(), $paramsKeys) &&
                $store->hasStateFragment($annotation->getName())
            ) {
                $arguments[$annotation->getArgument()] = $store->getStateFragment($annotation->getName());
            }
        }

        // Reorder arguments
        $params = [];
        foreach ($function->getParameters() as $parameter) {
            $name = $parameter->getName();
            $params[$name] = isset($arguments[$name]) ? $arguments[$name] : $arguments[$parameter->getPosition()];
        }

        return $params;
    }
1141870
public static function get($class)
    {
        $key = strtolower($class);

        if (isset(static::$instances[$key])) {
            return static::$instances[$key];
        }

        static::override($class);

        if (!class_exists($class)) {
            throw new ReflectionException("Class $class does not exist");
        }

        $instance = static::getInstance($class);
        static::register($class, $instance);
        return $instance;
    }
949197
private function getInjectionProviderParams(Argument $argument) : array
    {
        $param = $argument->get();
        $class = $param->getDeclaringClass();
        if (! $class instanceof \ReflectionClass) {
            throw new \LogicException; // @codeCoverageIgnore
        }
        $method = $param->getDeclaringFunction();
        $this->setQualifiers($method, $param);

        return [
            new Node\Arg(new Scalar\String_((string) $argument)),
            new Expr\Array_([
                new Expr\ArrayItem(new Scalar\String_($class->name)),
                new Expr\ArrayItem(new Scalar\String_($method->name)),
                new Expr\ArrayItem(new Scalar\String_($param->name))
            ])
        ];
    }
1334459
public function getPropertyClass(ReflectionProperty $property)
    {
        // Get the content of the @var annotation
        if (preg_match('/@var\s+([^\s]+)/', $property->getDocComment(), $matches)) {
            list(, $type) = $matches;
        } else {
            return null;
        }

        // Ignore primitive types
        if (in_array($type, $this->ignoredTypes)) {
            return null;
        }

        // Ignore types containing special characters ([], <> ...)
        if (! preg_match('/^[a-zA-Z0-9\\\\_]+$/', $type)) {
            return null;
        }

        $class = $property->getDeclaringClass();

        // If the class name is not fully qualified (i.e. doesn't start with a \)
        if ($type[0] !== '\\') {
            // Try to resolve the FQN using the class context
            $resolvedType = $this->tryResolveFqn($type, $class, $property);

            if (!$resolvedType && !$this->ignorePhpDocErrors) {
                throw new AnnotationException(sprintf(
                    'The @var annotation on %s::%s contains a non existent class "%s". '
                        . 'Did you maybe forget to add a "use" statement for this annotation?',
                    $class->name,
                    $property->getName(),
                    $type
                ));
            }
            
            $type = $resolvedType;
        }

        if (!$this->classExists($type) && !$this->ignorePhpDocErrors) {
            throw new AnnotationException(sprintf(
                'The @var annotation on %s::%s contains a non existent class "%s"',
                $class->name,
                $property->getName(),
                $type
            ));
        }

        // Remove the leading \ (FQN shouldn't contain it)
        $type = ltrim($type, '\\');

        return $type;
    }
735016
public static function createObject( $className, $arguments = array() )
	{
		if( !class_exists( $className ) )
			throw new RuntimeException( 'Class "'.$className.'" has not been loaded' );
		$class	= new ReflectionClass( $className );
		if( $arguments )
			$object	= $class->newInstanceArgs( $arguments );
		else
			$object	= $class->newInstance();
		return $object;
	}
363235
protected function getIdentifier($object)
    {
        $property = new ReflectionProperty(get_class($object), $this->getPrimaryKey());
        $property->setAccessible(true);
        return $property->getValue($object);
    }
904158
public function getClass(string $class){
        if(!class_exists($class)){
            throw new \InvalidArgumentException();
        }

        if(!array_key_exists($class, $this->classes)){
            $this->classes[$class]  = new \ReflectionClass($class);
        }

        return $this->classes[$class];
    }
1279344
public static function getInstance(array $arguments)
    {
        if (in_array('-nc', $arguments) || in_array('--no-color', $arguments)) {
            return new VerboseLogger(static::getLogLevel($arguments));
        }

        return new ColoredVerboseLogger(static::getLogLevel($arguments));
    }