Get migration queries class name parsed from file path

@param string $sFilePath The path of the file to extract the class name from

@throws MigrationException

@return string Class name in lower case most cases
330969
protected function _getClassNameFromFilePath($sFilePath)
    {
        $sFileName = basename($sFilePath);
        $aMatches = array();

        if (!preg_match(AbstractQuery::REGEXP_FILE, $sFileName, $aMatches)) {
            throw new MigrationException('Could not extract class name from file name');
        }

        return $aMatches[2] . 'migration';
    }
465128
protected function validateMigrationPaths($migrationPaths)
    {
        foreach ($migrationPaths as $migrationPath) {
            $path = \Yii::getAlias($migrationPath, false);
            if ($path === false) {
                throw new ExtensionException(
                  __CLASS__,
                  "Invalid path alias: $migrationPath"
                );
            }

            if (!file_exists($path)) {
                throw new ExtensionException(
                  __CLASS__,
                  "The migration path does not exist: " . realpath($this->getRootDir() . $path)
                );
            }
        }
    }
886668
private function getScannerForPath(
        $file_path,
        array $filetype_scanners,
        $will_analyze = false
    ) {
        $path_parts = explode(DIRECTORY_SEPARATOR, $file_path);
        $file_name_parts = explode('.', array_pop($path_parts));
        $extension = count($file_name_parts) > 1 ? array_pop($file_name_parts) : null;

        $file_name = $this->config->shortenFileName($file_path);

        if (isset($filetype_scanners[$extension])) {
            return new $filetype_scanners[$extension]($file_path, $file_name, $will_analyze);
        }

        return new FileScanner($file_path, $file_name, $will_analyze);
    }
1182988
public function fileGetContents($filePath)
    {
        if ($this->fileExists($filePath) == false) {
            throw new FileSystemException('File '.$filePath.' was not found');
        }
        return file_get_contents($filePath);
    }
378521
protected function dbTable( $filePath )
     {
         $cacheDir = defined( 'CLUSTER_METADATA_CACHE_PATH' ) ? CLUSTER_METADATA_CACHE_PATH : "/cache/";
         $storageDir = defined( 'CLUSTER_METADATA_STORAGE_PATH' ) ? CLUSTER_METADATA_STORAGE_PATH : "/storage/";

         if ( strpos( $filePath, $cacheDir ) !== false && strpos( $filePath, $storageDir ) === false )
         {
             return defined( 'CLUSTER_METADATA_TABLE_CACHE' ) ? CLUSTER_METADATA_TABLE_CACHE : 'ezdfsfile_cache';
         }

         return 'ezdfsfile';
     }
165742
protected function extractClassFromFile($path)
    {
        $fileContent = file_get_contents($path);
        $matches = [];
        $pattern = '/Cms\S+_\S+Class/';
        preg_match($pattern, $fileContent, $matches);

        if (!empty($matches[0])) {
            return $matches[0];
        }

        return null;
    }
1332275
public function readFile($filePath)
    {
        if (false === $fileContent = @file_get_contents($filePath)) {
            throw new RuntimeException(
                sprintf('unable to read file "%s"', $filePath)
            );
        }

        return $fileContent;
    }
272835
public static function getMimeType($filePath)
    {
        /*
         * The file does not exist?
         * Nothing to do
         */
        if (!is_string($filePath) || !is_readable($filePath)) {
            return '';
        }

        // 1st possibility: the finfo class
        if (class_exists('finfo')) {
            $finfo = new \finfo();

            return $finfo->file($filePath, FILEINFO_MIME_TYPE);
        }

        // 2nd possibility: the mime_content_type function
        if (function_exists('mime_content_type')) {
            return mime_content_type($filePath);
        }

        // Oops, there is no possibility to read the mime type
        $template = 'Neither \'finfo\' class nor \'mime_content_type\' function exists. There is no way to read the'
            . ' mime type of file \'%s\'.';

        $message = sprintf($template, $filePath);

        throw new \RuntimeException($message);
    }
82869
public function locate($classname, $basepath = null)
    {
        if (substr($classname, 0, 3) === 'Plg')
        {
            /*
             * Exception rule for Exception classes
             *
             * Transform class to lower case to always load the exception class from the /exception/ folder.
             */
            if ($pos = strpos($classname, 'Exception'))
            {
                $filename  = substr($classname, $pos + strlen('Exception'));
                $classname = str_replace($filename, ucfirst(strtolower($filename)), $classname);
            }

            $word  = strtolower(preg_replace('/(?<=\\w)([A-Z])/', ' \\1', $classname));
            $parts = explode(' ', $word);

            array_shift($parts);
            $package   = array_shift($parts);
            $namespace = ucfirst($package);

            if(count($parts)) {
                $file = array_pop($parts);
            } else {
                $file = $package;
            }

            //Switch basepath
            if(!$this->getNamespace($namespace)) {
                $basepath = $this->getNamespace('\\');
            } else {
                $basepath = $this->getNamespace($namespace);
            }

            $path = '';

            if (!empty($parts)) {
                $path = implode('/', $parts) . '/';
            }

            $result = $basepath.'/'.$package.'/'.$path . $file.'.php';

            if(!is_file($result)) {
                $result = $basepath.'/'.$package.'/'.$path . $file.'/'.$file.'.php';
            }

            return $result;
        }

        return false;

    }
1154679
protected function _getManifest( $filepath )
	{
		if( !file_exists( $filepath ) ) {
			throw new MW_Jsb2_Exception( sprintf( 'File does not exists: "%1$s"', $filepath ) );
		}

		if( ( $content = file_get_contents( $filepath ) ) === false ) {
			throw new MW_Jsb2_Exception( sprintf( 'Unable to read content from "%1$s"', $filepath ) );
		}

		if( ( $content = json_decode( $content ) ) === null ) {
			throw new MW_Jsb2_Exception( 'File content is not JSON encoded' );
		}

		return $content;
	}
1019926
protected function getFileGenerationPath()
	{
		$path = $this->getPathByOptionOrConfig( 'path', 'migration_target_path' );
		$migrationName = str_replace('/', '_', $this->migrationName);
		$fileName = $this->getDatePrefix() . '_' . $migrationName . '.php';

		return "{$path}/{$fileName}";
	}
1094637
public static function getFilename($filepath)
    {
        $explode_filepath = explode('/', $filepath);
        return \Library\Helper\File::getHumanReadableFilename(end($explode_filepath));
    }
931532
public function fromLock($lockPath)
    {
        if (!is_file($lockPath)) {
            throw new ComposerFileDoesNotExistsException($lockPath);
        }

        $file = new SplFileInfo($lockPath, null, null);
        $decodedData = json_decode($file->getContents(), true);

        if (json_last_error() != JSON_ERROR_NONE) {
            throw new ComposerFileIsInvalidException($lockPath);
        }

        $packages = array();
        foreach ($decodedData['packages'] as $package) {
            $packages[] = Package::fromArray($package);
        }

        $devPackages = array();
        foreach ($decodedData['packages-dev'] as $package) {
            $devPackages[] = Package::fromArray($package);
        }

        return new Composer($packages, $devPackages, true);
    }
236103
public function getLeafObject( string $filepath ) : Leaf
	{
		$leafObject = new $this->leafObjectClass( $this->search, $filepath );

		if ( $leafObject instanceof Leaf )
		{
			return $leafObject;
		}

		throw new \RuntimeException( sprintf( '%s is not a subclass of %s\\Leaf', $this->leafObjectClass, __NAMESPACE__ ) );
	}
537303
protected function getClassNameWithNamespace(File $phpCsFile): ?string
    {
        try {
            $lastToken = TokenHelper::getLastTokenPointer($phpCsFile);
        } catch (EmptyFileException $e) {
            return null;
        }

        if (!NamespaceHelper::findCurrentNamespaceName($phpCsFile, $lastToken)) {
            return null;
        }

        return ClassHelper::getFullyQualifiedName(
            $phpCsFile,
            $phpCsFile->findPrevious(TokenHelper::$typeKeywordTokenCodes, $lastToken)
        );
    }
445875
public function getExtensionByFileName($filepath)
    {
        $path = pathinfo($filepath);

        // check if the file has the extenison and we need
        // to lower down the extension (caused unknown extension for uppercased extension)
        if (isset($path['extension'])) {
            return strtolower($path['extension']);
        } else if (is_string($this->getMime())) {
            return str_replace("image/", "", $this->getMime());
        } else if ($this->format != "") {
            return $this->format;
        } else {
            // fallback to enable save image on empty extension. ImageMagick has no problem with this.
            return "jpg";
        }
    }
462940
protected static function classFromFile(SplFileInfo $file, $basePath)
    {
        $class = trim(str_replace($basePath, '', $file->getRealPath()), DIRECTORY_SEPARATOR);

        return str_replace(
            [DIRECTORY_SEPARATOR, 'App\\'],
            ['\\', app()->getNamespace()],
            ucfirst(Str::replaceLast('.php', '', $class))
        );
    }