src/Psalm/Internal/Codebase/Scanner.php
private function fileExistsForClassLike(ClassLikes $classlikes, $fq_class_name)
    {
        $fq_class_name_lc = strtolower($fq_class_name);

        if (isset($this->classlike_files[$fq_class_name_lc])) {
            return true;
        }

        if ($fq_class_name === 'self') {
            return false;
        }

        if (isset($this->existing_classlikes_lc[$fq_class_name_lc])) {
            throw new \InvalidArgumentException('Why are you asking about a builtin class?');
        }

        $composer_file_path = $this->config->getComposerFilePathForClassLike($fq_class_name);

        if ($composer_file_path && file_exists($composer_file_path)) {
            if ($this->debug_output) {
                echo 'Using composer to locate file for ' . $fq_class_name . "\n";
            }

            $classlikes->addFullyQualifiedClassLikeName(
                $fq_class_name_lc,
                realpath($composer_file_path)
            );

            return true;
        }

        $old_level = error_reporting();

        if (!$this->debug_output) {
            error_reporting(E_ERROR);
        }

        try {
            if ($this->debug_output) {
                echo 'Using reflection to locate file for ' . $fq_class_name . "\n";
            }

            /** @psalm-suppress TypeCoercion */
            $reflected_class = new \ReflectionClass($fq_class_name);
        } catch (\Throwable $e) {
            error_reporting($old_level);

            // do not cache any results here (as case-sensitive filenames can screw things up)

            return false;
        }

        error_reporting($old_level);

        /** @psalm-suppress MixedMethodCall due to Reflection class weirdness */
        $file_path = (string)$reflected_class->getFileName();

        // if the file was autoloaded but exists in evaled code only, return false
        if (!file_exists($file_path)) {
            return false;
        }

        $new_fq_class_name = $reflected_class->getName();

        if (strtolower($new_fq_class_name) !== strtolower($fq_class_name)) {
            $classlikes->addClassAlias($new_fq_class_name, strtolower($fq_class_name));
            $fq_class_name_lc = strtolower($new_fq_class_name);
        }

        $fq_class_name = $new_fq_class_name;
        $classlikes->addFullyQualifiedClassLikeName($fq_class_name_lc);

        if ($reflected_class->isInterface()) {
            $classlikes->addFullyQualifiedInterfaceName($fq_class_name, $file_path);
        } elseif ($reflected_class->isTrait()) {
            $classlikes->addFullyQualifiedTraitName($fq_class_name, $file_path);
        } else {
            $classlikes->addFullyQualifiedClassName($fq_class_name, $file_path);
        }

        return true;
    }
private function fileExistsForClassLike(ClassLikes $classlikes, $fq_class_name)
    {
        $fq_class_name_lc = strtolower($fq_class_name);

        if (isset($this->classlike_files[$fq_class_name_lc])) {
            return true;
        }

        if ($fq_class_name === 'self') {
            return false;
        }

        if (isset($this->existing_classlikes_lc[$fq_class_name_lc])) {
            throw new \InvalidArgumentException('Why are you asking about a builtin class?');
        }

        $composer_file_path = $this->config->getComposerFilePathForClassLike($fq_class_name);

        if ($composer_file_path && file_exists($composer_file_path)) {
            if ($this->debug_output) {
                echo 'Using composer to locate file for ' . $fq_class_name . "\n";
            }

            $classlikes->addFullyQualifiedClassLikeName(
                $fq_class_name_lc,
                realpath($composer_file_path)
            );

            return true;
        }

        $old_level = error_reporting();

        if (!$this->debug_output) {
            error_reporting(E_ERROR);
        }

        try {
            if ($this->debug_output) {
                echo 'Using reflection to locate file for ' . $fq_class_name . "\n";
            }

            /** @psalm-suppress TypeCoercion */
            $reflected_class = new \ReflectionClass($fq_class_name);
        } catch (\Throwable $e) {
            error_reporting($old_level);

            // do not cache any results here (as case-sensitive filenames can screw things up)

            return false;
        }

        error_reporting($old_level);

        /** @psalm-suppress MixedMethodCall due to Reflection class weirdness */
        $file_path = (string)$reflected_class->getFileName();

        // if the file was autoloaded but exists in evaled code only, return false
        if (!file_exists($file_path)) {
            return false;
        }

        $new_fq_class_name = $reflected_class->getName();

        if (strtolower($new_fq_class_name) !== strtolower($fq_class_name)) {
            $classlikes->addClassAlias($new_fq_class_name, strtolower($fq_class_name));
            $fq_class_name_lc = strtolower($new_fq_class_name);
        }

        $fq_class_name = $new_fq_class_name;
        $classlikes->addFullyQualifiedClassLikeName($fq_class_name_lc);

        if ($reflected_class->isInterface()) {
            $classlikes->addFullyQualifiedInterfaceName($fq_class_name, $file_path);
        } elseif ($reflected_class->isTrait()) {
            $classlikes->addFullyQualifiedTraitName($fq_class_name, $file_path);
        } else {
            $classlikes->addFullyQualifiedClassName($fq_class_name, $file_path);
        }

        return true;
    }
private function fileExistsForClassLike ( ClassLikes $ classlikes , $ fq_class_name ) { $ fq_class_name_lc = strtolower ( $ fq_class_name ) ; if ( isset ( $ this -> classlike_files [ $ fq_class_name_lc ] ) ) { return true ; } if ( $ fq_class_name === 'self' ) { return false ; } if ( isset ( $ this -> existing_classlikes_lc [ $ fq_class_name_lc ] ) ) { throw new \ InvalidArgumentException ( 'Why are you asking about a builtin class?' ) ; } $ composer_file_path = $ this -> config -> getComposerFilePathForClassLike ( $ fq_class_name ) ; if ( $ composer_file_path && file_exists ( $ composer_file_path ) ) { if ( $ this -> debug_output ) { echo 'Using composer to locate file for ' . $ fq_class_name . "\n" ; } $ classlikes -> addFullyQualifiedClassLikeName ( $ fq_class_name_lc , realpath ( $ composer_file_path ) ) ; return true ; } $ old_level = error_reporting ( ) ; if ( ! $ this -> debug_output ) { error_reporting ( E_ERROR ) ; } try { if ( $ this -> debug_output ) { echo 'Using reflection to locate file for ' . $ fq_class_name . "\n" ; } /** @psalm-suppress TypeCoercion */ $ reflected_class = new \ ReflectionClass ( $ fq_class_name ) ; } catch ( \ Throwable $ e ) { error_reporting ( $ old_level ) ; // do not cache any results here (as case-sensitive filenames can screw things up) return false ; } error_reporting ( $ old_level ) ; /** @psalm-suppress MixedMethodCall due to Reflection class weirdness */ $ file_path = ( string ) $ reflected_class -> getFileName ( ) ; // if the file was autoloaded but exists in evaled code only, return false if ( ! file_exists ( $ file_path ) ) { return false ; } $ new_fq_class_name = $ reflected_class -> getName ( ) ; if ( strtolower ( $ new_fq_class_name ) !== strtolower ( $ fq_class_name ) ) { $ classlikes -> addClassAlias ( $ new_fq_class_name , strtolower ( $ fq_class_name ) ) ; $ fq_class_name_lc = strtolower ( $ new_fq_class_name ) ; } $ fq_class_name = $ new_fq_class_name ; $ classlikes -> addFullyQualifiedClassLikeName ( $ fq_class_name_lc ) ; if ( $ reflected_class -> isInterface ( ) ) { $ classlikes -> addFullyQualifiedInterfaceName ( $ fq_class_name , $ file_path ) ; } elseif ( $ reflected_class -> isTrait ( ) ) { $ classlikes -> addFullyQualifiedTraitName ( $ fq_class_name , $ file_path ) ; } else { $ classlikes -> addFullyQualifiedClassName ( $ fq_class_name , $ file_path ) ; } return true ; }
Checks whether a class exists, and if it does then records what file it's in
for later checking

@param  string $fq_class_name

@return bool
Checks whether a class exists and if it does then records what file it s in for later checking