kylekatarnls/sbp

View on GitHub
src/Sbp/Plugins/Helpers/FileHelper.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Sbp\Plugins\Helpers;

class FileHelper
{
    public static function getSbpSource($file)
    {
        if (preg_match('#/\*:(.+):\*/#U', file_get_contents($file), $match)) {
            return static::cleanPath($match[1]);
        }
    }

    public static function cleanPath($path)
    {
        $realPath = realpath($path);

        return $realPath === false ? $path : $realPath;
    }

    public static function matchingLetter($file)
    {
        if (fileowner($file) === getmyuid()) {
            return 'u';
        }
        if (filegroup($file) === getmygid()) {
            return 'g';
        }

        return 'o';
    }
}