Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
CRAP
92.31% covered (success)
92.31%
12 / 13
FileInfo
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
6.02
92.31% covered (success)
92.31%
12 / 13
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 getRelativePath
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getRelativePathname
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getFilenameWithoutExtension
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getContents
0.00% covered (danger)
0.00%
0 / 1
2.03
80.00% covered (warning)
80.00%
4 / 5
<?php
namespace Gek\FileFinder;
use RuntimeException;
class FileInfo extends \SplFileInfo
{
    #region fields
    private $relativePath;
    private $relativePathname;
    #endregion fields
    #region ctor
    public function __construct(string $file_name, string $relativePath, string $relativePathname)
    {
        parent::__construct($file_name);
        $this->relativePath = $relativePath;
        $this->relativePathname = $relativePathname;
    }
    #endregion ctor
    #region properties
    /**
     * @return string
     */
    public function getRelativePath(): string
    {
        return $this->relativePath;
    }
    /**
     * @return string
     */
    public function getRelativePathname(): string
    {
        return $this->relativePathname;
    }
    #endregion properties
    #region Methods
    /**
     * @return string
     */
    public function getFilenameWithoutExtension(): string
    {
        $filename = $this->getFilename();
        return pathinfo($filename, \PATHINFO_FILENAME);
    }
    /**
     * @return false|string
     */
    public function getContents()
    {
        set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
        $content = file_get_contents($this->getPathname());
        restore_error_handler();
        if (false === $content) {
            throw new RuntimeException($error);
        }
        return $content;
    }
    #endregion Methods
}